Can someone explain why remaps to navigate across windows like nmap <C-h> <C-w>h
does not work when in the netrw window? Is there any reason why? Is there a setting to enable them?
1 Answer
The reason is that the netrw
buffer defines a buffer
mapping for <C-h>
.
The solution is to override that buffer
mapping:
autocmd! FileType netrw nnoremap <buffer> <C-h> <C-w>h
An alternative is to create a ~/vimfiles/ftplugin/netrw.vim
with the following content:
nnoremap <buffer> <C-h> <C-w>h
For earlier version of Vim the buffer mapping were reset every time the netrw view were visited. In such case you have to do:
autocmd WinEnter * if &ft=='netrw' | nnoremap <buffer><C-h> <C-w>h | endif
-
1It would be nice if you also mentioned ftplugins for things like this.– D. Ben Knoble ♦Commented Jun 14 at 11:58
-
I added the remaps into a new file called
netrw.vim
under~/.vim/after/plugin
, but it does not work. Indeed, I also tried the autocmds in the mainvimrc
file, also not working. EDIT: I forgot the<buffer>
argument. Now seems to be working.– mEmCommented Jun 14 at 12:07 -
Last somewhat related question: why instead the remap
nmap <A-h> <C-w>2<
does not work at all, even in normal buffers? I even tried changing tonmap <A-h> <C-w>2<S-,>
, also not working.– mEmCommented Jun 14 at 12:12 -
Maybe you should post another question about that to not confuse future readers. Did you tried <C-h> instead of <A-h>? What is the operating system that you are using (Linux, Windows, macOS)? Commented Jun 14 at 12:19
-
@VivianDeSmedt strangely enough, your solution works in my target env (it's a cluster), but not on my local machine. The only difference in versioning is: local
vim --version
printsVIM - Vi IMproved 8.2 (2019 Dec 12, compiled May 03 2024 02:37:51)
, remoteVIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 09 2023 00:00:00)
. Might that be the cause?– mEmCommented Jun 14 at 15:08