This plugin allows saving sessions per-directory, which will be resumed next time you open nvim in that directory.
:AutoSessionSave
- Install with vim-plug:
Plug 'pysan3/autosession.nvim'
- Install with packer:
use { "pysan3/autosession.nvim" }
- Install with lazy.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.
},
}
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
})
Use the following commands.
:AutoSession
- Show help
:AutoSessionRestore
- Restore previous session from
.session.vim
.
- Restore previous session from
:AutoSessionSave
- Create
.session.vim
to store current session.
- Create
:AutoSessionAuto
- Update
.session.vim
only if exists. - This is called on nvim shutdown (
VimLeave
) ifautosave_on_quit == true
- Update
: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.
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.
NVIM_DISABLE_AUTOSESSION=1 nvim
# PowerShell
$env:NVIM_DISABLE_AUTOSESSION=1
nvim
$env:NVIM_DISABLE_AUTOSESSION=$null
# Command Prompt
cmd /C "set NVIM_DISABLE_AUTOSESSION=1 && nvim"
By calling AutoSessionGlobal
, this plugin will register the current session as a session in Startify's menu screen.
Enhances help menu for this plugin