The "Netrw Directory Listing" you get by opening a directory in vim (e.g. :e .) seems to use a different set of keybindings than plain vim for navigation

I have my hjkl keys remapped thus:

noremap d h
noremap h gj
noremap t gk
noremap n l
noremap e d
noremap l n

But when I press 't' (aka arrow-up) in the directory listing, it actually opens the file under the cursor, instead of going up. How do I implement similar key mappings under this directory listing mode?

2 Answers 2


I'm afraid I don't understand.

[deleted some rambling I babbled on with before I figured out the root cause]

What are you trying to accomplish? Your noremap list there doesn't make sense to me anyways.

Aha! Got it!

You're using a DVORAK keyboard layout, aren't you? NOW the mappings begin to make sense. (Forgot to mention that.. didn't we!)

Looking at the source of the NETRW plugin, it looks like the netrw buffer is setting up BUFFER ONLY nnoremaps... which, of course, override yours. I'm looking for a solution.

From what I can tell, you'd have to do some major surgery to the $VIMRUNTIME/autoload/netrw.vim file, which would make upgrading a pain, and would spew netrw mappings all over your nice clean floor. But another idea struck me:

The netrw plugin sets the filetype to 'netrw' when it opens the buffer, so you could set up an autocommand in your .vimrc to set your needed key conversions as needed in the netrw window.

augroup netrw_dvorak_fix
    autocmd filetype netrw call Fix_netrw_maps_for_dvorak()
augroup END
function! Fix_netrw_maps_for_dvorak()
    noremap <buffer> d h
    noremap <buffer> h gj
    noremap <buffer> t gk
    noremap <buffer> n l
    noremap <buffer> e d
    noremap <buffer> l n
    " and any others...

Sort of has to be done like that since you can't concatenate map commands. Should work for you.

I suppose if you're using the dvorak noremap's throughout, then you could remove the <buffer> modifier.

  • Yay, it works. BTW, Function name must start with a capital or contain a colon
    – hhaamu
    Commented Jul 14, 2012 at 7:41
  • ya, forgot the capital... not bad for off the cuff... yes? glad it works for you.
    – lornix
    Commented Jul 14, 2012 at 10:02
  • 1
    Just to say that Lornix's answer is beyond belief amazing. First of all to figure out the user was using a Dvorak keyboard... that in itself is worthy of Holmes, and then to dig in and figure out the solution. OMG! I had the exact same problem and the solution is exactly the same. Amazing. Commented Feb 6, 2013 at 20:19
  • How could this be extended to switch the keys back to a custom state after the netrw buffer has been closed? Commented Dec 24, 2015 at 20:19

Nowadays, a simpler solution is to put the mappings in .vim/after/ftplugin/netrw.vim:

    noremap <buffer> d h
    noremap <buffer> h gj
    noremap <buffer> t gk
    noremap <buffer> n l
    noremap <buffer> e d
    noremap <buffer> l n

You need <buffer> for the reasons explained by lornix.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .