A single layer implementation.
Standalone, no dependencies.
Can be used with nvim workspace manager.
Name | Description |
---|---|
SessionAdd | Add session - Uses directory name if no argument is given |
SessionDel | Delete session |
SessionList | List sessions |
SessionChange[!] | Change session - Defaults to last_session if no argument is given - If used with bang, session won't be loaded |
SessionSave | Save session |
SessionLoad[!] | Load session - If used with bang, existing buffers won't be deleted (useful during startup) |
SessionName | Print current session name |
SessionRename | Rename current session |
SessionStartEvents | Start events - Events when to save a session, default is: VimLeavePre |
SessionStopEvents | Stop events |
Name | Description |
---|---|
add(strName) | Adds a session - Optional: strName = CURRENT_WORKING_DIRECTORY |
del(strName) | Deletes a session - Mandatory: strName - Returns immidiately if no argument is given |
list() | Lists sessions |
rename(strName) | Renames current session - Mandatory: strName |
change_session(strName, boolLoad) | Changes session - Optional: strName = last_session - Optional: boolLoad = true |
save() | Saves current session |
load(boolDelBuffers) | Loads current session - Optional: boolDelBuffers = true |
start_events() | Starts events |
stop_events() | Stops events |
get_session_name(boolPrint) | Returns current session name - Optional: boolPrint = false |
Lazy.nvim
{
"The-Plottwist/nvim-session-manager",
branch = "stable"
}
defaults = {
events = {"VimPreLeave"},
--For more info: help sessionoptions
save_options = { "blank", "buffers", "curdir", "help", "skiprtp", "tabpages", "winsize", "winpos" },
session_dir = vim.fn.stdpath("state") .. path_seperator .. "sessions",
default_session = "last_session"
}
Notes
-To modify: require("session-manager").setup({events = {}, ...})
-Does not load any sessions by default
-Adds an ungrouped UIEnter
event seperate from User events to refresh buffers when a session is loaded before UI (Gives error on empty tabpages, please close empty tabs).
--enable the plugin
require("session-manager").setup()
--check if a file argument is given at vim start
vim.cmd("let g:ARGC = argc()")
--load last_session if no file argument is given
if vim.g.ARGC == 0 then
require("session-manager").load()
end
-No need to assign to a variable like manager = require(...)
as lua stores all require calls as table values where described in the section 8.1 of Programming in Lua: "[...]it keeps a table with the names of all loaded files. If a required file is already in the table, require simply returns." (Not recommended outside of configuration files)