persistence.nvim/README.md

73 lines
1.9 KiB
Markdown
Raw Normal View History

2021-07-12 10:47:14 +02:00
# 💾 Persistence
2021-07-12 10:49:06 +02:00
**Persistence** is a simple lua plugin for automated session management.
2021-07-12 10:47:14 +02:00
## ✨ Features
- automatically saves the active session under `~/.local/state/nvim/sessions` on exit
2021-07-12 10:47:14 +02:00
- simple API to restore the current or last session
## ⚡️ Requirements
- Neovim >= 0.7.2
2021-07-12 10:47:14 +02:00
## 📦 Installation
Install the plugin with your preferred package manager:
### [packer](https://github.com/wbthomason/packer.nvim)
```lua
-- Lua
use({
"folke/persistence.nvim",
event = "BufReadPre", -- this will only start session saving when an actual file was opened
2021-07-12 10:47:14 +02:00
module = "persistence",
config = function()
require("persistence").setup()
end,
})
```
### [vim-plug](https://github.com/junegunn/vim-plug)
```vim
" 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
```
2021-07-12 10:47:14 +02:00
## ⚙️ Configuration
2021-07-12 10:49:06 +02:00
Persistence comes with the following defaults:
2021-07-12 10:47:14 +02:00
```lua
{
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved
2021-07-12 10:47:14 +02:00
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.
```lua
-- restore the session for the current directory
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persistence").load()<cr>]], {})
2021-07-12 10:47:14 +02:00
-- restore the last session
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persistence").load({ last = true })<cr>]], {})
2021-07-12 10:47:14 +02:00
-- stop Persistence => session won't be saved on exit
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persistence").stop()<cr>]], {})
2021-07-12 10:47:14 +02:00
```