neovim: add H keybinding to switch between matching .c and .h files

This commit is contained in:
2025-06-13 19:39:16 +00:00
parent 6f4e96145a
commit 93d68e494f
2 changed files with 30 additions and 0 deletions

View File

@@ -244,6 +244,10 @@ with pkgs.vimPlugins;
type = "lua";
config = builtins.readFile ./nix_shell.lua;
}
{
type = "viml";
config = builtins.readFile ./source_nav.vim;
}
{
# show commit which last modified text under the cursor.
# trigger with `:GitMessenger` or `<Leader>gm` (i.e. `\gm`)

View File

@@ -0,0 +1,26 @@
function GoToHeader()
let newfile = expand('%:r') . '.h'
execute "e " . fnameescape(l:newfile)
endfunc
function GoToSource()
let newfile = expand('%:r') . '.c'
execute "e " . fnameescape(l:newfile)
endfunc
function ToggleHeaderSource()
" If in abc.c file, open abc.h
" If in abc.h, open abc.c
let ext = expand('%:e')
if ext =~ 'c'
call GoToHeader()
else
call GoToSource()
end
endfunc
" command H call ToggleHeaderSource()
" command C call ToggleHeaderSource()
nmap H :call ToggleHeaderSource()<CR>
" TODO: port to lua impl
" vim.api.nvim_set_keymap("n", "H", "", { callback=ToggleHeaderSource, desc = "cycle between .h <-> .c files" })