Recently I’ve found myself editing in excess of twenty source files concurrently; time to use a vim session so that I don’t need to specify the list of files again each time I start editing. Basic usage is simple.
vim firstfile then :e secondfile, etc. At any time after they’re all open, do :mksession! which will create a Session.vim file in your initial location. When you want to open up those same files again, use vim -S and you’re there. One great advantage of this is that :b8 for example, will always take you to the same file, even if you close and re-open that file — vim knows that you appreciate consistency and does its best to help.

However, there is one small mystery. Say you originally opened up a, b, c and then did :ls. You would see that a was buffer 1 and c was buffer 3. But when you re-open your session, you find that a is buffer 2 and c is buffer 4 — why no buffer 1? The answer is that vim kept buffer 1 for your headline file, but you specified none. I still find this a bit weird, but the working invocation is vim a -S. Now it has opened a as buffer 1 and all other files mentioned in Session.vim as the remaining buffers, so it looks again as it did originally.

Note that Session.vim contains a cd command (which you can edit of course) so you could keep several session files in your base location, relying on the individual session file to set you up in the appropriate destination. For example, have core.vim and plugins.vim in your home directory. Then let vim -S core.vim take you to the base directory for editing those files.

Note also that a huge degree of behaviour is configurable via the sessionoptions setting.

Advertisements