feat: restore buffers after loading a session#3335
Open
igorlfs wants to merge 1 commit into
Open
Conversation
igorlfs
commented
Jun 12, 2026
| end, | ||
| }) | ||
|
|
||
| vim.api.nvim_create_autocmd("SessionLoadPost", { |
Contributor
Author
There was a problem hiding this comment.
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).
igorlfs
commented
Jun 12, 2026
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) |
Contributor
Author
There was a problem hiding this comment.
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...
Contributor
Author
|
Am I missing something or is the CI failure unrelated? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SessionLoadPostand reopen them.