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.vimsaves the session:source session.vimrestores the sessionvim -S session.vimstarts 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 filesessionoptionscontrols what is saved (buffers, folds, globals, etc.):set sessionoptions-=optionsprevents saving options- Neovim and plugins like vim-obsession automate session management
- Sessions include window layout, tab pages, and cursor positions