Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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!
    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...
endfunction

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.

share|improve this answer
    
Yay, it works. BTW, Function name must start with a capital or contain a colon –  hhaamu Jul 14 '12 at 7:41
    
ya, forgot the capital... not bad for off the cuff... yes? glad it works for you. –  lornix Jul 14 '12 at 10:02
    
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. –  William Herschel Feb 6 '13 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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