1
Fork 0

Wezterm & neovim navigation

This commit is contained in:
prescientmoon 2024-02-29 12:45:25 +01:00
parent b490e41bd1
commit a3a18c76d9
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
3 changed files with 81 additions and 1 deletions

View file

@ -85,12 +85,77 @@ local function unmap(key, mods)
} }
end end
local function bind_if(cond, key, mods, action)
local function callback(win, pane)
if cond(pane) then
win:perform_action(action, pane)
else
win:perform_action(
wezterm.action.SendKey({ key = key, mods = mods }),
pane
)
end
end
return { key = key, mods = mods, action = wezterm.action_callback(callback) }
end
-- {{{ Detect nvim processes
local function is_inside_vim(pane)
local tty = pane:get_tty_name()
if tty == nil then
return false
end
local success, _, _ = wezterm.run_child_process({
"sh",
"-c",
"ps -o state= -o comm= -t"
.. wezterm.shell_quote_arg(tty)
.. " | "
.. "grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'",
})
return success
end
local function is_outside_vim(pane)
return not is_inside_vim(pane)
end
-- }}}
config.keys = { config.keys = {
-- {{{ Disable certain default keybinds -- {{{ Disable certain default keybinds
unmap("f", "CTRL|SHIFT"), unmap("f", "CTRL|SHIFT"),
unmap("w", "CTRL|SHIFT"), unmap("w", "CTRL|SHIFT"),
unmap("Enter", "ALT"), unmap("Enter", "ALT"),
-- }}} -- }}}
-- {{{ Nvim nevigation keybinds
bind_if(
is_outside_vim,
"h",
"CTRL",
wezterm.action.ActivatePaneDirection("Left")
),
bind_if(
is_outside_vim,
"j",
"CTRL",
wezterm.action.ActivatePaneDirection("Down")
),
bind_if(
is_outside_vim,
"k",
"CTRL",
wezterm.action.ActivatePaneDirection("Up")
),
bind_if(
is_outside_vim,
"l",
"CTRL",
wezterm.action.ActivatePaneDirection("Right")
),
-- }}}
} }
-- }}} -- }}}

View file

@ -38,6 +38,7 @@
"mini.pairs": { "branch": "main", "commit": "04f58f2545ed80ac3b52dd4826e93f33e15b2af6" }, "mini.pairs": { "branch": "main", "commit": "04f58f2545ed80ac3b52dd4826e93f33e15b2af6" },
"mini.statusline": { "branch": "main", "commit": "dfd3d2ba295473930f78f143852b9b53eb54ae2a" }, "mini.statusline": { "branch": "main", "commit": "dfd3d2ba295473930f78f143852b9b53eb54ae2a" },
"mini.surround": { "branch": "main", "commit": "a1b590cc3b676512de507328d6bbab5e43794720" }, "mini.surround": { "branch": "main", "commit": "a1b590cc3b676512de507328d6bbab5e43794720" },
"navigator": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" },
"neoconf": { "branch": "main", "commit": "4ef6c6c5882e7e16209173fb8c47414202843384" }, "neoconf": { "branch": "main", "commit": "4ef6c6c5882e7e16209173fb8c47414202843384" },
"neodev.nvim": { "branch": "main", "commit": "b0ccf605c952eb0d1efe3692d5b241c52ceee187" }, "neodev.nvim": { "branch": "main", "commit": "b0ccf605c952eb0d1efe3692d5b241c52ceee187" },
"nui": { "branch": "main", "commit": "c3c7fd618dcb5a89e443a2e1033e7d11fdb0596b" }, "nui": { "branch": "main", "commit": "c3c7fd618dcb5a89e443a2e1033e7d11fdb0596b" },

View file

@ -736,7 +736,7 @@ let
[ "<tab>d" "<tab>f" "<tab>F" "<tab>h" "<tab>r" ] [ "<tab>d" "<tab>f" "<tab>F" "<tab>h" "<tab>r" ]
]; ];
# {{{ Keymaps # {{{ Keybinds
opts.mappings = { opts.mappings = {
add = "<tab>s"; # Add surrounding in Normal and Visul modes add = "<tab>s"; # Add surrounding in Normal and Visul modes
delete = "<tab>d"; # Delete surrounding delete = "<tab>d"; # Delete surrounding
@ -1348,6 +1348,20 @@ let
}; };
}; };
# }}} # }}}
# {{{ navigator
navigator = {
package = "numToStr/Navigator.nvim";
cond = blacklist [ "vscode" "firenvim" "neovide" ];
config = true;
keys = [
(nmap "<c-h>" "<cmd>NavigatorLeft<cr>" "Navigate left")
(nmap "<c-j>" "<cmd>NavigatorDown<cr>" "Navigate down")
(nmap "<c-k>" "<cmd>NavigatorUp<cr>" "Navigate up")
(nmap "<c-l>" "<cmd>NavigatorRight<cr>" "Navigate right")
];
};
# }}}
# }}} # }}}
}; };
# }}} # }}}