Skip to content

[idea] Wire checktime on FocusGained/BufEnter so autoread actually fires #140

@stanfish06

Description

@stanfish06

What

Add autocmds that call checktime on FocusGained and BufEnter so that the existing autoread = true setting actually reloads files changed on disk.

Where

lua/config/options.lua:60:

vim.o.autoread = true

The fix belongs in the same file, near the autoread line.

Why it matters

Neovim's autoread does not poll for file changes on its own — it only reloads when triggered by checktime. Without a checktime call, autoread fires only on a narrow set of events (switching to the file via :edit, or when certain shell commands run via :!). In the typical workflow — edit a file in a terminal, switch back to Neovim — the buffer silently stays stale.

The config sets autoread = true (implying a desire for automatic reload) and also makes heavy use of the terminal (, to open a split terminal, the tabe | te tip documented in init.lua). A FocusGained handler is the natural complement: when you Alt-Tab back to Neovim or close the terminal split, all open buffers check for disk changes.

Suggested implementation

In lua/config/options.lua, after the autoread line:

vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter" }, {
    callback = function()
        if vim.fn.getcmdwintype() == "" then
            vim.cmd("silent! checktime")
        end
    end,
})

The getcmdwintype() == "" guard skips the checktime call when the command-line window is open (where it would error). silent! suppresses "file changed on disk" prompts for files that haven't actually changed — only files with real changes will prompt.

Notes

  • BufEnter catches the case where you switch to a buffer in the same Neovim instance (e.g., after a git pull in the terminal split).
  • FocusGained catches the case where Neovim regains focus from another application.
  • This is a zero-dependency, pure-builtin change — no plugins needed.
  • Pairs naturally with the existing autoread setting and the terminal-heavy workflow documented in init.lua.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions