Question

I'm trying to remap my Alt+x combo into the NERDTree Enter functionality. Let me explain: when I navigate files/folders inside NERDTree, I can open files/expand folders with Enter.

I want to do this with a left-hand key combination like Alt+x. I tried to remap those keys to <CR> and to <Enter>, both none of them worked:

# in ~/.vimrc
nnoremap ≈ <Enter>     " doesn't work
nnoremap ≈ <CR>        " doesn't work
nnoremap ≈ <CR><Enter> " doesn't work

When I say "doesn't work", I mean that when I press Alt+x while exploring files/folders, I move to the next file/folder (which I guess it's like moving to the next line).

Note I'm on a Mac, so is actually the output from Alt+x (it's tested with other mappings).

What should I remap?

Was it helpful?

Solution

Modifiers with Alt (<M- or <A-) is troublesome in a lot of environments, especially in terminals over SSH with a terminal multiplexer, and I therefore try not to use it. Even if I do get it to work on my desktop, it might not work somewhere else for some obscure reason. There's plenty of keybinds to take from. Unless you have a big reason to use Alt, I'd advice against it.


That being said you can find which command is being invoked when pressing Enter (or o) to open a folder in NERDTree using the :verb command. This has to be run while the NERDTree pane is selected:

:verb map <Enter>
n  o           *@:call nerdtree#invokeKeyMap("o")<CR>
        Last set from ~/.vim/bundle/nerdtree/lib/nerdtree/key_map.vim

Now that you the correct command there's no point in hacking with rebinding something else to <Enter> or <CR>.
Generally you'd use <A-x>, but if works for you then that's fine I guess:

:nnoremap ≈ :call nerdtree#invokeKeyMap("o")<CR>

Bottom line:
I would like to note that I don't see why you would want to use such a mapping. You can use o, and you would/should be in close range of this (same could be said for Enter).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top