vimrc: add src-hdr file switching func
This commit is contained in:
parent
6c14d6dbee
commit
48e8487801
28
.vim/vimrc
28
.vim/vimrc
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user