Skip to content

tigion/sessions.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sessions.nvim

A simple session management plugin for Neovim. It uses :mksession to save and :source to load working directory based sessions.

Warning

This plugin is based on my personal needs. Work in progress. 🚀

The former name of this plugin was nvim-sessions.

Other better plugins are:

Features

  • Uses one session file per working directory.
  • Session files are stored global in vim.fn.stdpath('data') in a configurable subdirectory.
  • Sessions can manually saved, loaded and deleted.
  • Optionally, the session is automatically saved when Neovim is closed.
  • It ignores empty windows from plugins like nvim-tree or outline
    (removes temporary blank from the :h sessionoptions). Can be configured in the options.

Tip

See :h sessionoptions to change what is stored in the session file with :mksession.

Requirements

  • Neovim >= 0.10

Installation

return {
  'tigion/sessions.nvim',
  event = 'VeryLazy',
  cmd = 'Session',
  keys = {
    { '<Leader>ws', '<Cmd>Session save<CR>', desc = 'Save session (cwd)' },
    { '<Leader>wl', '<Cmd>Session load<CR>', desc = 'Load session (cwd)' },
  },
  ---@module 'sessions'
  ---@type sessions.Config
  opts = {},
}

Configuration

The default options are:

---@class sessions.Config
---@field auto_save? boolean Automatically saves the session on Neovim exit.
---@field directory? string The subdirectory in `vim.fn.stdpath('data')` where the sessions are saved.
---@field ignore_blank? boolean Ignores saving sessions for blank buffers.
---@field ignored_filetypes? table<string, boolean> Ignores session saving for the specified filetypes.
---@field notify? boolean Notifies when a session is loaded or saved.
---@field overwrite? boolean Overwrites existing session files without confirmation.

---The default options.
---@type sessions.Config
local defaults = {
  auto_save = false,
  directory = 'sessions', -- Will be created if not available.
  ignore_blank = true,
  ignored_filetypes = { -- Will prevent session saving if found.
    alpha = true,
    dashboard = true,
    snacks_dashboard = true,
  },
  notify = true,
  overwrite = true,
}

For other plugin manager, call the setup function require('sessions').setup({ ... }) directly.

Usage

Command Description
:Session info Shows information about the current session and the Session command.
:Session save Saves the current session for the current working directory.
:Session load Loads the session for the current working directory.
:Session delete Deletes the session for the current working directory.

With require('sessions').exists() you can check if a session exists for the current working directory.

Run :checkhealth sessions to check the health of the plugin.

TODO

  • Add lua comment annotations.
  • Add auto save.
  • Update readme.
  • Move simple session management from tigion.core.util.session to a plugin.

About

A Neovim plugin for a simple session management.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages