Hot exit is one of killer features of Sublime Text editor. It allows to close editor at any point of time without worrying about modifications in opened files - it just closes without any question. When launch ST again all opened and edited files will be at the same state as they were before close

I wonder is there a way doing the same in vim?

  • :xa exit all (save all changes and close Vim)
    – Sim
    Dec 10, 2015 at 13:43
  • This writes the files, but doesn't save anything else. I think the OP wants something that both saves the files without writing them, and saves the state of any open tabs or buffers Dec 10, 2015 at 20:27
  • Yes, I understood that later from his comments.
    – Sim
    Dec 10, 2015 at 20:32

2 Answers 2


Vim can do this, though it may be a bit clunky and take some setup.

romainl gets you partway with session. The missing bits are swap files, :preserve, and the & flag for cpoptions.

Swap files are intended for recovery if Vim or your system crashes. They enable you to recover any unsaved changes (with some limitations, see :he swap-file). However, when Vim exits normally, it deletes any swap files it was using, even if the buffer had unsaved changes.

That's where :preserve and cpoptions's & come in. :preserve forces Vim to write all buffers to their swap files immediately (as opposed to the standard after 4 seconds or 200 characters, or whatever your options have set it to). Doing :set cpoptions+=& tells Vim not to delete swap files saved with :preserve when exiting normally.

Unfortunately, Vim does not automatically clean up swap files when recovering from them, so you can soon end up with a directory looking like this:


You can delete the older ones manually, but Vim will only automatically offer to recover if there is a *.swp file where it would put its new swap file. The :recover command will force Vim to look for swap files to recover from.

By using autocommands, you can automate preserving (probably with the QuitPre event) and recovering (probably with BufRead or BufReadPost). Recover.vim is a plugin that might work as a friendlier alternative for managing recovering. It appears to also handle cleaning up swap files. I'm not sure how it would handle a directory with a .swo but no .swp file. You may still need to use :recover for that case.

vim-obsession is another plugin that claims to make handling sessions much easier.


Yes. It's called "session" and you can read all about it in:

:help session
  • 2
    I'm aware about sessions. But seems it is not the same - it saves all opened buffers and tabs (and settings) but if you have some changes in one of buffers you must write them to disk before exit. In sublime text you do not need to save opened file on exit - sublime saves all changes to it in separate place and restores them on reopen. So original file is untouched on disk but the changes are not lost too
    – LazyS
    Dec 10, 2015 at 14:03
  • Yes, that would be the main difference. No idea if it can be achieved in any way without resorting to tmux/screen/detach.
    – romainl
    Dec 10, 2015 at 14:07

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.