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

How do I continuously record and restore sessions with vim-obsession?

Answer

:Obsession

Explanation

If you routinely work across many files, tabs, and split layouts, rebuilding your workspace after a restart is costly. vim-obsession solves this by continuously updating a session file while you work, so restore is one command away. :Obsession is lightweight but powerful for long-lived feature branches and context-heavy debugging sessions.

How it works

  • :Obsession starts tracking the current session
  • It writes session state (buffers, windows, tab pages, working directory, etc.) to Session.vim by default
  • As your layout changes, the session file is updated automatically
  • Running :Obsession again toggles it off

After restart, source the session file to recover the exact working setup.

Example

Start tracking in your project root:

:Obsession

Work normally: open multiple tabs, split windows, jump through files. Later, after closing Vim, return and restore:

:source Session.vim

Your prior workspace shape and open buffers come back with minimal friction.

Tips

  • Use :Obsession path/to/my-session.vim to keep per-project session files explicit
  • Pair with Git worktrees so each worktree has its own recoverable editor state
  • If session restore misses expected globals, review your 'sessionoptions' setting

Next

How do I insert the unnamed register literally in Insert mode without auto-indent side effects?