diff --git a/.tmux.conf b/.tmux.conf index 148fe68..8d50730 100755 --- a/.tmux.conf +++ b/.tmux.conf @@ -19,12 +19,18 @@ bind '"' split-window -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" ### vim/tmux navigation +### https://github.com/christoomey/vim-tmux-navigator set -g focus-events on -is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?$"' -bind -n C-Left if-shell "$is_vim" "send-keys C-h" "select-pane -L" -bind -n C-Down if-shell "$is_vim" "send-keys C-j" "select-pane -D" -bind -n C-Up if-shell "$is_vim" "send-keys C-k" "select-pane -U" -bind -n C-Right if-shell "$is_vim" "send-keys C-l" "select-pane -R" +is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ + | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(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' +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 # change windows bind -n S-Right next-window diff --git a/nvim/lua/custom/plugins/vim-tmux-navigator.lua b/nvim/lua/custom/plugins/vim-tmux-navigator.lua new file mode 100644 index 0000000..10a2348 --- /dev/null +++ b/nvim/lua/custom/plugins/vim-tmux-navigator.lua @@ -0,0 +1,22 @@ +-- Seamless navigation between tmux and vim windows. +-- https://github.com/christoomey/vim-tmux-navigator +return { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateLeft', + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + }, + keys = { + { '', 'TmuxNavigateLeft' }, + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, + init = function() + vim.g.tmux_navigator_disable_when_zoomed = 1 + end, +}