Add smart window switching

This commit is contained in:
Sebastian Bugge 2023-02-27 00:30:52 +01:00
parent 1f2f05884e
commit f67a54cadd
No known key found for this signature in database
GPG key ID: 49D435DEDD6B2829

View file

@ -12,17 +12,26 @@ unbind %
# reload config file (change file location to your the tmux.conf you want to use) # 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!' 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'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
# switch panes using Alt-arrow without prefix bind-key -T copy-mode-vi 'C-j' select-pane -D
set -s escape-time 0 # Disable esc=alt bind-key -T copy-mode-vi 'C-k' select-pane -U
bind -n M-h select-pane -L bind-key -T copy-mode-vi 'C-l' select-pane -R
bind -n M-l select-pane -R bind-key -T copy-mode-vi 'C-\' select-pane -l
bind -n M-j select-pane -U bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+
bind -n M-k select-pane -D
# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on
# Don't rename windows automatically # Don't rename windows automatically
set-option -g allow-rename off set-option -g allow-rename off