The NERDTree provides two mappings you could use manually to get this effect: Typing cd
on a node changes the directory to it, and typing C
on a node, "enters" it via the NERDTree.
Personally, I often combine them -- just type Ccd
-- the C
will enter the directory and leave the cursor on it, and a cd
will change the working directory to it.
Now, if you do want to create just one mapping to use directly, you could use the NERDTree's extension mechanism. Read up on :help NERDTreeAPI
for the details, but the short version is: put a file in ~/.vim/nerdtree_plugin/cd_mapping.vim
with the following contents:
call NERDTreeAddKeyMap({
\ 'key': '_C',
\ 'callback': 'NERDTreeEnterDirectoryAndCD',
\ 'quickhelpText': 'Enter directory and cd into it' })
function! NERDTreeEnterDirectoryAndCD()
let node = g:NERDTreeDirNode.GetSelected()
exec 'cd ' . node.path.str({'format': 'Cd'})
NERDTreeCWD
endfunction
This should do the trick with the keybinding _C
. Change the key
property to whatever you'd like the key to be.