💾 Simple session management for Neovim
Find a file
2023-10-13 07:57:09 +02:00
.github chore: update templates 2023-03-19 20:36:39 +01:00
doc chore(build): auto-generate vimdoc 2023-05-22 14:39:07 +00:00
lua/persistence feat: don't save the session when no files are open (save_empty = false) 2023-10-13 07:57:09 +02:00
.gitignore fix: dont throw error when session was already stopped 2023-01-06 19:28:37 +01:00
CHANGELOG.md chore(main): release 1.1.0 (#23) 2023-02-28 12:43:14 +01:00
LICENSE docs: added LICENSE 2022-09-05 10:27:37 +02:00
README.md feat: don't save the session when no files are open (save_empty = false) 2023-10-13 07:57:09 +02:00
selene.toml feat: inital version 2021-07-02 08:55:37 +02:00
stylua.toml feat: inital version 2021-07-02 08:55:37 +02:00
vim.toml feat: inital version 2021-07-02 08:55:37 +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:

folke

-- 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.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved
  options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
  pre_save = nil, -- a function to call before saving the session
  save_empty = false, -- don't save if there are no open file buffers
}

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

-- restore the session for the current directory
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persistence").load()<cr>]], {})

-- restore the last session
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persistence").load({ last = true })<cr>]], {})

-- stop Persistence => session won't be saved on exit
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persistence").stop()<cr>]], {})