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

How do I make Vim automatically reload files changed outside the editor?

Answer

:set autoread | autocmd FocusGained * checktime

Explanation

When working with Git, build tools, or collaborators, files may change outside Vim. The autoread option combined with FocusGained autocmd ensures Vim detects and reloads these changes automatically when you return to the editor.

How it works

  • autoread — tells Vim to re-read files that changed on disk (when Vim notices)
  • checktime — explicitly tells Vim to check all buffers for external changes
  • FocusGained — fires when the terminal/GUI regains focus
  • CursorHold — fires when the cursor is idle, another good trigger

Example

set autoread
autocmd FocusGained,BufEnter * checktime
autocmd CursorHold,CursorHoldI * checktime
1. You're editing file.py in Vim
2. A git pull modifies file.py externally
3. You switch back to Vim (FocusGained fires)
4. checktime detects the change
5. File is silently reloaded with the new content

Tips

  • autoread alone isn't enough — Vim only checks on specific triggers, hence the autocmds
  • If the file changed AND you have unsaved edits, Vim will prompt you
  • Set updatetime=250 for faster CursorHold detection (default is 4000ms)
  • Use :checktime manually to force an immediate check of all buffers

Next

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