fix auto session load timing

This commit is contained in:
Ray Elliott 2026-01-12 21:52:50 +00:00
parent 5e3a14596d
commit 7d2c85417d
1 changed files with 11 additions and 2 deletions

View File

@ -106,18 +106,27 @@ local session_aug = vim.api.nvim_create_augroup("SessionManagement", { clear = t
vim.api.nvim_create_autocmd("VimEnter", {
group = session_aug,
pattern = "*",
nested = true, -- Allow other autocmds to fire after loading session
once = true,
callback = function()
-- Only auto-load if:
-- 1. Session.vim exists in cwd
-- 2. No files were specified on command line (vim.fn.argc() == 0)
-- 3. Not started with nvim -S (check if we already loaded a session)
if vim.fn.argc() == 0 and vim.fn.filereadable("Session.vim") == 1 and vim.v.this_session == "" then
vim.cmd("source Session.vim")
vim.cmd("silent! source Session.vim")
end
end,
})
-- Ensure filetype is detected for current buffer after session load
vim.api.nvim_create_autocmd("SessionLoadPost", {
group = session_aug,
pattern = "*",
callback = function()
vim.cmd("filetype detect")
end,
})
-- Auto-save session on exit, but ONLY if Session.vim already exists
vim.api.nvim_create_autocmd("VimLeavePre", {
group = session_aug,