0

I recently configured vim-tmux-navigator and I'm enjoying it. However, the binding of ctrl-K overrides the kill to end of line command in the terminal and I use this a lot. As such, I want to bind to Alt equivalents rather than Ctrl.

I made the following changes to the NeoVim plugin configuration.

diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua
index 9215d83..c81bb77 100644
--- a/lua/custom/plugins/init.lua
+++ b/lua/custom/plugins/init.lua
@@ -13,11 +13,11 @@ return {
       "TmuxNavigatePrevious",
     },
     keys = {
-      { "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
-      { "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
-      { "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
-      { "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
-      { "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
+      { "<m-h>", "<cmd>TmuxNavigateLeft<cr>" },
+      { "<m-j>", "<cmd>TmuxNavigateDown<cr>" },
+      { "<m-k>", "<cmd>TmuxNavigateUp<cr>" },
+      { "<m-l>", "<cmd>TmuxNavigateRight<cr>" },
+      { "<m-\\>", "<cmd>TmuxNavigatePrevious<cr>" },
     },
   }
 }

And to the tmux configuration.

diff --git a/.tmux.conf b/.tmux.conf
index 21da869..e1249fa 100644
--- a/.tmux.conf
+++ b/.tmux.conf
@@ -18,19 +18,19 @@ set -g history-limit 8000
 # 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 '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 -n 'M-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
+bind-key -n 'M-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
+bind-key -n 'M-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
+bind-key -n 'M-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'"
+    "bind-key -n 'M-\\' 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 -n 'M-\\' 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
+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

This works in NeoVim and in tmux but not in both together. How can I fix my configuration?

1 Answer 1

1

tmux part of configuration is wrong:

+bind-key -n 'M-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
+bind-key -n 'M-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
+bind-key -n 'M-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
+bind-key -n 'M-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'

See send-keys, they should send M-h/j/k/l instead of C-h/j/k/l to the vim process.

1
  • Beautiful! Works like a charm. Mar 1 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.