From eec9e3c72de29f953348c620801154c33368a476 Mon Sep 17 00:00:00 2001 From: olimorris Date: Sat, 5 Mar 2022 15:22:34 +0000 Subject: [PATCH] chore: update README.md --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d77232f..c2c8e45 100644 --- a/README.md +++ b/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 - 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 +- Stop or even delete the current sessions ## ⚡️ Requirements @@ -25,8 +26,6 @@ Install the plugin with your preferred package manager: -- Lua use({ "olimorris/persisted.nvim", - event = "BufReadPre", -- this will only start session saving when an actual file was opened - module = "persisted", config = function() require("persisted").setup() 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 autosave = true, -- automatically save session files 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. -Some example keybindings for the plugins functions are contained below: +The plugin's functions, alongside some example keybindings, are contained below: -```lua --- restore the session for the current directory and current branch (if `git_use_branch` is enabled) -vim.api.nvim_set_keymap("n", "qr", [[lua require("persisted").load()]]) +### Commands --- restore the last session -vim.api.nvim_set_keymap("n", "ql", [[lua require("persisted").load({ last = true })]]) +- `SessionStart` - Start a session. Useful if `autosave` is set to false +- `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 -vim.api.nvim_set_keymap("n", "qs", [[lua require("persisted").start()]]) +### Callbacks --- stop persisted => session won't be saved on exit -vim.api.nvim_set_keymap("n", "qx", [[lua require("persisted").stop()]]) +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. --- delete persisted => delete the current session -vim.api.nvim_set_keymap("n", "qd", [[lua require("persisted").delete()]]) +> **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. --- toggle persisted => determines whether to load, start or stop a session -vim.api.nvim_set_keymap("n", "qt", [[lua require("persisted").toggle()]]) -``` +### Lazy loading + +To lazy load the plugin, consider adding the `module = "persisted"` option if you're using packer. The commands may then be called with `lua require("persisted").toggle()` for example. The only command which differs is `SessionLoadLast` which is called with `lua require("persisted").load({ last = true })`. ### Helpers