💾 Simple session management for Neovim
Find a file
2022-09-05 08:02:17 +00:00
.github/workflows build: added panvimdoc github action 2022-09-05 10:01:47 +02:00
doc Auto generate docs 2022-09-05 08:02:17 +00:00
lua/persistence fix: vim.fn.has('win32') returns 0 or 1, not a boolean (#8) 2021-10-22 20:24:20 +02:00
README.md docs: key mappings present in the README (#10) 2022-09-03 14:36:12 +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 .config/nvim/sessions on exit
  • simple API to restore the current or last session

Requirements

  • Neovim >= 0.5.0

📦 Installation

Install the plugin with your preferred package manager:

packer

-- Lua
use({
  "folke/persistence.nvim",
  event = "BufReadPre", -- this will only start session saving when an actual file was opened
  module = "persistence",
  config = function()
    require("persistence").setup()
  end,
})

vim-plug

" Vim Script
Plug 'folke/persistence.nvim'

lua << EOF
  require("persistence").setup {
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
  }
EOF

⚙️ Configuration

Persistence comes with the following defaults:

{
  dir = vim.fn.expand(vim.fn.stdpath("config") .. "/sessions/"), -- directory where session files are saved
  options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
}

🚀 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>]], {})