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()