From 35f527f64310cf36fb03e5f43b48ab98db59ee06 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Tue, 17 Feb 2026 23:27:16 -0500 Subject: [PATCH] Add vim-tmux-navigator for seamless pane navigation --- config/tmux/tmux.conf | 19 +++++++++++++++++++ migrations/1771386669.sh | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 migrations/1771386669.sh diff --git a/config/tmux/tmux.conf b/config/tmux/tmux.conf index 79df1da5..eb692b87 100644 --- a/config/tmux/tmux.conf +++ b/config/tmux/tmux.conf @@ -29,6 +29,25 @@ bind -n C-M-S-Down resize-pane -D 5 bind -n C-M-S-Up resize-pane -U 5 bind -n C-M-S-Right resize-pane -R 5 +# Smart pane switching with awareness of Vim splits. +# See: https://github.com/christoomey/vim-tmux-navigator +is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ + | grep -iqE '^[^TXZ ]+ +(\\S+/)?g?\\.?(view|l?n?vim?x?|fzf)(diff)?(-wrapped)?$'" +bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L' +bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D' +bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U' +bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R' +if-shell -b '[ "$(echo "$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p") < 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" +if-shell -b '[ "$(echo "$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p") >= 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" + +bind-key -T copy-mode-vi 'C-h' select-pane -L +bind-key -T copy-mode-vi 'C-j' select-pane -D +bind-key -T copy-mode-vi 'C-k' select-pane -U +bind-key -T copy-mode-vi 'C-l' select-pane -R +bind-key -T copy-mode-vi 'C-\' select-pane -l + # Window navigation bind r command-prompt -I "#W" "rename-window -- '%%'" bind c new-window -c "#{pane_current_path}" diff --git a/migrations/1771386669.sh b/migrations/1771386669.sh new file mode 100644 index 00000000..4916a285 --- /dev/null +++ b/migrations/1771386669.sh @@ -0,0 +1,24 @@ +echo "Add vim-tmux-navigator plugin for seamless tmux/nvim navigation" + +mkdir -p ~/.config/nvim/lua/plugins + +cat > ~/.config/nvim/lua/plugins/tmux-navigator.lua << 'EOF' +return { + "christoomey/vim-tmux-navigator", + cmd = { + "TmuxNavigateLeft", + "TmuxNavigateDown", + "TmuxNavigateUp", + "TmuxNavigateRight", + "TmuxNavigatePrevious", + "TmuxNavigatorProcessList", + }, + keys = { + { "", "TmuxNavigateLeft" }, + { "", "TmuxNavigateDown" }, + { "", "TmuxNavigateUp" }, + { "", "TmuxNavigateRight" }, + { "", "TmuxNavigatePrevious" }, + }, +} +EOF