From f67a54cadd6db7ebe5863f2bc041f526a1bd2c16 Mon Sep 17 00:00:00 2001 From: Sebastian Bugge Date: Mon, 27 Feb 2023 00:30:52 +0100 Subject: [PATCH] Add smart window switching --- .tmux.conf | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index efafa31..6f3bb8a 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -12,17 +12,26 @@ unbind % # reload config file (change file location to your the tmux.conf you want to use) bind r source-file ~/.tmux.conf \; display 'Reloaded tmux config!' +# 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|n?vim?x?)(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 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\' 'select-pane -l'" +if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \ + "bind-key -n 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\\\' 'select-pane -l'" - -# switch panes using Alt-arrow without prefix -set -s escape-time 0 # Disable esc=alt -bind -n M-h select-pane -L -bind -n M-l select-pane -R -bind -n M-j select-pane -U -bind -n M-k select-pane -D - -# Enable mouse control (clickable windows, panes, resizable panes) -set -g mouse on +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 +bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+ # Don't rename windows automatically set-option -g allow-rename off