From a3a18c76d9655dd8cefa739b3c2f01b15681899d Mon Sep 17 00:00:00 2001 From: prescientmoon Date: Thu, 29 Feb 2024 12:45:25 +0100 Subject: [PATCH] Wezterm & neovim navigation --- home/features/desktop/wezterm/wezterm.lua | 65 ++++++++++++++++++++++ home/features/neovim/config/lazy-lock.json | 1 + home/features/neovim/default.nix | 16 +++++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/home/features/desktop/wezterm/wezterm.lua b/home/features/desktop/wezterm/wezterm.lua index 28c81a0..33198ae 100644 --- a/home/features/desktop/wezterm/wezterm.lua +++ b/home/features/desktop/wezterm/wezterm.lua @@ -85,12 +85,77 @@ local function unmap(key, mods) } 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 = { -- {{{ Disable certain default keybinds unmap("f", "CTRL|SHIFT"), unmap("w", "CTRL|SHIFT"), 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") + ), + -- }}} } -- }}} diff --git a/home/features/neovim/config/lazy-lock.json b/home/features/neovim/config/lazy-lock.json index 2f349bd..0872ed6 100644 --- a/home/features/neovim/config/lazy-lock.json +++ b/home/features/neovim/config/lazy-lock.json @@ -38,6 +38,7 @@ "mini.pairs": { "branch": "main", "commit": "04f58f2545ed80ac3b52dd4826e93f33e15b2af6" }, "mini.statusline": { "branch": "main", "commit": "dfd3d2ba295473930f78f143852b9b53eb54ae2a" }, "mini.surround": { "branch": "main", "commit": "a1b590cc3b676512de507328d6bbab5e43794720" }, + "navigator": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "neoconf": { "branch": "main", "commit": "4ef6c6c5882e7e16209173fb8c47414202843384" }, "neodev.nvim": { "branch": "main", "commit": "b0ccf605c952eb0d1efe3692d5b241c52ceee187" }, "nui": { "branch": "main", "commit": "c3c7fd618dcb5a89e443a2e1033e7d11fdb0596b" }, diff --git a/home/features/neovim/default.nix b/home/features/neovim/default.nix index c5af1fe..20507f2 100644 --- a/home/features/neovim/default.nix +++ b/home/features/neovim/default.nix @@ -736,7 +736,7 @@ let [ "d" "f" "F" "h" "r" ] ]; - # {{{ Keymaps + # {{{ Keybinds opts.mappings = { add = "s"; # Add surrounding in Normal and Visul modes delete = "d"; # Delete surrounding @@ -1348,6 +1348,20 @@ let }; }; # }}} + # {{{ navigator + navigator = { + package = "numToStr/Navigator.nvim"; + cond = blacklist [ "vscode" "firenvim" "neovide" ]; + + config = true; + keys = [ + (nmap "" "NavigatorLeft" "Navigate left") + (nmap "" "NavigatorDown" "Navigate down") + (nmap "" "NavigatorUp" "Navigate up") + (nmap "" "NavigatorRight" "Navigate right") + ]; + }; + # }}} # }}} }; # }}}