Currently I'm using Vim sessions to restore my window layout, but this approach also restores buffers, which I'd prefer to be closed on startup.

Is there a way to do something like:

$ vim file.txt

And in Vim something like:

: restore-layout

The only variant I can think of is to create a function which will do this, but it's not convenient for me.

Though it just occurred to me, that it may be convenient to define a function, which will wipe out all buffers with some exceptions. I may call this function automatically during a session restoration.

I'll try this later today.

Thank you.

2 Answers 2


A window cannot exist without any buffer attached.

Just make sure you have an empty unnamed buffer in every window and save the session.


I've ended with this piece in my vimrc:

fun! BuffWipe()
  for nr in range(1, bufnr('$'))
    if (bufwinnr(nr) == -1) && (bufexists(nr))
      exec 'bw ' . nr

Which I call before creating a session on VimLeave.

For some reason it doesn't wipe out all buffers I'd expect (which are those, that are not being visible in any window), but it wipes almost all of them.

I find this approach to be rather convenient, since it allows me to close numerous buffers I finished working with all at once.

  • Remove buffers from ssop
    – Matt
    Feb 14, 2021 at 15:31
  • @Matt I did, and vim -S my-session-script.vim still restored all the buffers, which had been open when I exited vim. So I don't think that simply removing 'buffers' could help Feb 14, 2021 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.