From 9969fc422fcba8a907f85c3de2b556bf77d28e27 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Wed, 30 Aug 2017 23:07:24 +0200 Subject: [PATCH] fix tmux window switching --- tmux.conf | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tmux.conf b/tmux.conf index 2f46465..fa1bd02 100644 --- a/tmux.conf +++ b/tmux.conf @@ -16,16 +16,20 @@ unbind C-b set -g prefix C-a bind C-a send-prefix -# window switching -bind -n C-h select-window -t:- -bind -n C-l select-window -t:+ - -# smart pane switching with awareness of vim splits -bind -nr C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L" -bind -nr C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D" -bind -nr C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U" -bind -nr C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R" -bind -nr C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l" +# 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 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" +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 # splitting panes bind | split-window -h