From: Sergey Matveev Date: Tue, 10 May 2022 14:37:11 +0000 (+0300) Subject: More complex alt-switcher X-Git-Url: http://www.git.stargrave.org/?p=dotfiles.git;a=commitdiff_plain;h=e40e7338c2e589d1ca6cf37fdaa5c98035f281dd More complex alt-switcher --- diff --git a/vim/.vim/ftplugin/c/alt.vim b/vim/.vim/ftplugin/c/alt.vim index 609f37d..35ef67b 100644 --- a/vim/.vim/ftplugin/c/alt.vim +++ b/vim/.vim/ftplugin/c/alt.vim @@ -1 +1,21 @@ -nnoremap :execute "edit %<." . {"c": "h", "h": "c", "cc": "hh", "hh": "cc"}[expand("%:e")] +if exists("*CAltSwitcher") | finish | endif + +let g:AltExts = { + \ "c": ["h"], + \ "h": ["c", "cc"], + \ "cc": ["hh", "h"], + \ "hh": ["cc"] +\} + +function! CAltSwitcher() abort + for ext in g:AltExts[expand("%:e")] + let name = expand("%<") . "." . ext + if filereadable(name) + execute "edit " . name + return + endif + endfor + echomsg "no alt found" +endfunction + +nnoremap :call CAltSwitcher()