vimtricks.wiki Concise Vim tricks, one at a time.

How do I save and restore my entire Vim session?

Answer

:mksession and :source

Explanation

The :mksession command saves the current Vim session (windows, buffers, tabs, cursor positions) to a file. :source restores it later.

How it works

  • :mksession session.vim saves the session
  • :source session.vim restores the session
  • vim -S session.vim starts Vim with the saved session

Example

:mksession ~/session.vim    " Save session
" ... close Vim ...
vim -S ~/session.vim         " Restore session

Tips

  • :mksession! overwrites an existing session file
  • sessionoptions controls what is saved (buffers, folds, globals, etc.)
  • :set sessionoptions-=options prevents saving options
  • Neovim and plugins like vim-obsession automate session management
  • Sessions include window layout, tab pages, and cursor positions

Next

How do you yank a single word into a named register?