https://github.com/tigion/nvim-sessions
A simple session management plugin for neovim.
https://github.com/tigion/nvim-sessions
lua neovim neovim-plugin
Last synced: 8 months ago
JSON representation
A simple session management plugin for neovim.
- Host: GitHub
- URL: https://github.com/tigion/nvim-sessions
- Owner: tigion
- License: mit
- Created: 2024-08-21T12:37:08.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-06T10:33:26.000Z (over 1 year ago)
- Last Synced: 2025-02-06T11:30:22.455Z (over 1 year ago)
- Topics: lua, neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nvim-sessions
A simple session management plugin for Neovim. It uses
[`:mksession`][mksession] to save and [`:source`][source] to load working
directory based sessions.
[mksession]: https://neovim.io/doc/user/starting.html#%3Amksession
[sessionoptions]: https://neovim.io/doc/user/options.html#'sessionoptions'
[source]: https://neovim.io/doc/user/repeat.html#%3Asource
> [!WARNING]
> This plugin is based on my personal needs. Work in progress. 🚀
Other better plugins are:
- [Shatur/neovim-session-manager](https://github.com/Shatur/neovim-session-manager)
- [folke/persistence.nvim](https://github.com/folke/persistence.nvim)
- [tpope/vim-obsession](https://github.com/tpope/vim-obsession)
- [echasnovski/mini.sessions](https://github.com/echasnovski/mini.sessions)
- and many more ...
## Features
- 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 temporary `blank` from the `:h sessionoptions`). Can be configured
in the options.
> [!TIP]
> See [`:h sessionoptions`][sessionoptions] to change what is stored in the
> session file with `:mksession`.
## Requirements
- Neovim >= 0.10
## Installation
### [lazy.nvim]
[lazy.nvim]: https://github.com/folke/lazy.nvim
```lua
return {
'tigion/nvim-sessions',
event = 'VeryLazy',
cmd = 'Session',
keys = {
{ 'ws', 'Session save', desc = 'Save session (cwd)' },
{ 'wl', 'Session load', desc = 'Load session (cwd)' },
},
---@module 'sessions'
---@type sessions.Config
opts = {},
}
```
## Configuration
The default options are:
```lua
---@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 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.
## Usage
| 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.
## TODO
- [x] Add lua comment [annotations](https://luals.github.io/wiki/annotations/).
- [x] Add auto save.
- [x] Update readme.
- [x] Move simple session management from tigion.core.util.session to a plugin.