Automatically quit vim if NERDTree is last and only buffer

后端 未结 5 719
鱼传尺愫
鱼传尺愫 2020-12-07 22:36

I have the following in my .vimrc:

\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"         


        
相关标签:
5条回答
  • 2020-12-07 22:38

    You could :cabbrv q qa but I'd advise against that because you'll forget about it when you actually want q.

    0 讨论(0)
  • 2020-12-07 22:41

    I like to do this: cmap bq :bufdo q<CR> to close all buffers with two keystrokes in command mode.

    0 讨论(0)
  • 2020-12-07 22:44

    A script to do exactly this has been posted on the NERDTree issue list. Checkout issue-21 on GitHub for nerdtree.

    This leads to the single line command for your vimrc here:

    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
    
    0 讨论(0)
  • 2020-12-07 22:48
    function! s:CloseIfOnlyControlWinLeft()
      if winnr("$") != 1
        return
      endif
      if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
            \ || &buftype == 'quickfix'
        q
      endif
    endfunction
    augroup CloseIfOnlyControlWinLeft
      au!
      au BufEnter * call s:CloseIfOnlyControlWinLeft()
    augroup END
    

    From my vimrc, based on a version from janus repo.

    Enhancements: also close if only a quickfix window is left. It uses the BufEnter autocommand instead, which is required for &bt to work properly.

    0 讨论(0)
  • 2020-12-07 22:48

    An idea in need of implementation:

    You could write a function which, when called, checks if the only buffer remaining (or perhaps the only non-help buffer, if you prefer) is a NERDTree buffer and, if so, deletes it (or just quits).

    Then have an autocmd run it whenever a buffer is deleted / hidden / whatever actually happens when you :q (it shames me to admit I'm not entirely sure!).

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