Auto-open NERDTree in "EVERY" tab

Viewed 28571

Is it possible to open NERDTree in every tab with pressing t or T in NERDTree, if yes, How?

7 Answers

This is probably not the best way, but if you edit plugin/NERDTree.vim and change this:

 exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTab ." :call <SID>openInNewTab(0)<cr>"

to this:

 exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTab ." :call <SID>openInNewTab(0)<cr>:NERDTree<cr>"

it will alter the binding of 't' in the NERDTree view to first open the file and then open NERDTree. Note, that the NERDTree views will not keep in sync.

This problem was actually mentioned in the official Repository's Readme file including three situations related to opening NERDTree automatically:


How can I open a NERDTree automatically when vim starts up?

Stick this in your vimrc: autocmd vimenter * NERDTree


How can I open a NERDTree automatically when vim starts up if no files were specified?

Stick this in your vimrc:

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

Note: Now start vim with plain vim, not vim .


How can I open NERDTree automatically when vim starts up on opening a directory?

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif

This window is tab-specific, meaning it's used by all windows in the tab. This trick also prevents NERDTree from hiding when first selecting a file.

Related