Auto-open NERDTree in “EVERY” tab

后端 未结 7 2146
说谎
说谎 2020-11-30 22:10

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

相关标签:
7条回答
  • 2020-11-30 22:24
    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
    
    0 讨论(0)
  • 2020-11-30 22:30
    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 ^^

    0 讨论(0)
  • 2020-11-30 22:30

    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.

    0 讨论(0)
  • 2020-11-30 22:32

    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.

    0 讨论(0)
  • 2020-11-30 22:35

    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.

    0 讨论(0)
  • 2020-11-30 22:36

    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

    0 讨论(0)
提交回复
热议问题