mihaifm / vimpanel

A modern side panel for Vim
106 stars 9 forks source link

Close Panel when the last Buffer is closed #13

Open tuxflo opened 5 years ago

tuxflo commented 5 years ago

Hi! Since NERDTree has some serious issues with session management I want to give vimpanel a try. In NERDTree I used to have the following line in my vimrc to ensure that NERDTree is closed if the last buffer was closed:

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

Is there a way to achieve the same behaviour (or even a better one that automatically saves the session) with vimpanel?

mihaifm commented 5 years ago

Hi

I haven't updated this plugin in a while but any feedback is appreciated.

I don't fully understand your workflow, but you can achieve this with the command below, although it's a bit hacky:

autocmd bufenter * if (winnr("$") == 1 && bufwinnr("vimpanel-") > 0 && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1) | q | endif

winnr("$") == 1 This checks if there is only one window active bufwinnr("vimpanel-") > 0 Checks if the buffer name starts with vimpanel- len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 Counts the number of active buffers

However I see several problems with this:

So I would honestly not use this command. Instead you can just quit vimpanel as you do with any other buffer. This is easier compared with NERDTree because NERDTree uses a hidden buffer making things more complicated.

Regarding sessions, there is a VimpanelSessionMake command which allows you to save the session. It's a wrapper around the built-in mksession but also saves the layout of the panel (or panels, since you can have more than one with vimpanel).