Vim Undo Magic

Ever have a time when you are happily editing a script in vim and you realize you made a mistake over the course of editing? Luckily, Vim supports back in time undos.

You want to go back 10 minutes?

:earlier 10m

You want to go forward in time by 5 seconds?

:later 5s

Sweet cuppin’ cakes that’s ballsy. Armed with this tool, you step forward and backwards in your undo/redo adventure, you make an accidental edit. Whoops. Now all the code you’ve edited in the 10 minutes that you rolled back with the handy-dandy <code>:earlier</code> command is gone…right?

Nope! Undo branching is where the real awesomeness of Vim shines. If you realize your mistake, you can find a list of undo branches like so:


Which will show you something like this:

number changes when saved

3 3 08:59:35
4 2 09:00:13

To jump to one of those branches, you can type:

:undo 3 or :undo 4

I <3 Vim

(via Life Hacker)