From fcdb23e156fa2b98367da8e7af8a347ee2400656 Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Tue, 4 May 2021 22:38:09 +0100 Subject: [PATCH] vim: Add christoomey/vim-tmux-navigator --- tag-tmux/tmux.conf | 19 +++++++++++++++++++ tag-vim/config/nvim/init.vim | 1 + 2 files changed, 20 insertions(+) diff --git a/tag-tmux/tmux.conf b/tag-tmux/tmux.conf index 4912ab55..8f9d9dfc 100644 --- a/tag-tmux/tmux.conf +++ b/tag-tmux/tmux.conf @@ -53,3 +53,22 @@ bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$( bind-key C-b send-keys 'tat && exit' 'C-m' bind-key K run-shell 'tmux switch-client -n \; kill-session -t "$(tmux display-message -p "#S")" || tmux kill-session' +# 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' +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 '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 diff --git a/tag-vim/config/nvim/init.vim b/tag-vim/config/nvim/init.vim index a6b0443a..2da9fe98 100644 --- a/tag-vim/config/nvim/init.vim +++ b/tag-vim/config/nvim/init.vim @@ -28,6 +28,7 @@ set smartindent " Plugins call plug#begin('~/.vim/plugged') Plug 'arcticicestudio/nord-vim' +Plug 'christoomey/vim-tmux-navigator' Plug 'editorconfig/editorconfig-vim' Plug 'jiangmiao/auto-pairs' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }