Skip to content

Commit 5b3c701

Browse files
authored
fix: workaround netrw mapping for ctrl-l (#393)
This adds a workaround for the netrw keymapping conflict for ctrl-l by setting the `g:Netrw_UserMaps` list. To limit the impact to users, this will leave the list alone if the user has already set the variable and instead gives a warning to prompt the user about the issue. This mapping workaround can be disabled by setting either `g:tmux_navigator_no_mappings` or `g:tmux_navigator_disable_netrw_workaround`. Fixes #189, Fixes #251, Fixes #379
1 parent c600cf1 commit 5b3c701

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,27 @@ instead of having to use a different prefix (ctrl-a by default) which you may
356356
find convenient. If not, simply remove the lines that set/unset the prefix key
357357
from the code example above.
358358
359+
#### netrw
360+
361+
Vim's builtin file explorer, named the netrw plugin, has a default keymapping
362+
for `<C-l>`. When using `vim-tmux-navigator` with default settings,
363+
`vim-tmux-navigator` will try to override the netrw mapping so that `<C-l>` will
364+
still be mapped to `:TmuxNavigateRight` as it is for other buffers. If you
365+
prefer to keep the netrw mapping, set this variable in your vimrc:
366+
367+
``` vim
368+
let g:tmux_navigator_disable_netrw_workaround = 1
369+
```
370+
371+
Alternatively, if you prefer to work around the issue yourself, you can add the
372+
following to your vimrc:
373+
374+
``` vim
375+
let g:tmux_navigator_disable_netrw_workaround = 1
376+
" g:Netrw_UserMaps is a list of lists. If you'd like to add other key mappings,
377+
" just add them like so: [['a', 'command1'], ['b', 'command2'], ...]
378+
let g:Netrw_UserMaps = [['<C-l>', '<C-U>TmuxNavigateRight<cr>']]
379+
```
359380
360381
Troubleshooting
361382
---------------

doc/tmux-navigator.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ CONFIGURATION *tmux-navigator-configuration*
3636
nnoremap <silent> {Right-Mapping} :<C-U>TmuxNavigateRight<cr>
3737
nnoremap <silent> {Previous-Mapping} :<C-U><C-U>TmuxNavigatePrevious<cr>
3838

39+
* Disable the <C-l> remapping on netrw buffers (use netrw's mapping)
40+
let g:tmux_navigator_disable_netrw_workaround = 1
41+
3942
vim:tw=78:ts=8:ft=help:norl:

plugin/tmux_navigator.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ if !get(g:, 'tmux_navigator_no_mappings', 0)
2121
nnoremap <silent> <c-k> :<C-U>TmuxNavigateUp<cr>
2222
nnoremap <silent> <c-l> :<C-U>TmuxNavigateRight<cr>
2323
nnoremap <silent> <c-\> :<C-U>TmuxNavigatePrevious<cr>
24+
25+
if !get(g:, 'tmux_navigator_disable_netrw_workaround', 0)
26+
if !exists('g:Netrw_UserMaps')
27+
let g:Netrw_UserMaps = [['<C-l>', '<C-U>TmuxNavigateRight<cr>']]
28+
else
29+
echohl ErrorMsg | echo 'vim-tmux-navigator conflicts with netrw <C-l> mapping. See https://github.com/christoomey/vim-tmux-navigator#netrw or add `let g:tmux_navigator_disable_netrw_workaround = 1` to suppress this warning.' | echohl None
30+
endif
31+
endif
2432
endif
2533

2634
if empty($TMUX)

0 commit comments

Comments
 (0)