-nnoremap <buffer> <C-^> :execute "edit %<." . {"c": "h", "h": "c", "cc": "hh", "hh": "cc"}[expand("%:e")]<CR>
+if exists("*<SID>CAltSwitcher") | finish | endif
+
+let g:AltExts = {
+ \ "c": ["h"],
+ \ "h": ["c", "cc"],
+ \ "cc": ["hh", "h"],
+ \ "hh": ["cc"]
+\}
+
+function! <SID>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 <buffer> <C-^> :call <SID>CAltSwitcher()<CR>