Close vim NERDtree on close of file
Asked Answered
S

3

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?

Synonymize answered 7/4, 2011 at 13:16 Comment(1)
possible duplicate of Automatically quit vim if NERDTree is last and only buffer.Synonymize
J
19

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

Jayejaylene answered 7/4, 2011 at 13:38 Comment(0)
L
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

Legged answered 25/10, 2012 at 21:14 Comment(3)
This solution works better if you don't want to type wqaCanonize
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.Godric
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.Koral
J
19

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

Jayejaylene answered 7/4, 2011 at 13:38 Comment(0)
F
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
Frontality answered 16/3, 2020 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.