NERDTree and tabs together in Vim, painlessly
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>
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.
Commands and Mappings
Vim-nerdtree-tabs defines two commands:
:NERDTreeTabsToggleswitches NERDTree on/off for all tabs.
:NERDTreeToggle, 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
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
On startup, focus NERDTree if opening a directory, focus file if opening a file.
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.)
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!