Skip to content

Commit

Permalink
add goto_header_associate_cpp_h to fix issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohannfra committed Apr 16, 2020
1 parent f881eb7 commit dbcdc0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ Put the following lines in your .vimrc to map gh to switch between .c/.h or .cpp
nnoremap gh :GotoHeaderSwitch <CR>
```

If you need to switch between a ".cpp" file and a ".h" file (like in #2) add this to your .vimrc
```vim
let g:goto_header_associate_cpp_h = 1
```

Now you'll just need to press F12 on a line like one of those and it will open the corresponding file in a new tab
```c
#include <stdio.h>
Expand Down
18 changes: 7 additions & 11 deletions autoload/goto_header.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ function! s:CheckConfigVals()
if !exists("g:goto_header_includes_dirs")
let g:goto_header_includes_dirs = [".", "/usr/include", "..", "~"]
endif
if !exists('g:goto_header_use_find')
let g:goto_header_use_find = 0
endif
if !exists('g:goto_header_excludes_dirs')
let g:goto_header_excludes_dirs = []
endif
if !exists('g:goto_header_open_in_new_tab')
let g:goto_header_open_in_new_tab = 0
endif
if !exists("g:goto_header_search_flags")
if g:goto_header_use_find
let g:goto_header_search_flags = "-type f"
else
let g:goto_header_search_flags = "-t f -s"
endif
endif
if !exists('g:goto_header_use_shorter_path')
let g:goto_header_use_shorter_path = 0
endif
let g:goto_header_use_find = get(g:, 'goto_header_use_find')
let g:goto_header_open_in_new_tab = get(g:, 'goto_header_open_in_new_tab')
let g:goto_header_use_shorter_path = get(g:, 'goto_header_use_shorter_path')
let g:goto_header_associate_cpp_h = get(g:, 'goto_header_associate_cpp_h')
endfunction

function! s:OpenFile(fp)
Expand Down Expand Up @@ -175,14 +170,15 @@ function! goto_header#Direct()
endfunction

function! goto_header#Switch()
call s:CheckConfigVals()
let filename = expand('%:t')
let found = 0
let s:path = ""
let extensions_dict = {
\ ".cpp" : ".hpp",
\ ".cpp" : (g:goto_header_associate_cpp_h) ? ".h" : ".hpp",
\ ".hpp" : ".cpp",
\ ".c" : ".h",
\ ".h" : ".c",
\ ".hpp" : ".cpp",
\}

for key in keys(extensions_dict)
Expand Down

0 comments on commit dbcdc0d

Please sign in to comment.