Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use the right-arrow key to open a node in NERDtree. I see there is NERDTreeAddKeyMap, but I'm too much of a vimscript newb to know how to invoke it properly. I want right-arrow to invoke activateNode. I've done it by adding this line into NERD_tree.vim itself:

exec "nnoremap <silent> <buffer> <Right> :call <SID>activateNode(0)<cr>"

but I want to do it the right way in my .vimrc

share|improve this question

:help NERDTreeAddKeyMap() will show you how to write a small plugin for NERDTree. Because you are calling a built-in NERDTree function you don't even need a custom one.

share|improve this answer
I was hoping for more detail here... I know nothing about vimscript. – Ned Batchelder Apr 9 '12 at 14:30

I think that, barring a limitation in the version I'm using (4.2.0), the following will do what you want.

In a mymapping.vim, in ~/.vimfiles/nerdtree_plugin/

" -*- vim -*-
call NERDTreeAddKeyMap({ 'key': "Right", 'scope': "Node", 'callback': "<SID>activateNode" })

Now, to get "Right" to work properly, you'll have to edit NERD_tree.vim, in:

"FUNCTION: KeyMap.bind() {{{3
function! s:KeyMap.bind()


if mapkey =~? '^\([CM]-\|middlerelease\|2-leftmouse\|leftrelease\)'


if mapkey =~? '^\([CM]-\|middlerelease\|2-leftmouse\|leftrelease\|right\)'

The old code didn't do special handling for mapping keys that weren't <MiddleRelease>, <2-LeftMouse>, or <LeftRelease>

share|improve this answer
Probably should add that I don't think that you can do it "in your .vimrc" exactly. Because the mapping depends on the plugin being loaded, I think the only way to do it is in a separate file like I outline above. – pottsdl Apr 20 '12 at 16:49

Your Answer


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.