Save A Vim Session And Then Resume It

By | August 20, 2011

Vim sessions are magical things that preserve every setting, every tab, every fold, everything open file, and just about everything else (except command history – “undo”)

You can save your vim session and environment and then open it again later, without missing a beat. This is so helpful if you are editing a file remotely on a server and then lose your connection (you should also be using screen for this). In such a situation, you would just log back in and resume your session.

So let’s get down to it, shall we? To save your vim session, choose a file to save for vim to save your session’s meta-data. For our purposes we’ll use the file name of “myproject.vimsess”. From within your vim session, enter command mode and type:

:mksession! /path/to/myproject.vimsess

That will save your session. Now to resume your session, from the command line you would type:

vim -S /path/to/myproject.vimsess

Happy vim-ming!