Suppose I have a folder with lots of .h and .cpp files. I frequently need to do the following:
prefix_SomeReallyLongFileName.h
,
Adding my two cents ;) to the above great answers:
.vimrc
" Jump to a file whose extension corresponds to the extension of the current
" file. The `tags' file, created with:
" $ ctags --extra=+f -R .
" has to be present in the current directory.
function! JumpToCorrespondingFile()
let l:extensions = { 'c': 'h', 'h': 'c', 'cpp': 'hpp', 'hpp': 'cpp' }
let l:fe = expand('%:e')
if has_key(l:extensions, l:fe)
execute ':tag ' . expand('%:t:r') . '.' . l:extensions[l:fe]
else
call PrintError(">>> Corresponding extension for '" . l:fe . "' is not specified")
endif
endfunct
" jump to a file with the corresponding extension ( aka )
nnoremap :call JumpToCorrespondingFile()
inoremap :call JumpToCorrespondingFile()
" Print error message.
function! PrintError(msg) abort
execute 'normal! \'
echohl ErrorMsg
echomsg a:msg
echohl None
endfunction