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

How do I discard all unsaved changes and reload the file from disk in Vim?

Answer

:e!

Explanation

:e! forces Vim to reload the current file from disk, discarding every unsaved change in the buffer. The ! override bypasses Vim's usual protection that prevents you from losing work, so use it deliberately. It is the fastest way to abandon an experimental edit session and return to the last saved state.

How it works

  • :e (edit) reloads the current file, but will refuse if there are unsaved changes.
  • Adding ! tells Vim to proceed anyway, discarding modifications without prompting.
  • The cursor position is reset to the top of the file after the reload.
  • Marks, undo history, and other buffer-local state are cleared.

Example

You have edited a file and want to start over:

Buffer state (unsaved edits):      After :e!:
line 1 original                    line 1 original
line 2 CHANGED                     line 2 original
line 3 NEW LINE                    line 3 original

The buffer is reset to exactly what is on disk.

Tips

  • Compare with :u (undo): undo steps through individual changes, whereas :e! reloads the entire file at once regardless of how many changes were made.
  • Use :earlier 1f to revert to the state at the last file write while keeping undo history intact — a less destructive alternative.
  • :e! % is equivalent but explicit; % is automatically the current file when no filename is given.
  • For multiple buffers, :bufdo e! reloads all buffers from disk.

Next

How do I remove a word I accidentally added to my Vim spell dictionary?