From 469f5bf953d1aa5c20154e216b7cb61347a8f8e4 Mon Sep 17 00:00:00 2001 From: punkfairie <23287005+punkfairie@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:01:07 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(tmux):=20Make=20tmux=20pane=20?= =?UTF-8?q?switching=20smarter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/nvim/lua/plugins/editor.lua | 18 ++++++++++++++++++ .tmux.conf | 29 +++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.config/nvim/lua/plugins/editor.lua b/.config/nvim/lua/plugins/editor.lua index 8556b22..18c03f4 100644 --- a/.config/nvim/lua/plugins/editor.lua +++ b/.config/nvim/lua/plugins/editor.lua @@ -67,4 +67,22 @@ return { "kdheepak/lazygit.nvim", cmd = "LazyGit", }, + + { + "christoomey/vim-tmux-navigator", + cmd = { + "TmuxNavigateLeft", + "TmuxNavigateDown", + "TmuxNavigateUp", + "TmuxNavigateRight", + "TmuxNavigatePrevious", + }, + keys = { + { "", "TmuxNavigateLeft" }, + { "", "TmuxNavigateDown" }, + { "", "TmuxNavigateUp" }, + { "", "TmuxNavigateRight" }, + { "", "TmuxNavigatePrevious" }, + }, + }, } diff --git a/.tmux.conf b/.tmux.conf index c985a34..0dff72f 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -5,6 +5,7 @@ set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' set -g @plugin 'catppuccin/tmux' ################################################################################ @@ -26,6 +27,9 @@ set -g renumber-windows on set -g default-terminal "tmux-256color" set -ag terminal-overrides ",*:RGB" +set -g @continuum-boot 'on' +set -g @continuum-restore 'on' + ################################################################################ # Key Mappings # ################################################################################ @@ -45,11 +49,20 @@ bind -N 'hsplit' - split-window -v -c "#{pane_current_path}" unbind '"' unbind % -# Vi-like pane switching. -bind -N 'Switch to pane (left)' h select-pane -L -bind -N 'Switch to pane (down)' j select-pane -D -bind -N 'Switch to pane (up)' k select-pane -U -bind -N 'Switch to pane (right)' l select-pane -R +# Smart pane switching with awareness of vim/fzf. +IS_VIM="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" +IS_FZF="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?fzf$'" + +bind -n -N 'Switch to pane (left)' C-h if-shell "${IS_VIM} || ${IS_FZF}" 'send C-h' 'select-pane -L' +bind -n -N 'Switch to pane (down)' C-j if-shell "${IS_VIM} || ${IS_FZF}" 'send C-j' 'select-pane -D' +bind -n -N 'Switch to pane (up)' C-k if-shell "${IS_VIM} || ${IS_FZF}" 'send C-k' 'select-pane -U' +bind -n -N 'Switch to pane (right)' C-l if-shell "${IS_VIM} || ${IS_FZF}" 'send C-l' 'select-pane -R' + +# Copy-mode. +bind -T copy-mode-vi -N 'Copy mode: switch to pane (left)' C-h if-shell "${IS_VIM} || ${IS_FZF}" 'send C-h' 'select-pane -L' +bind -T copy-mode-vi -N 'Copy mode: Switch to pane (down)' C-j if-shell "${IS_VIM} || ${IS_FZF}" 'send C-j' 'select-pane -D' +bind -T copy-mode-vn -N 'Copy mode: Switch to pane (up)' C-k if-shell "${IS_VIM} || ${IS_FZF}" 'send C-k' 'select-pane -U' +bind -T copy-mode-vn -N 'Copy mode: Switch to pane (right)' C-l if-shell "${IS_VIM} || ${IS_FZF}" 'send C-l' 'select-pane -R' # Vi-like resizing. bind -r -N 'Resize pane (left)' M-h resize-pane -L 5 @@ -91,7 +104,11 @@ unbind p bind p paste-buffer bind -T copy-mode-vi v send -X begin-selection -bind -T copy-mode-vi y send -X copy-selection-and-cancel +bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'copyq copy -' +bind -T copy-mode-vi ? command-prompt -p '?' 'send -X search-backward %1' +bind -T copy-mode-vi / command-prompt -p '/' 'send -X search-forward %1' +bind -T copy-mode-vi q send -X cancel +bind -T copy-mode-vi Escape if-shell -F '#{selection_present}' 'send -X clear-selection' 'send -X cancel' ################################################################################ # Catppuccin #