The situation is this:

I have 2 sessions: s1.vim and s2.vim. First one was saved with files A, B, C in buffers list. Second one was saved with file A.

Next I start vim: vim -S s1.vim. :ls shows A, B, C. Then I source second session. :so s2.vim. And instead of A :ls shows A, B, C again. Why is that?


1 Answer 1


"Session" is simply a Vim script. You can read it - it does not try to wipe any existing buffers (except maybe one it was started from and only if it was blank). It works well on Vim startup, but may leave extra buffers floating around if you load it later.

Currently there's no way to change this behaviour. If you really feel it wrong (although, I should say, it's the most safe option), you can open an issue on Vim's Github page.

  • 1
    Vim documentation on :mksession explicitly says that session file when executed with :source unloads currently loaded buffers and restores new ones. mksession help page May 2, 2021 at 13:15
  • 1
    My bad. This is indeed a default behavior. I found an issue on Github regarding this question. There was a mistake on documentation since session file doesn't contain code to unload any buffers except current one. github May 2, 2021 at 13:43
  • 1
    @whysoserious It says "unloads all buffers", not "wipes" them. Indeed, it closes all windows that could result in unloading all buffers (though it's tunable).
    – Matt
    May 2, 2021 at 14:09
  • yes, for some reason I thought that unloaded buffer is no longer in the buffer list. Thanks May 2, 2021 at 14:51
  • @whysoserious :h bufloaded() vs :h buflisted().
    – Matt
    May 2, 2021 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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