chore: update README.md
parent
0f642be4fa
commit
eec9e3c72d
36
README.md
36
README.md
|
|
@ -8,8 +8,9 @@ The plugin was forked from the fantastic [Persistence.nvim](https://github.com/f
|
||||||
|
|
||||||
- Automatically saves the active session under `.local/share/nvim/sessions` on exit
|
- Automatically saves the active session under `.local/share/nvim/sessions` on exit
|
||||||
- Simple API to restore the current or last session
|
- Simple API to restore the current or last session
|
||||||
- Make use of sessions per git branch
|
- Support for sessions across git branches
|
||||||
- Specify custom directory to save sessions
|
- Specify custom directory to save sessions
|
||||||
|
- Stop or even delete the current sessions
|
||||||
|
|
||||||
## ⚡️ Requirements
|
## ⚡️ Requirements
|
||||||
|
|
||||||
|
|
@ -25,8 +26,6 @@ Install the plugin with your preferred package manager:
|
||||||
-- Lua
|
-- Lua
|
||||||
use({
|
use({
|
||||||
"olimorris/persisted.nvim",
|
"olimorris/persisted.nvim",
|
||||||
event = "BufReadPre", -- this will only start session saving when an actual file was opened
|
|
||||||
module = "persisted",
|
|
||||||
config = function()
|
config = function()
|
||||||
require("persisted").setup()
|
require("persisted").setup()
|
||||||
end,
|
end,
|
||||||
|
|
@ -58,6 +57,8 @@ Persisted comes with the following defaults:
|
||||||
use_git_branch = false, -- create session files based on the branch of the git enabled repository
|
use_git_branch = false, -- create session files based on the branch of the git enabled repository
|
||||||
autosave = true, -- automatically save session files
|
autosave = true, -- automatically save session files
|
||||||
options = { "buffers", "curdir", "tabpages", "winsize" }, -- session options used for saving
|
options = { "buffers", "curdir", "tabpages", "winsize" }, -- session options used for saving
|
||||||
|
before_save = function() end, -- function to run before the session is saved to disk
|
||||||
|
after_save = function() end, -- function to run after the session is saved to disk
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -65,27 +66,26 @@ Persisted comes with the following defaults:
|
||||||
|
|
||||||
**Persisted** 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.
|
**Persisted** 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.
|
||||||
|
|
||||||
Some example keybindings for the plugins functions are contained below:
|
The plugin's functions, alongside some example keybindings, are contained below:
|
||||||
|
|
||||||
```lua
|
### Commands
|
||||||
-- restore the session for the current directory and current branch (if `git_use_branch` is enabled)
|
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qr", [[<cmd>lua require("persisted").load()<cr>]])
|
|
||||||
|
|
||||||
-- restore the last session
|
- `SessionStart` - Start a session. Useful if `autosave` is set to false
|
||||||
vim.api.nvim_set_keymap("n", "<leader>ql", [[<cmd>lua require("persisted").load({ last = true })<cr>]])
|
- `SessionStop` - Stop recording a session
|
||||||
|
- `SessionLoad` - Load the session for the current directory and current branch if `git_use_branch` is enabled
|
||||||
|
- `SessionLoadLast` - Load the last session
|
||||||
|
- `SessionDelete` - Delete the current session
|
||||||
|
- `SessionToggle` - Determines whether to load, start or stop a session
|
||||||
|
|
||||||
-- start persisted => if autosave is set to false
|
### Callbacks
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qs", [[<cmd>lua require("persisted").start()<cr>]])
|
|
||||||
|
|
||||||
-- stop persisted => session won't be saved on exit
|
The plugin allows for _before_ and _after_ callbacks to be executed relative to the session. This is achieved via the `before_save` and `after_save` configuration options.
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qx", [[<cmd>lua require("persisted").stop()<cr>]])
|
|
||||||
|
|
||||||
-- delete persisted => delete the current session
|
> **Note:** The author uses a _before_ callback to ensure that [minimap.vim](https://github.com/wfxr/minimap.vim) is not written into the session. Its presence prevents the exact buffer and cursor position from being restored when loading a session.
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qd", [[<cmd>lua require("persisted").delete()<cr>]])
|
|
||||||
|
|
||||||
-- toggle persisted => determines whether to load, start or stop a session
|
### Lazy loading
|
||||||
vim.api.nvim_set_keymap("n", "<leader>qt", [[<cmd>lua require("persisted").toggle()<cr>]])
|
|
||||||
```
|
To lazy load the plugin, consider adding the `module = "persisted"` option if you're using packer. The commands may then be called with `<cmd>lua require("persisted").toggle()<cr>` for example. The only command which differs is `SessionLoadLast` which is called with `<cmd>lua require("persisted").load({ last = true })<cr>`.
|
||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue