vimpanel icon indicating copy to clipboard operation
vimpanel copied to clipboard

Close Panel when the last Buffer is closed

Open tuxflo opened this issue 5 years ago • 1 comments

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?

tuxflo avatar Apr 08 '19 19:04 tuxflo

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:

  • it doesn't allow you to open a panel without having any other buffers in vim
  • it doesn't work with multiple panels, something that is supported by vimpanel but not NERDTree

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).

mihaifm avatar Apr 09 '19 09:04 mihaifm