From e9f0509e71ba79fb92bb55933d19b63d2fd11ef4 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 23 Oct 2023 14:04:53 +0200 Subject: use vim-tmux-navigator plugin --- config/common/tmux/tmux.conf | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'config/common/tmux') diff --git a/config/common/tmux/tmux.conf b/config/common/tmux/tmux.conf index 45166c0..5867a92 100755 --- a/config/common/tmux/tmux.conf +++ b/config/common/tmux/tmux.conf @@ -62,12 +62,34 @@ bind J command-prompt -1p "Send to window:" "join-pane -t \:%% ; select-window - bind b break-pane -t : # Reset length and shit bind z select-layout main-vertical + + + + # Pane navigating with h|j|k|l a la vim -bind -n -N "select leftwards pane" M-h select-pane -L -bind -n -N "select downwards pane" M-j select-pane -D -bind -n -N "select upwards pane" M-k select-pane -U -bind -n -N "select rightwards pane" M-l select-pane -R -# Window navigating with M-u|i +# 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)?$'" +bind-key -n 'M-h' if-shell "$is_vim" 'send-keys M-h' 'select-pane -L' +bind-key -n 'M-j' if-shell "$is_vim" 'send-keys M-j' 'select-pane -D' +bind-key -n 'M-k' if-shell "$is_vim" 'send-keys M-k' 'select-pane -U' +bind-key -n 'M-l' if-shell "$is_vim" 'send-keys M-l' 'select-pane -R' +tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")' +if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" +if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" + +bind-key -T copy-mode-vi 'M-h' select-pane -L +bind-key -T copy-mode-vi 'M-j' select-pane -D +bind-key -T copy-mode-vi 'M-k' select-pane -U +bind-key -T copy-mode-vi 'M-l' select-pane -R +bind-key -T copy-mode-vi 'M-\' select-pane -l + + + + bind -n M-u previous-window bind -n M-i next-window # Session navigeting with S-M-u|i -- cgit v1.2.3