NERDTree and tabs together in Vim, painlessly
This plugin aims at making NERDTree feel like a true panel, independent of tabs.
Just one NERDTree, always and ever. It will always look the same in all tabs, including expanded/collapsed nodes, scroll position etc.
Open in all tabs / close in all tabs. Do this via
Meaningful tab captions for inactive tabs. No more captions like 'NERD_tree_1'.
When you close a file, the tab closes with it. No NERDTree hanging open.
Autoopen NERDTree on GVim / MacVim startup.
Many of these features can be switched off. See section Configuration.
If you haven't already, install NERDTree (see https://github.com/scrooloose/nerdtree)
Install the plugin through Pathogen:
cd ~/.vim/bundle git clone https://github.com/jistr/vim-nerdtree-tabs.git
Or through Vundle:
Or through Janus:
cd ~/.janus git clone https://github.com/jistr/vim-nerdtree-tabs.git
Map :NERDTreeTabsToggle command to some combo so you don't have to type it. Alternatively, you can use plug-mapping instead of a command, like this:
map <Leader>n <plug>NERDTreeTabsToggle<CR>
Commands and Mappings
Vim-nerdtree-tabs provides these commands:
:NERDTreeTabsOpenswitches NERDTree on for all tabs.
:NERDTreeTabsCloseswitches NERDTree off for all tabs.
:NERDTreeTabsToggletoggles NERDTree on/off for all tabs.
:NERDTreeTabsFindfind currently opened file and select it
:NERDTreeMirror, but smarter: When opening, it first tries to use an existing tree (i.e. previously closed in this tab or perform a mirror of another tab's tree). If all this fails, a new tree is created. It is recommended that you use this command instead of
:NERDTreeMirrorToggletoggles NERDTree on/off in current tab, using the same behavior as
:NERDTreeSteppedOpenfocuses the NERDTree, opening one first if none is present.
:NERDTreeSteppedCloseunfocuses the NERDTree, or closes/hides it if it was not focused.
:NERDTreeFocusTogglefocus the NERDTree or create it if focus is on a file, unfocus NERDTree if focus is on NERDTree
There are also plug-mappings available with the same functionality:
You can switch on/off some features of the plugin by setting global vars to 1 (for on) or 0 (for off) in your vimrc. Here are the options and their default values:
Open NERDTree on gvim/macvim startup
Open NERDTree on console vim startup
Do not open NERDTree if vim starts in diff mode
On startup, focus NERDTree if opening a directory, focus file if opening a file. (When set to
2, always focus file window after startup).
Open NERDTree on new tab creation (if NERDTree was globally opened by :NERDTreeTabsToggle)
Unfocus NERDTree when leaving a tab for descriptive tab names
Close current tab if there is only one window in it and it's NERDTree
Synchronize view of all NERDTree windows (scroll and cursor position)
Synchronize focus when switching windows (focus NERDTree after tab switch if and only if it was focused before tab switch)
When switching into a tab, make sure that focus is on the file window, not in the NERDTree window. (Note that this can get annoying if you use NERDTree's feature "open in new tab silently", as you will lose focus on the NERDTree.)
When given a directory name as a command line parameter when launching Vim,
Automatically find and select currently opened file in NERDTree.
To run NERDTreeTabs on console vim startup, put into your .vimrc:
The tab autoclose feature is stolen from Carl Lerche & Yehuda Katz's Janus. Thanks, guys!