neovim: add H keybinding to switch between matching .c and .h files
This commit is contained in:
@@ -244,6 +244,10 @@ with pkgs.vimPlugins;
|
|||||||
type = "lua";
|
type = "lua";
|
||||||
config = builtins.readFile ./nix_shell.lua;
|
config = builtins.readFile ./nix_shell.lua;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
type = "viml";
|
||||||
|
config = builtins.readFile ./source_nav.vim;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
# show commit which last modified text under the cursor.
|
# show commit which last modified text under the cursor.
|
||||||
# trigger with `:GitMessenger` or `<Leader>gm` (i.e. `\gm`)
|
# trigger with `:GitMessenger` or `<Leader>gm` (i.e. `\gm`)
|
||||||
|
26
hosts/common/programs/neovim/source_nav.vim
Normal file
26
hosts/common/programs/neovim/source_nav.vim
Normal 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" })
|
Reference in New Issue
Block a user