Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close vim NERDtree on close of file

Tags:

vim

nerdtree

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?

like image 684
berkes Avatar asked Apr 07 '11 13:04

berkes


People also ask

How do I close NERDTree in Vim?

If you want to close NERDTree window make sure you are inside the NERDTree menu. You can switch windows by using ctrl+w then type :q to close NERDTree window so that you will be left with the window for editing your code.

How do you close a file in NERDTree?

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

How do I switch between Vim and NERDTree?

After having opened a new file from the tree in a new window press ctrl-w p to switch back to the NERDTree and use it again to return to your previous window.


3 Answers

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

like image 187
phildobbin Avatar answered Sep 30 '22 23:09

phildobbin


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

like image 18
yawmark Avatar answered Oct 04 '22 23:10

yawmark


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
like image 5
AmerllicA Avatar answered Oct 03 '22 23:10

AmerllicA