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 10mreverts to the state 10 minutes ago:earlier 1hreverts to 1 hour ago:earlier 5sreverts to 5 seconds ago:earlier 3freverts 3 file-writes ago
Example
After spending 30 minutes editing and realizing you took a wrong turn 15 minutes ago:
:earlier 15m
Tips
:later 10mmoves forward in time (un-reverts)g-andg+step through the undo tree chronologically:undolistshows all undo branches:set undofilepersists undo history across Vim sessions- This uses Vim's undo tree, which never loses data