Change root in NERDTree
Asked Answered
C

4

28

I tried to change the NERDTree root with

:BookmarkToRoot <bookmark>

command and with C letter but when I close vim and open vim the root is not changed.

Do you know how to change the root forever?

Charliecharline answered 28/4, 2011 at 11:16 Comment(1)
see this similar question: #5801340Compensable
M
47

You could try something like:

nnoremap <leader>n :NERDTree /path/to/folder<CR>

I have this in my .vimrc:

set autochdir
let NERDTreeChDirMode=2
nnoremap <leader>n :NERDTree .<CR>

so that NERDTree always opens in the current folder.

With the 1st line, the working directory is always the one where the active buffer is located.

With the 2nd line, I make sure the working directory is set correctly.

With the 3rd line, I hit <leader>n to open NERDTree.

Mcintire answered 28/4, 2011 at 12:7 Comment(3)
Thank you, you advised me many other good settings. Is it possible when I set the new root in NERDTree with C command that it will automatically set the /path/to/folder in .vimrc file? Or should I always edit .vimrc file manually?Charliecharline
Now when I start vim, NERDTree has root always ~ so I have to press <leader>n to open in the root I wish.Charliecharline
Greate, NERDTreeChDirMode=2 is what I wanted.Borghese
J
1

As i don't want vim to change directories automatically, i just use:

com! -nargs=1 -complete=dir Ncd NERDTree | cd <args> |NERDTreeCWD

so you can just do a ":Ncd path/you/like/" with path completion.

Justiciary answered 3/1, 2016 at 20:46 Comment(0)
R
1

Quickest what worked form me was just :cd new-root, close :q and reopen :NERDTree.

Rachealrachel answered 31/5, 2022 at 6:38 Comment(0)
L
0

I simply changed the “Working Directory:” of my GVim launcher to where I wanted the root to be.

enter image description here

Leeway answered 5/1, 2023 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.