19

I am trying out Vim, installed some plugins, amongst which NERDTree, followed some guides and set up a .vimrc (half of whose content I don't understand — yet).

What annoys me, is that if I :wq, vim remains active, it only closes the documents' split-screen. I end up with a fullscreen NERDTree. I would like NERDTree to close too, on closing the last tab or buffers.

Or am I using it wrong?

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
berkes
  • 26,996
  • 27
  • 115
  • 206
  • possible duplicate of [Automatically quit vim if NERDTree is last and only buffer.](http://stackoverflow.com/questions/2066590/automatically-quit-vim-if-nerdtree-is-last-and-only-buffer) – berkes Apr 07 '11 at 16:32

3 Answers3

21

Put this in your vimrc:

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") 
      \ && b:NERDTree.isTabTree()) | q | endif

Note: \ is to allow multiple line commands

user2490003
  • 10,706
  • 17
  • 79
  • 155
phildobbin
  • 814
  • 8
  • 9
  • 1
    This solution works better if you don't want to type wqa – aclave1 Aug 17 '14 at 14:31
  • 2
    This does not work for me. Very strange. Any tip on how to find out that. I do not get any errors so I do not if it is run at all. – fossekall Apr 22 '17 at 06:46
  • I find that, it normally work if default open with tree view. If I default open without tree view, and type `:NERDTreeCWD` or `:NERDTreeToggle`, then need `:q` twice. – Mithril Jun 27 '17 at 02:51
19

The :wqa command will write all changed buffers and exit Vim. This will close down NerdTree, too.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
yawmark
  • 1,934
  • 14
  • 16
5

Actually, using :q just close current split so for closing all splits go back to the terminal we should use :qa, this command closes all splits even NERDTree.

There is a shortcut for :wq and it is :x, the :x write the changes and close the current split, if you wanna save all changes and close all splits and go back to the terminal you can use below command too:

:xa

That is equivalent to:

:wqa
AmerllicA
  • 29,059
  • 15
  • 130
  • 154