Search code examples
vimvim-plugin

How can I keep my custom keybindings with NERDTree?


I'm a Colemak vim user and so I have to use custom keybindings. Is there a way to extend these keybindings also to the NERDTree plugin?

Thanks in advance.


Solution

  • If you check the built-in documentation for NERDTree mappings with :help NERDTreeMappings, you'll find a full list of all mappings, with descriptions. One of the parts in the descriptions is Map option. Changing that setting will change the mapping (including in the built-in help that shows up with the ? key).

    For example, here's the entry for the "o" key: https://github.com/scrooloose/nerdtree/blob/master/doc/NERDTree.txt#L297-L310

    The mapping is defined by NERDTreeMapActivateNode. So, in order to change that to whatever is appropriate on your colemak keyboard, you'd need to put this in your ~/.vimrc file:

    let g:NERDTreeMapActivateNode = "p"
    

    ... or whatever is in the place of "o" in the real colemak layout.

    You'd have to go through all mappings that interest you, and replace them with whatever you need. And be careful that they don't conflict. It's a lot of variables, but it's probably the most reliable way.

    Alternatively, you can make buffer-local mappings for the nerdtree filetype (put nnoremap <buffer> o p in the file ~/.vim/ftplugin/nerdtree.vim), but I don't recommend it, because pressing ? will not show you these.