A simple session management plugin for Neovim. It uses
:mksession to save and :source to load working
directory based sessions.
Warning
This plugin is based on my personal needs. Work in progress. 🚀
The former name of this plugin was nvim-sessions.
Other better plugins are:
- Shatur/neovim-session-manager
- folke/persistence.nvim
- tpope/vim-obsession
- echasnovski/mini.sessions
- and many more ...
- Uses one session file per working directory.
- Session files are stored global in
vim.fn.stdpath('data')in a configurable subdirectory. - Sessions can manually saved, loaded and deleted.
- Optionally, the session is automatically saved when Neovim is closed.
- It ignores empty windows from plugins like nvim-tree or outline
(removes temporaryblankfrom the:h sessionoptions). Can be configured in the options.
Tip
See :h sessionoptions to change what is stored in the
session file with :mksession.
- Neovim >= 0.10
return {
'tigion/sessions.nvim',
event = 'VeryLazy',
cmd = 'Session',
keys = {
{ '<Leader>ws', '<Cmd>Session save<CR>', desc = 'Save session (cwd)' },
{ '<Leader>wl', '<Cmd>Session load<CR>', desc = 'Load session (cwd)' },
},
---@module 'sessions'
---@type sessions.Config
opts = {},
}The default options are:
---@class sessions.Config
---@field auto_save? boolean Automatically saves the session on Neovim exit.
---@field directory? string The subdirectory in `vim.fn.stdpath('data')` where the sessions are saved.
---@field ignore_blank? boolean Ignores saving sessions for blank buffers.
---@field ignored_filetypes? table<string, boolean> Ignores session saving for the specified filetypes.
---@field notify? boolean Notifies when a session is loaded or saved.
---@field overwrite? boolean Overwrites existing session files without confirmation.
---The default options.
---@type sessions.Config
local defaults = {
auto_save = false,
directory = 'sessions', -- Will be created if not available.
ignore_blank = true,
ignored_filetypes = { -- Will prevent session saving if found.
alpha = true,
dashboard = true,
snacks_dashboard = true,
},
notify = true,
overwrite = true,
}For other plugin manager, call the setup function
require('sessions').setup({ ... }) directly.
| Command | Description |
|---|---|
:Session info |
Shows information about the current session and the Session command. |
:Session save |
Saves the current session for the current working directory. |
:Session load |
Loads the session for the current working directory. |
:Session delete |
Deletes the session for the current working directory. |
With require('sessions').exists() you can check if a session exists for the
current working directory.
Run :checkhealth sessions to check the health of the plugin.
- Add lua comment annotations.
- Add auto save.
- Update readme.
- Move simple session management from tigion.core.util.session to a plugin.