Skip to content

Instantly share code, notes, and snippets.

@seanh
Last active June 12, 2019 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanh/4bf8f757ad23ca1fa28a88830e6a9f89 to your computer and use it in GitHub Desktop.
Save seanh/4bf8f757ad23ca1fa28a88830e6a9f89 to your computer and use it in GitHub Desktop.
obsession.vim cheatsheet (simple, no-hassle Vim sessions from Tim Pope)

obsession.vim cheatsheet

obsession.vim is simple, no-hassle Vim sessions from Tim Pope. It's a small plugin that just provides :Obsession, a better replacement for the standard :mksession command.

  • Adds the :Obsession command:

    • :Obsession with no argument creates a Session.vim file in the current directory and begins session tracking using that file.

      :Obsession while a session is already being tracked pauses session tracking and :Obsession while paused unpauses.

    • :Obsession <directory_or_filename> begins tracking a session with the given filename as the session file, or a Session.vim in the given directory. Will create the session file if it doesn't exist.

      Passing a directory doesn't seem to work -- it produced an error from Vim.

    • :Obsession! stops recording the current session and deletes the session file.

  • To load a previously created session you do vim -S <path_to_session_file> or :source <path_to_session_file> as usual, rather than using the :Obsession command. You only use :Obsession to create a new session or to delete a session.

    If the session file is one created by Obsession, then sourcing it will automatically turn on Obsession's automatic session updating.

  • Automatically updates the session file before exiting Vim, and also whenever the layout changes (in case Vim crashes)

  • If you try to make a new session on top of an existing session it just lets you do it, instead of complaining

  • Has an indicator for your status line, tab line or title string

  • Airline has a builtin extension for Obsession. Add let g:airline#extensions#obsession#enabled = 1 to your vimrc to enable it. It just seems to put a $ in the status line when Obsession is tracking a session, doesn't display the name of the session.

  • If you want the size of your GVim window to also be recorded as part of your session add set sessionoptions+=resize to your gvimrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment