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

How do I restore a file to its state at a specific time?

Answer

:earlier 10m

Explanation

The :earlier command restores the buffer to its state at a specific time in the past. Vim tracks changes with timestamps, allowing time-based undo.

How it works

  • :earlier 10m reverts to the state 10 minutes ago
  • :earlier 1h reverts to 1 hour ago
  • :earlier 5s reverts to 5 seconds ago
  • :earlier 3f reverts 3 file-writes ago

Example

After spending 30 minutes editing and realizing you took a wrong turn 15 minutes ago:

:earlier 15m

Tips

  • :later 10m moves forward in time (un-reverts)
  • g- and g+ step through the undo tree chronologically
  • :undolist shows all undo branches
  • :set undofile persists undo history across Vim sessions
  • This uses Vim's undo tree, which never loses data

Next

How do you yank a single word into a named register?