How do I force Vim to check if open files were changed externally and reload them?
Answer
:checktime
Explanation
The :checktime command tells Vim to check whether any open buffers have been modified outside of Vim and prompt you to reload them. This is essential when working with tools that modify files in the background — like git operations, build tools, formatters, or other editors. Unlike autoread, which only triggers on certain events, :checktime gives you explicit control over when to check.
How it works
:checktime— Checks all open buffers against their files on disk. If a file has changed and the buffer has no unsaved modifications, Vim reloads it silently.:checktime {bufnr}— Checks only a specific buffer by number.- If a buffer has both external changes and unsaved local changes, Vim prompts you to choose whether to reload or keep your version.
Example
After running a formatter from a terminal split:
:!prettier --write %
:checktime
Or after a git rebase modifies tracked files:
:checktime
Vim reloads any buffers whose underlying files were updated by the rebase.
Tips
- Pair with
autoreadfor the best of both worlds:set autoreadhandles automatic cases, and:checktimehandles manual triggers. - Map it for convenience:
:nnoremap <leader>r :checktime<CR>to quickly refresh after external tool runs. - In Neovim,
:checktimeis particularly useful sinceautoreadonly fires onFocusGainedandBufEnterevents. - Use
:bufdo checktimeto force-check every buffer if the simple:checktimemisses some.