@@ 1,12 1,17 @@
function! chelper#SwitchToHeader() abort
- let l:root = expand('%:t:r')
- let l:ext = expand('%:t:e')
+ let l:root = expand('%:t:r')
+ let l:ext = expand('%:t:e')
- if l:ext ==# 'cpp'
- " exe "e inc/" . l:root . ".h"
- exe "find " . l:root . ".h"
- elseif l:ext ==# 'h' && filereadable('src/'.l:root.'.cpp')
- " exe "e src/" . l:root . ".cpp"
- exe "find " . l:root . ".cpp"
- endif
+ let l:header_exts = ['h', 'hh', 'hpp']
+ let l:source_exts = ['c', 'cc', 'cpp']
+
+ if index(l:source_exts, l:ext) >=0
+ for ext in l:header_exts
+ silent! exe "find " . l:root . "." . ext
+ endfor
+ elseif index(l:header_exts, l:ext) >=0
+ for ext in l:source_exts
+ silent! exe "find " . l:root . "." . ext
+ endfor
+ endif
endfunction