I don't know much about NerdTree
, but according to :h NERDTreeKeymapAPI
, you can use
a function provided by the plugin, NERDTreeAddKeyMap()
, to override default mappings:
4.1. Key map API *NERDTreeKeymapAPI*
NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
Adds a new keymapping for all NERD tree buffers.
{options} must be a dictionary, and must contain the following keys:
"key" - the trigger key for the new mapping
"callback" - the function the new mapping will be bound to
"quickhelpText" - the text that will appear in the quickhelp (see
|NERDTree-?|)
"override" - if 1 then this new mapping will override whatever previous
mapping was defined for the key/scope combo. Useful for overriding the
default mappings.
Additionally, a "scope" argument may be supplied. This constrains the
mapping so that it is only activated if the cursor is on a certain object.
That object is then passed into the handling method. Possible values are:
"FileNode" - a file node
"DirNode" - a directory node
"Node" - a file or directory node
"Bookmark" - A bookmark
"all" - the keymap is not constrained to any scope (default). When
thei is used, the handling function is not passed any arguments.
Example: >
call NERDTreeAddKeyMap({
\ 'key': 'foo',
\ 'callback': 'NERDTreeCDHandler',
\ 'quickhelpText': 'echo full path of current node',
\ 'scope': 'DirNode' })
function! NERDTreeCDHandler(dirnode)
call a:dirnode.changeToDir()
endfunction
<
This code should sit in a file like ~/.vim/nerdtree_plugin/mymapping.vim.
It adds a (redundant) mapping on 'foo' which changes vim's CWD to that of
the current dir node. Note this mapping will only fire when the cursor is
on a directory node.
In your case, if you want CR
to act as C-d
, to scroll down half a page, you could write in ~/.vim/after/plugin/my_nerdtree.vim
(you can create the missing directories if ~/.vim/after/plugin/
doesn't exist on your system):
call NERDTreeAddKeyMap({
\ 'key': '<cr>',
\ 'callback': {-> feedkeys("\<c-d>", 'int')},
\ })
More generally, you can use ~/.vim/after/plugin/my_plugin.vim
to override whatever customization
was done by a third-party plugin.
So, if NerdTree
didn't provide this public function, in the same file as before, you could install an autocmd listening to FileType
, which would remap CR
to C-d
, but only in a NerdTree
buffer:
augroup my_nerdtree
au!
au FileType nerdtree nnoremap <buffer> <cr> <c-d>
augroup END
Although, both methods are not exactly equivalent here. The public function seems to provide more control over the mapping, and it could even be more reliable, I don't know.