]> Sergey Matveev's repositories - dotfiles.git/commitdiff
More complex alt-switcher
authorSergey Matveev <stargrave@stargrave.org>
Tue, 10 May 2022 14:37:11 +0000 (17:37 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 10 May 2022 14:37:11 +0000 (17:37 +0300)
vim/.vim/ftplugin/c/alt.vim

index 609f37df4ea551c0e21c7c86c29996b217087377..35ef67b9bd8f29ed3c040b12444b2cff5dfbff1c 100644 (file)
@@ -1 +1,21 @@
-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>