Skip to content

pysan3/autosession.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

autosession.nvim

Plugin to Save and Restore Sessions Per-directory

This plugin allows saving sessions per-directory, which will be resumed next time you open nvim in that directory.

Demo

:AutoSessionSave

autosession

Install

Plug 'pysan3/autosession.nvim'
use { "pysan3/autosession.nvim" }
return {
  "pysan3/autosession.nvim", -- restore previous session
  event = { "VeryLazy" },                   -- OPTIONAL
  -- lazy = false,                          -- If you do not want to lazy load.
  dependencies = { "mhinz/vim-startify" },  -- OPTIONAL: Used for `:AutoSessionGlobal`
  opts = {
    -- Options explained below.
  },
}

Setup

This plugin will only be loaded after setup is called. The setup function should be called with a lua table with the following keys.

The following values are the default which will be chosen if the keys do not exist.

See ./lua/autosession/config.lua for more details.

require("autosession").setup({
  msg = nil, -- string: printed when startup is completed
  restore_on_setup = false, -- boolean: If true, automatically restore session on nvim startup
  warn_on_setup = false, -- boolean: If true, warning shown when no `.session.vim` is found
  autosave_on_quit = false, -- boolean: If true, automatically overwrites sessionfile if exists
  save_session_global_dir = vim.g.startify_session_dir or vim.fn.stdpath("data") .. "/session", -- string
  --                        dir path to where global session files should be stored.
  --                        global sessions will show up in startify screen as dirname of the session
  sessionfile_name = ".session.vim", -- string: default name of sessionfile. better be .gitignored
  disable_envvar = "NVIM_DISABLE_AUTOSESSION", -- string: disable this plugin altogether when this envvar is found
})

Usage

Use the following commands.

  • :AutoSession
    • Show help
  • :AutoSessionRestore
    • Restore previous session from .session.vim.
  • :AutoSessionSave
    • Create .session.vim to store current session.
  • :AutoSessionAuto
    • Update .session.vim only if exists.
    • This is called on nvim shutdown (VimLeave) if autosave_on_quit == true
  • :AutoSessionGlobal
    • Resigter current session for vim-startify.
    • Runs AutoSessionSave along the way.
    • WARNING: Only works on *nix systems. Aborting on Windows (except Cygwin).
  • :AutoSessionDelete
    • Delete a global session.

Tips

Temporary Disable AutoLoading

When the environment variable passed to config.disable_envvar (default: NVIM_DISABLE_AUTOSESSION) is not nil, this plugin will be disabled altogether (does not autosave on quit as well).

This might be useful when you want to peek into a single file in a session directory.

Unix System

NVIM_DISABLE_AUTOSESSION=1 nvim

Windows

# PowerShell
$env:NVIM_DISABLE_AUTOSESSION=1
nvim
$env:NVIM_DISABLE_AUTOSESSION=$null

# Command Prompt
cmd /C "set NVIM_DISABLE_AUTOSESSION=1 && nvim"

Recommended Dependencies

By calling AutoSessionGlobal, this plugin will register the current session as a session in Startify's menu screen.

as-global

Enhances help menu for this plugin

nvim-notify

Releases

No releases published

Packages

No packages published

Languages