folke / persistence.nvim

💾 Simple session management for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to prevent sessions from being created when Neovim is launched by Git?

dirn opened this issue · comments

I recently started trying out persistence.nvim after many years of using ProSession. So far everything works great. I noticed once difference, though, that caught me by surprise. When I'm working with Git and close Neovim, e.g., after writing a commit message or performing an interactive rebase, the next time I call require("persistence").load() from the same directory, instead of my previous session, I'm greeted by whatever Git opened in Neovim, e.g., the commit message or rebase todo.

Is there a way to tell persistence.nvim not to automatically save the session when Neovim is opened by Git?

This is possible to do with autocmd's. I've setup the following in my config. I'm using LazyVim, but ultimately that doesn't really matter too much; the config is the same I think:

local function augroup(name)
  return vim.api.nvim_create_augroup("rwjblue_" .. name, { clear = true })
end

vim.api.nvim_create_autocmd("FileType", {
  group = augroup("disable_session_persistence"),
  pattern = { "gitcommit" },
  callback = function()
    require("persistence").stop()
  end,
})