vimrc: add src-hdr file switching func

This commit is contained in:
surtur 2022-08-11 12:41:49 +02:00
parent 6c14d6dbee
commit 48e8487801
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -971,6 +971,34 @@ augroup AutoMkdir
augroup END
" as per https://stackoverflow.com/a/38775966
function! HeaderToggle() " bang for overwrite when saving vimrc
let file_path = expand('%')
let file_name = expand('%<')
let extension = split(file_path, '\.')[-1] " '\.' is how you really split on dot
let err_msg = 'There is no file '
if extension ==# 'cpp'
let next_file = join([file_name, '.h'], '')
if filereadable(next_file)
:e %<.h
else
echo join([err_msg, next_file], '')
endif
elseif extension ==# 'h'
let next_file = join([file_name, '.cpp'], '')
if filereadable(next_file)
:e %<.cpp
else
echo join([err_msg, next_file], '')
endif
endif
endfunction
nnoremap <leader>hh :call HeaderToggle()<cr>
nnoremap <Leader>ve :e $MYVIMRC<CR>
nnoremap <Leader>vr :source $MYVIMRC<CR>