💾 Simple session management for Neovim
Find a file
2025-02-25 19:20:14 +01:00
.github ci: update 2024-07-22 14:24:46 +02:00
doc chore(build): auto-generate docs 2025-02-25 18:17:41 +00:00
lua/persistence refactor: cleanup 2025-02-25 19:20:14 +01:00
.editorconfig chore(update): update repository (#72) 2024-07-15 17:09:09 +02:00
.gitignore ci: update 2024-07-06 23:45:36 +02:00
CHANGELOG.md chore(main): release 3.1.0 (#66) 2024-07-07 21:24:56 +02:00
LICENSE docs: added LICENSE 2022-09-05 10:27:37 +02:00
README.md feat: sessions per branch. Closes #9 2024-07-06 22:00:20 +02:00
selene.toml ci: update 2024-07-05 15:46:10 +02:00
stylua.toml ci: update 2024-07-05 15:46:10 +02:00
vim.toml ci: update 2024-07-05 15:46:10 +02:00

💾 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

-- 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:

{
  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'

🚀 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.

-- load the session for the current directory
vim.keymap.set("n", "<leader>qs", function() require("persistence").load() end)

-- select a session to load
vim.keymap.set("n", "<leader>qS", function() require("persistence").select() end)

-- load the last session
vim.keymap.set("n", "<leader>ql", function() require("persistence").load({ last = true }) end)

-- stop Persistence => session won't be saved on exit
vim.keymap.set("n", "<leader>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