Skip to content

feat: cleanup buffers after loading a session#1993

Merged
CKolkey merged 1 commit into
NeogitOrg:masterfrom
igorlfs:session-cleanup
Jul 22, 2026
Merged

feat: cleanup buffers after loading a session#1993
CKolkey merged 1 commit into
NeogitOrg:masterfrom
igorlfs:session-cleanup

Conversation

@igorlfs

@igorlfs igorlfs commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Context: neovim/neovim#40336

TLDR: Neogit leaves leftover buffers when restoring vim sessions. We could have a "full restore" functionality, but that's somewhat complex. Instead, just wipe the leftover buffers, which is a low-cost improvement.

Comment thread lua/neogit/autocmds.lua
callback = function()
for _, buf in ipairs(api.nvim_list_bufs()) do
local buf_name = api.nvim_buf_get_name(buf)
if buf_name:match("Neogit%w+") then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we can't use ^Neogit%w+ (i.e., ^) because when restoring, the buffer is no longer owned by neogit and neovim ends up prepending the full path to the cwd.

@CKolkey
CKolkey merged commit 41c3b38 into NeogitOrg:master Jul 22, 2026
2 of 6 checks passed
@CKolkey

CKolkey commented Jul 22, 2026

Copy link
Copy Markdown
Member

Thanks :)

@igorlfs
igorlfs deleted the session-cleanup branch July 22, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants