Auto-open NERDTree in “EVERY” tab

2019-01-08 07:28发布

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

标签: vim nerdtree
7条回答
Luminary・发光体
2楼-- · 2019-01-08 07:34

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.

查看更多
别忘想泡老子
3楼-- · 2019-01-08 07:42

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-08 07:45

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.

查看更多
做个烂人
5楼-- · 2019-01-08 07:47
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 ^^

查看更多
Anthone
6楼-- · 2019-01-08 07:51
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
查看更多
虎瘦雄心在
7楼-- · 2019-01-08 07:52

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.

查看更多
登录 后发表回答