From 2d24894ead376a712c25a66c57c5245d7c8d7001 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 7 Apr 2024 19:12:06 +0200 Subject: Dotfiles: Tmux: Fix nvim-tmux window switching for nixos --- dotfiles/tmux.conf | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'dotfiles') diff --git a/dotfiles/tmux.conf b/dotfiles/tmux.conf index 8b733a7..6662ba4 100644 --- a/dotfiles/tmux.conf +++ b/dotfiles/tmux.conf @@ -46,6 +46,25 @@ bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel bind '"' split-window -v -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" +# 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 'n?vim?x?'" # This is changed from the default due to it not working on Nix; see https://github.com/christoomey/vim-tmux-navigator/issues/195 +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 + resurrect_dir="$HOME/.tmux/resurrect" set -g @resurrect-dir $resurrect_dir set -g @resurrect-capture-pane-contents 'on' @@ -62,7 +81,6 @@ set -g @yank_selection 'primary' set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' -set -g @plugin 'christoomey/vim-tmux-navigator' set -g @plugin 'catppuccin/tmux' set -g @plugin 'baitinq/tmux-yank' #has https://github.com/tmux-plugins/tmux-yank/pull/177 set -g @plugin 'tmux-plugins/tmux-resurrect' -- cgit 1.4.1