diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-10-23 14:04:53 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-10-23 14:04:53 +0200 |
commit | e9f0509e71ba79fb92bb55933d19b63d2fd11ef4 (patch) | |
tree | ddd152ade759d2a8ff4788ebec851951d2131ea3 | |
parent | 2993a95e1f6f11ac463a1befb23be17bdcf4ec28 (diff) |
use vim-tmux-navigator plugin
-rwxr-xr-x | config/common/tmux/tmux.conf | 32 | ||||
-rw-r--r-- | config/essentials/nvim/after/plugin/vim-tmux-navigator.lua | 6 | ||||
-rw-r--r-- | config/essentials/nvim/lua/user/packer.lua | 2 |
3 files changed, 35 insertions, 5 deletions
diff --git a/config/common/tmux/tmux.conf b/config/common/tmux/tmux.conf index 45166c0..5867a92 100755 --- a/config/common/tmux/tmux.conf +++ b/config/common/tmux/tmux.conf @@ -62,12 +62,34 @@ bind J command-prompt -1p "Send to window:" "join-pane -t \:%% ; select-window - bind b break-pane -t : # Reset length and shit bind z select-layout main-vertical + + + + # Pane navigating with h|j|k|l a la vim -bind -n -N "select leftwards pane" M-h select-pane -L -bind -n -N "select downwards pane" M-j select-pane -D -bind -n -N "select upwards pane" M-k select-pane -U -bind -n -N "select rightwards pane" M-l select-pane -R -# Window navigating with M-u|i +# 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|l?n?vim?x?|fzf)(diff)?$'" +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' +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 '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 'M-\' select-pane -l + + + + bind -n M-u previous-window bind -n M-i next-window # Session navigeting with S-M-u|i diff --git a/config/essentials/nvim/after/plugin/vim-tmux-navigator.lua b/config/essentials/nvim/after/plugin/vim-tmux-navigator.lua new file mode 100644 index 0000000..c7042fd --- /dev/null +++ b/config/essentials/nvim/after/plugin/vim-tmux-navigator.lua @@ -0,0 +1,6 @@ +vim.cmd("let g:tmux_navigator_no_mappings = 1") +vim.keymap.set("n", "<M-h>", ":<C-U>TmuxNavigateLeft<cr>", {silent = true}) +vim.keymap.set("n", "<M-j>", ":<C-U>TmuxNavigateDown<cr>", {silent = true}) +vim.keymap.set("n", "<M-k>", ":<C-U>TmuxNavigateUp<cr>", {silent = true}) +vim.keymap.set("n", "<M-l>", ":<C-U>TmuxNavigateRight<cr>", {silent = true}) +vim.keymap.set("n", "<M-/>", ":<C-U>TmuxNavigatePrevious<cr>", {silent = true}) diff --git a/config/essentials/nvim/lua/user/packer.lua b/config/essentials/nvim/lua/user/packer.lua index 94d4dff..36f9ec0 100644 --- a/config/essentials/nvim/lua/user/packer.lua +++ b/config/essentials/nvim/lua/user/packer.lua @@ -43,6 +43,8 @@ return require('packer').startup(function(use) use('tpope/vim-vinegar') use('m4xshen/autoclose.nvim') + use('christoomey/vim-tmux-navigator') + -- utils use('godlygeek/tabular') use('renerocksai/calendar-vim') |