Close vim NERDtree on close of file

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


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

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

Tags:

Vim

Nerdtree