Skip to content

feat: restore buffers after loading a session#3335

Open
igorlfs wants to merge 1 commit into
nvim-tree:masterfrom
igorlfs:session-restore
Open

feat: restore buffers after loading a session#3335
igorlfs wants to merge 1 commit into
nvim-tree:masterfrom
igorlfs:session-restore

Conversation

@igorlfs

@igorlfs igorlfs commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Hello,

I'm on a quest to make all of my plugins (vim) "session friendly". For nvim-tree this sounds pretty straightforward, so I went ahead and implemented it myself.

Problem: nvim-tree leaves stale empty buffers after restoring a session

Solution: detect these buffers on SessionLoadPost and reopen them.

Comment thread lua/nvim-tree/autocmd.lua
end,
})

vim.api.nvim_create_autocmd("SessionLoadPost", {

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.

I went with this location since it was the standard, but it might a good idea have this as an eager autocmd. Otherwise, any means of "lazy loading" may end up calling setup too late (sessions could be loaded relatively early, as in, part of the initilization with nvim -S Session.vim).

Comment thread lua/nvim-tree/autocmd.lua
Comment on lines +44 to +47
if vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_call(win, function()
api.open()
end)

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.

There's an edge case with this approach: if nvim-tree was the only buf from a tabpage, it will not be restored. I think that's fine, as it's sort of unlikely. Could add a comment as a reference, or otherwise look into it. The vim api is not very tab friendly, but I guess it should be possible to hook an unholy :[N]tabnew...

@igorlfs

igorlfs commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Am I missing something or is the CI failure unrelated?

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.

1 participant