vimtricks.wiki Concise Vim tricks, one at a time.

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 autoread for the best of both worlds: set autoread handles automatic cases, and :checktime handles manual triggers.
  • Map it for convenience: :nnoremap <leader>r :checktime<CR> to quickly refresh after external tool runs.
  • In Neovim, :checktime is particularly useful since autoread only fires on FocusGained and BufEnter events.
  • Use :bufdo checktime to force-check every buffer if the simple :checktime misses some.

Next

How do I return to normal mode from absolutely any mode in Vim?