Tip 23Saving and Restoring Sessions

Sometimes you have to restart Vim. Usually this means losing your list of open buffers, as well as any open tab pages or windows. Fortunately, Vim’s session management allows you to save your current workspace so that you can restore it again later.

Saving and Loading Sessions Manually

The source code that accompanies this book includes a webapp directory. Switch to that directory and launch Vim, using the -O flag to open the specified files in vertical splits:

=> $ cd code/webapp
=> $ vim -O app.js test/app-test.js

You should see the app.js and app-test.js files in adjacent windows. Now use the :mksession! command to save the session (:h :mksession):

=> :mksession!

Vim records the current session ...

Get Modern Vim now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.