From eaf9c23a97806a58037e880427f2c6503692aa49 Mon Sep 17 00:00:00 2001 From: Hans Goor Date: Mon, 25 Mar 2024 21:11:57 +0100 Subject: [PATCH] Integrate tmux with some vim bindings. --- tmux/.tmux.conf | 3 +++ tmux/.tmux/bindings.conf | 10 +++++----- tmux/.tmux/nvim.conf | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tmux/.tmux/nvim.conf diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index f364508..2e09a62 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -11,6 +11,9 @@ source $HOME/.tmux/plugin-configs/rose-pine.conf # General config source $HOME/.tmux/globals.conf +# Nvim helper +source $HOME/.tmux/nvim.conf + # Keybindings source $HOME/.tmux/bindings.conf diff --git a/tmux/.tmux/bindings.conf b/tmux/.tmux/bindings.conf index 1b59405..f32cb9d 100644 --- a/tmux/.tmux/bindings.conf +++ b/tmux/.tmux/bindings.conf @@ -8,10 +8,10 @@ bind c new-window -c "#{pane_current_path}" unbind '"' unbind % bind | split-window -h -c "#{pane_current_path}" -bind - split-window -v "#{pane_current_path}" +bind - split-window -v -c "#{pane_current_path}" # Alt-arrow switching -bind -n M-Left select-pane -L -bind -n M-Right select-pane -R -bind -n M-Up select-pane -U -bind -n M-Down select-pane -D +# bind -n M-Left select-pane -L +# bind -n M-Right select-pane -R +# bind -n M-Up select-pane -U +# bind -n M-Down select-pane -D diff --git a/tmux/.tmux/nvim.conf b/tmux/.tmux/nvim.conf new file mode 100644 index 0000000..e759de7 --- /dev/null +++ b/tmux/.tmux/nvim.conf @@ -0,0 +1,29 @@ +# helper to decide whether we are inside (n)vim +is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ + | grep -iqE '^[^TXZ ]+ +(\\$+\\/)?g?(view|n?vim?x?)(diff)?$'" + +# Correct binding depending on version +if-shell -b '[[ "$(tmux -V)" == tmux\ 2.* ]]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" +if-shell -b '[[ "$(tmux -V)" == tmux\ 3.* ]]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" + +# Bindings +bind-key -n 'C-Space' if-shell "$is_vim" 'send-keys C-Space' 'select-pane -t:.+' + +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' + +bind-key -n 'M-Left' if-shell "$is_vim" 'send-keys M-h' 'select-pane -L' +bind-key -n 'M-Down' if-shell "$is_vim" 'send-keys M-j' 'select-pane -D' +bind-key -n 'M-Up' if-shell "$is_vim" 'send-keys M-k' 'select-pane -U' +bind-key -n 'M-Right' if-shell "$is_vim" 'send-keys M-l' 'select-pane -R' + +bind-key -T copy-mode-vi 'M-h' select-pane -L +bind-key -T copy-mode-vi 'M-j' select-pane -D +bind-key -T copy-mode-vi 'M-k' select-pane -U +bind-key -T copy-mode-vi 'M-l' select-pane -R +bind-key -T copy-mode-vi 'C-\' select-pane -l +bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+