GithubHelp home page GithubHelp logo

adrianord / neovim-session-manager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shatur/neovim-session-manager

0.0 0.0 0.0 148 KB

A simple wrapper around :mksession.

License: GNU General Public License v3.0

Lua 100.00%

neovim-session-manager's Introduction

Neovim Session Manager

A Neovim 0.7+ plugin that use built-in :mksession to manage sessions like folders in VSCode. It allows you to save the current folder as a session to open it later. The plugin can also automatically load the last session on startup, save the current one on exit and switch between session folders.

The plugin saves the sessions in the specified folder (see configuration). The session corresponds to the working directory. If a session already exists for the current folder, it will be overwritten.

Dependencies

Commands

Use the command :SessionManager[!] with one of the following arguments:

Argument Description
load_session Select and load session. (Your current session won't appear on the list).
load_last_session Will remove all buffers and :source the last saved session.
load_current_dir_session Will remove all buffers and :source the last saved session file of the current directory.
save_current_session Works like :mksession, but saves/creates current directory as a session in sessions_dir.
delete_session Select and delete session.
delete_current_dir_sesssion Deletes the session associated with the current directory.

When ! is specified, the modified buffers will not be saved.

Commands load_session and delete_session use vim.ui.select(). To use your favorite picker like Telescope, consider installing dressing.nvim or telescope-ui-select.nvim.

Configuration

To configure the plugin, you can call require('session_manager').setup(values), where values is a dictionary with the parameters you want to override. Here are the defaults:

local Path = require('plenary.path')
local config = require('session_manager.config')
require('session_manager').setup({
  sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'), -- The directory where the session files will be saved.
  session_filename_to_dir = session_filename_to_dir, -- Function that replaces symbols into separators and colons to transform filename into a session directory.
  dir_to_session_filename = dir_to_session_filename, -- Function that replaces separators and colons into special symbols to transform session directory into a filename. Should use `vim.loop.cwd()` if the passed `dir` is `nil`.
  autoload_mode = config.AutoloadMode.LastSession, -- Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession
  autosave_last_session = true, -- Automatically save last session on exit and on session switch.
  autosave_ignore_not_normal = true, -- Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed.
  autosave_ignore_dirs = {}, -- A list of directories where the session will not be autosaved.
  autosave_ignore_filetypes = { -- All buffers of these file types will be closed before the session is saved.
    'gitcommit',
    'gitrebase',
  },
  autosave_ignore_buftypes = {}, -- All buffers of these bufer types will be closed before the session is saved.
  autosave_only_in_session = false, -- Always autosaves session. If true, only autosaves after a session is active.
  max_path_length = 80,  -- Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all.
})

Autocommands

You can specify commands to be executed automatically after saving or loading a session using the following events:

Event Description
SessionSavePre Executed before a session is saved
SessionSavePost Executed after a session is saved
SessionLoadPre Executed before a session is loaded
SessionLoadPost Executed after a session is loaded

For example, if you would like to have NvimTree or any other file tree automatically opened after a session load, have this somewhere in your config file:

local config_group = vim.api.nvim_create_augroup('MyConfigGroup', {}) -- A global group for all your config autocommands

vim.api.nvim_create_autocmd({ 'User' }, {
  pattern = "SessionLoadPost",
  group = config_group,
  callback = function()
    require('nvim-tree.api').tree.toggle(false, true)
  end,
})

Save session on BufWrite

You can enable this opt in feature with

-- Auto save session
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
  callback = function ()
    for _, buf in ipairs(vim.api.nvim_list_bufs()) do
      -- Don't save while there's any 'nofile' buffer open.
      if vim.api.nvim_get_option_value("buftype", { buf = buf }) == 'nofile' then
        return
      end
    end
    session_manager.save_current_session()
  end
})

For more information about autocmd and its event, see also:

neovim-session-manager's People

Contributors

shatur avatar zeioth avatar adrianord avatar lostl1ght avatar ttytm avatar kurakurakantor avatar svanharmelen avatar manuzor avatar knmac avatar dnaaun avatar snowair avatar utkarshgupta137 avatar tonyxty avatar m3tior avatar rverst avatar ranebrown avatar julesnp avatar sjdonado avatar subjective avatar howarddo2208 avatar hbiel avatar elsa002 avatar dandrestor avatar caenrique avatar loneexile avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.