Barbaric Tip of the Week: Saving Your Session for Later in Vim

| Comments

Barbaric Tip of the Week is a weekly series whose main purpose is to share tiny bits of knowledge that I find specially useful and interesting.

I started my machine, opened the command line, ran vim and opened my weekly planning, project notes and overall work checklist as I usually do, in the exact window configuration that I usually use, which my weekly planning window on the left, and job checklist and project notes stacked on the right. Everything was the exactly the same as the previous 999 times, everything but for one thing, this time a thought sprang to my mind: Wouldn’t it be awesome if I could save this file/window configuration and just load it at all once?

Well… That was about time… there is indeed a way to do that… :)

You can save your complete session in vim, that is, the files you have opened with the specific windows or tab configurations that you’re using, with the :mksession command:

:mksession ~/jobsession.vim

Later, the next time you open vim you can load that session with :source:

:source ~/jobsession.vim

Or alternatively open vim directly with a specific session by using the -S option:

> gvim -S ~/jobsession.vim

Voilá! Enjoy!

Bonus tip: Did you know that you can also resize windows with the :resize command? You can use :vertical resize <numberOfLines> to resize a window’s width, and :resize <numberOfLines> to resize its height. Cool right?