When I open a new tab with different path from the previous file in VIM, NERDTree will still remains the same directory hierarchy of the previous file.
Is there a sync shortcut to change the current root directory to the new opened file's directory?
|
When I open a new tab with different path from the previous file in VIM, NERDTree will still remains the same directory hierarchy of the previous file. Is there a sync shortcut to change the current root directory to the new opened file's directory? |
|||
|
|
|
I'm not sure if there's a NERDTree-specific way to do that, but you can always configure Vim so that it sets the working directory to the current file's directory:
Now all what you have to do after opening a file in a new tab is |
|||
|
|
|
I use the following mapping to view the current buffer in NERDTree:
|
|||
|
|
|
I found both the existing answers educational, and successfully combined the two so that the behavior is more like many people would expect from an IDE: Click on an open window/buffer, and have that file highlighted in the NERDTree. I put this in my ~/.vimrc:
What this does:
Note that this won't work on any other buffer that isn't modifiable -- but that's generally a good thing; otherwise (for example) any time you got That one-line solution worked great for me at first, but I soon found that it causes NERDTree to activate any time I opened a file--and as a result, it prevents NERDTree from ever being closed! If you don't want to use NERDTree full-time, put this in your .vimrc instead:
|
||||
|
|
|
I came across this question yesterday, after a few hours of digging, I submited a Pull Request to scrooloose's nerdtree repo introducing a
Compare to @shinzui's and @Lambart's Compare to @Yaser Sulaiman's answer, this solution alwys have a NERD tree window opened and can be easily codable. If a NERD tree window has already been opened, using |
||||
|
|
|
throw a % sign on the end like a boss
i have this in my .vimrc, it maps Ctrl+o to toggle nerdtree in the dir of the current buffer:
|
|||
|
|