folke / persistence.nvim

💾 Simple session management for Neovim
Apache License 2.0
638 stars 26 forks source link

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

Closed dirn closed 11 months ago

dirn commented 1 year ago

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?

rwjblue commented 1 year ago

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,
})