Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/folke/persistence.nvim
💾 Simple session management for Neovim
https://github.com/folke/persistence.nvim
neovim neovim-plugin
Last synced: 5 days ago
JSON representation
💾 Simple session management for Neovim
- Host: GitHub
- URL: https://github.com/folke/persistence.nvim
- Owner: folke
- License: apache-2.0
- Created: 2021-07-02T06:54:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T13:07:36.000Z (4 months ago)
- Last Synced: 2024-08-01T16:44:44.158Z (4 months ago)
- Topics: neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 99.6 KB
- Stars: 600
- Watchers: 5
- Forks: 26
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 💾 Persistence
**Persistence** is a simple lua plugin for automated session management.
## ✨ Features
- automatically saves the active session under `~/.local/state/nvim/sessions` on exit
- simple API to restore the current or last session## ⚡️ Requirements
- Neovim >= 0.7.2
## 📦 Installation
Install the plugin with your preferred package manager:
### [lazy.nvim](https://github.com/folke/lazy.nvim)
```lua
-- Lua
{
"folke/persistence.nvim",
event = "BufReadPre", -- this will only start session saving when an actual file was opened
opts = {
-- add any custom options here
}
}
```## ⚙️ Configuration
Persistence comes with the following defaults:
```lua
{
dir = vim.fn.stdpath("state") .. "/sessions/", -- directory where session files are saved
-- minimum number of file buffers that need to be open to save
-- Set to 0 to always save
need = 1,
branch = true, -- use git branch to save session
}
```> [!TIP]
> To configure what should be saved in your session, check [:h 'sessionoptions'](https://neovim.io/doc/user/options.html#'sessionoptions')## 🚀 Usage
**Persistence** works well with plugins like `startify` or `dashboard`. It will never restore a session automatically,
but you can of course write an autocmd that does exactly that if you want.```lua
-- load the session for the current directory
vim.keymap.set("n", "qs", function() require("persistence").load() end)-- select a session to load
vim.keymap.set("n", "qS", function() require("persistence").select() end)-- load the last session
vim.keymap.set("n", "ql", function() require("persistence").load({ last = true }) end)-- stop Persistence => session won't be saved on exit
vim.keymap.set("n", "qd", function() require("persistence").stop() end)
```## 📅 Events
- **PersistenceLoadPre**: before loading a session
- **PersistenceLoadPost**: after loading a session
- **PersistenceSavePre**: before saving a session
- **PersistenceSavePost**: after saving a session