Auto-open NERDTree in "EVERY" tab
Asked Answered
A

7

44

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

Abramson answered 30/12, 2009 at 10:42 Comment(1)
How do you open it in split view? It works, but it opened the file over it when i double clicked on the file. vim newbie here...Router
U
6

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.

Upstream answered 3/1, 2010 at 20:23 Comment(0)
B
115
autocmd VimEnter * NERDTree
autocmd BufEnter * NERDTreeMirror

edit: The above command seems to open the new tab in NERDTree's buffer. Instead use this as mentioned by wejrowski in the comment below :

autocmd BufWinEnter * NERDTreeMirror
Birthroot answered 4/5, 2010 at 0:25 Comment(5)
You add these to your ~/.vimrcLightfooted
I did this and when I open a file through nerdtree in a new tab "t" it opens the file in a new tab in the side nerdtree panel and makes the main area blank. so there's no nerdtree anymore.Jeromyjerreed
Hmm I fixed it by swapping "autocmd BufEnter * NERDTreeMirror" with "autocmd BufWinEnter * NERDTreeMirror".. seems like it was opening nerdTree then using that nerdtree window to open the bufferJeromyjerreed
this is the wrong answer. use nerdtreetabs. nerdtree is garbage without itMonocoque
Quickfix window doesn't work properly with that.Aerify
L
65

I wrote a vim plugin that does this and also adds some goodies on top (i.e. keeps all trees in sync, ensures meaningful tab captions - not captions like 'NERD_tree_1' etc.).

It's here on Github: https://github.com/jistr/vim-nerdtree-tabs

Lubric answered 13/10, 2011 at 15:14 Comment(4)
this plugin seems to work really well, fixes all of these types of shortcomings in NERDTree. Good job!Lehrer
used for two seconds so far, and i love itSymposium
This is the way NERDTree should work out of the box. Thank you.Jerboa
Thanks so much for writing this dude -- super useful! It still works with the latest version of NERDTree -- hopefully it continues to work.Signorino
S
49
autocmd VimEnter * NERDTree
autocmd BufEnter * NERDTreeMirror

autocmd VimEnter * wincmd w

This one is a little better than Dustin's one because it places the cursor directly on the file you are intending to edit for quick edits. Thanks dustin for the original example ^^

Selfjustifying answered 3/10, 2011 at 20:53 Comment(0)
K
7

A better solution is to open NERDTree only if there are no command line arguments set.

" Open NERDTree in new tabs and windows if no command line args set autocmd VimEnter * if !argc() | NERDTree | endif autocmd BufEnter * if !argc() | NERDTreeMirror | endif

NERDTree is e.g. not helpful if you do a git commit or something similiar.

Kubis answered 6/8, 2014 at 8:26 Comment(0)
U
6

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.

Upstream answered 3/1, 2010 at 20:23 Comment(0)
O
6

How about toggling it.

" in .vimrc
" NERDTree, Use F3 for toggle NERDTree
nmap <silent> <F3> :NERDTreeToggle<CR>

In OSX, you just need to fn-F3 to toggle NERDTree.

Outfielder answered 5/1, 2014 at 4:54 Comment(0)
M
0

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.

Moriyama answered 27/9, 2018 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.