2

I have installed vim-tmux-navigator on the tmux and the vim side and I can navigate between vim panes and tmux windows using Ctrl-[hjkl]

BUT: This means that readline (or bash?) shortcuts are overwritten, e.g. Ctrl-k (delete to end-of-line), which I want to use.

All my attempts to remap keys to require the the tmux-prefix, e.g. Ctrl-b [hjkl] vim-tmux-navigator have failed.

Does anyone have a solution for this?

Note: I am using C-b as an example, for which there is a good solution below. I have been using C-Space wich complicates things a little.

3

Yes, it's possible to remap the keybindings in order to use <C-b> (your tmux prefix) followed by [hjkl] to change panes, and \ to go to the previous pane.

Note that you need to configure that both in Vim and in tmux.

This is the Vim configuration for those keybindings:

let g:tmux_navigator_no_mappings = 1

nnoremap <silent> <C-b>h :TmuxNavigateLeft<cr>
nnoremap <silent> <C-b>j :TmuxNavigateDown<cr>
nnoremap <silent> <C-b>k :TmuxNavigateUp<cr>
nnoremap <silent> <C-b>l :TmuxNavigateRight<cr>
nnoremap <silent> <C-b>\ :TmuxNavigatePrevious<cr>

Add those lines to your .vimrc.

And in your .tmux.conf, use the snippet (not the TPM) to configure it, then change the main bindings to:

bind-key h if-shell "$is_vim" "send-keys C-b h"  "select-pane -L"
bind-key j if-shell "$is_vim" "send-keys C-b j"  "select-pane -D"
bind-key k if-shell "$is_vim" "send-keys C-b k"  "select-pane -U"
bind-key l if-shell "$is_vim" "send-keys C-b l"  "select-pane -R"
bind-key \ if-shell "$is_vim" "send-keys C-b \\" "select-pane -l"

(In short, remove the C- part, and also the -n which makes them run without a prefix. Then update the send-keys to send the keys Vim is expecting, which are the same ones, with the prefix.)

You might want to update the copy-mode-vi keybindings too, though it's unclear which keys you would like to use there, since there's no "prefix" enabled in that mode... You might want to think about that one.

| improve this answer | |
  • darn, while my comment does nicely avoid the tmux prefix, it only works in command mode: – Richard Wonka Aug 6 '19 at 8:59
  • @RichardWonka Did this one work for you? I'm not a user of the tmux-navigator myself, but I'd expect it should fix the issue you were having... – filbranden Aug 6 '19 at 13:28
  • It almost does - it does with <C-b> as prefix. I can pass the keys back and forth between vim and tmux. but, I've been using <C-Space> as a prefix, which is very convenient - and it appears that passing <C-Space> isn't as intuitive as passing <C-b> .. so I am now looking at either finding out how to pass that particular prefix or changing my prefix, which would be a bummer. – Richard Wonka Aug 7 '19 at 6:17
  • I'd expect C-space to work in tmux (i.e. "send-keys C-space h") and <C-Space> to work in vim... Sometimes <C-Space> doesn't work directly in Vim terminal, so additionally to the 5 directional mappings, also add nmap <C-@> <C-Space> which will make the others work, when your Ctrl+Space appears to Vim as <C-@> instead. I hope that helps! – filbranden Aug 7 '19 at 6:31
  • 1
    Yeah, <C-w> is a great choice! Glad you found a setup that works well for you. – filbranden Aug 7 '19 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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