Is it possible that whenever I select a directory and enter that directory from the NERDTree it should become the root directory? That is, every time I select a new directory the following two commands will be triggered: cd
and :NERDTreeCWD
?
Thanks!
set in your vimrc: let g:NERDTreeChDirMode = 2
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With