In the buffer
You saved the file after changing DEBUG to False. Since then you changed the retry count and added a line. Before:
# Configuration
DEBUG = False
MAX_RETRIES = 10
TIMEOUT = 30
^
After typing :earlier 1f and <CR>:
# Configuration
DEBUG = False
MAX_RETRIES = 3
^
The two edits made after the save are gone. The edit you saved stays. The buffer matches the file on disk again, so the modified flag clears, and the cursor lands where the oldest undone change happened.
When you would reach for it
You saved, then started an experiment: a few substitutions, a deleted block, a rename that touched a dozen lines. It went nowhere and you want the file back the way it was when you last wrote it. Pressing u until it looks right means counting changes you did not count while making them. :earlier 1f uses the save as the landmark and goes straight there, in one step, without touching the disk.
Gotchas
- If the buffer has no changes since the last save,
:earlier 1fdoes not stay put. It goes back to the write before that one. Run it right after:wand you lose the work between your last two saves.:later 1fbrings it back. - If you have not saved since opening the file, there is no write to return to, and
:earlier 1fgoes all the way back to before your first change. - Undo history normally lives only as long as the buffer. Close the file and reopen it, and there is nothing to walk back through. Set
'undofile'to keep history on disk between sessions, which also makesfcounts work across them. - This is not
:e!. It moves through undo history, so nothing is lost:<C-r>replays the undone changes one at a time, and:later 1frestores them all at once. Pressinguafterward does the opposite of what you might hope; it keeps going backward from the saved state.
Variants
:later 1f
Moves forward to the next save, or to the newest state if there is no later save. The exact inverse of :earlier 1f.
:earlier 10m
Goes back to the buffer as it was ten minutes ago. The units are s, m, h, and d, for when you remember when things were fine but not which change broke them.
:earlier 3f
Goes back three saves. A larger count than the number of writes stops at the original state of the buffer rather than failing.