···11-- Autocmds are automatically loaded on the VeryLazy event
22-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
33-- Add any additional autocmds here
44+55+-- Aggressive fugitive auto-reload with polling
66+local function setup_fugitive_aggressive_reload()
77+ local timer = nil
88+99+ local function refresh_fugitive()
1010+ -- Check all files for changes
1111+ vim.cmd("silent! checktime")
1212+1313+ -- Force refresh any open fugitive buffers
1414+ for _, win in ipairs(vim.api.nvim_list_wins()) do
1515+ local buf = vim.api.nvim_win_get_buf(win)
1616+ if vim.api.nvim_buf_get_option(buf, "filetype") == "fugitive" then
1717+ vim.api.nvim_buf_call(buf, function()
1818+ pcall(vim.cmd, "silent! edit")
1919+ end)
2020+ end
2121+ end
2222+ end
2323+2424+ local function start_polling()
2525+ if timer then vim.fn.timer_stop(timer) end
2626+ -- Poll every 2 seconds
2727+ timer = vim.fn.timer_start(2000, function()
2828+ refresh_fugitive()
2929+ end, { ["repeat"] = -1 })
3030+ end
3131+3232+ local function stop_polling()
3333+ if timer then
3434+ vim.fn.timer_stop(timer)
3535+ timer = nil
3636+ end
3737+ end
3838+3939+ local augroup = vim.api.nvim_create_augroup("FugitiveAggressiveReload", { clear = true })
4040+4141+ -- Start polling when fugitive buffer opens
4242+ vim.api.nvim_create_autocmd("FileType", {
4343+ group = augroup,
4444+ pattern = "fugitive",
4545+ callback = start_polling,
4646+ })
4747+4848+ -- Stop polling when no fugitive buffers are open
4949+ vim.api.nvim_create_autocmd("BufDelete", {
5050+ group = augroup,
5151+ callback = function()
5252+ -- Check if any fugitive buffers remain
5353+ local has_fugitive = false
5454+ for _, buf in ipairs(vim.api.nvim_list_bufs()) do
5555+ if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, "filetype") == "fugitive" then
5656+ has_fugitive = true
5757+ break
5858+ end
5959+ end
6060+ if not has_fugitive then
6161+ stop_polling()
6262+ end
6363+ end,
6464+ })
6565+end
6666+6767+-- Set up aggressive reload
6868+setup_fugitive_aggressive_reload()
···11-- Options are automatically loaded before lazy.nvim startup
22-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
33-- Add any additional options here
44+55+-- Enable autoread to detect external file changes
66+vim.opt.autoread = true