1

I'm trying to use vim-tmux-navigator. I'd like to use default key bindings to move between vim and tmux splits. Which is <C-W>hjkl.

But it isn't working. Either you can't remap anything with C-W prefix or something else, I don't know. Is this possible?

I know that a lot of people use <C-l> to switch between splits, but I don't like it. I'd like to use default bindings for that.

let g:tmux_navigator_no_mappings = 1

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

Here is my config. I can confirm again, that it isn't working for me. It's moves between vim splits without a problem, but isn't calling TmuxNavigate commands obviously, because can't move to another tmux split. At the same time it's moving between vim and tmux splits perfectly when issuing TmuxNavigate command manually.

Which is why I created this question in the first place. Guys, are you sure this is working for you?

3
  • 1
    Perhaps there is some other plugin that's messing with it? Have you tried with only that plugin enabled?
    – Tumbler41
    Jul 1, 2016 at 14:11
  • Make sure you actually need windows enough to warrant such a contrived mechanism.
    – romainl
    Jul 1, 2016 at 15:01
  • @romainl Of course I need windows. It's not contrived, many people using it. And it's not other plugins as well, because this keys do what they do in vanilla vim perfectly, which is moving around splits. Jul 1, 2016 at 18:43

2 Answers 2

1

Some commands are defined by the plugin, you can use them:

nnoremap <C-W>l :TmuxNavigateRight<CR>

Have a look at the plugin's code for more informations.

And note you can also disable the default mapping with the variable:

g:tmux_navigator_no_mappings
2
  • Have you tried that? I've already done that. It's not working for me. Jul 1, 2016 at 13:53
  • Yes, and it's working here.
    – nobe4
    Jul 1, 2016 at 13:53
1

This is actually answered in an issue on vim-tmux-navigator and the solution works for me:

.tmux.conf

bind-key -n C-w switch-client -T VIMWINDOWS
bind-key -T VIMWINDOWS h if-shell "$is_vim" "send-keys C-a C-h"  "select-pane -L"
bind-key -T VIMWINDOWS j if-shell "$is_vim" "send-keys C-a C-j"  "select-pane -D"
bind-key -T VIMWINDOWS k if-shell "$is_vim" "send-keys C-a C-k"  "select-pane -U"
bind-key -T VIMWINDOWS l if-shell "$is_vim" "send-keys C-a C-l"  "select-pane -R"

vimrc

nnoremap <silent> <c-a><c-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <c-a><c-j> :TmuxNavigateDown<cr>
nnoremap <silent> <c-a><c-k> :TmuxNavigateUp<cr>
nnoremap <silent> <c-a><c-l> :TmuxNavigateRight<cr>

Your Answer

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

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