Last Updated: February 15, 2022
·
25.14K
· tlehman

Time traveling in vim

Have you ever been using vim, and you mess up, hit u some number of times, and then you go too far?

You can get out of this by just using :earlier and :later.

For example :earlier 35s will go back 35 seconds in time. If you over shot your destination, you can move forward in time with :later 12s.

Related protips:

Basic Vim commands - For getting started

20 Responses
Add your response

Nice! Didn't know that was possible.

over 1 year ago ·

VIM has actually one of the most advanced history systems I know of. If you want to know more about VIM's undo-branches, just head over to the wiki -> http://vim.wikia.com/wiki/Using_undo_branches

over 1 year ago ·

@originell Undo branches look amazing, thank you.

over 1 year ago ·

That is amazing!

over 1 year ago ·

@tlehman always glad when I can amaze people with knowledge :D

over 1 year ago ·

I knew vim has crazy functionality, but wholy SH*T, awesome, thanks!

over 1 year ago ·

Great feature!

over 1 year ago ·

I use Gundo [1] for many of the history operations, very powerful.

[1] http://sjl.bitbucket.org/gundo.vim/

over 1 year ago ·

Nice feature, but here's one scenario of undo that I still didn't solve:

Start up vim. Hit Insert, type two or three words, then press Ctrl-U. It'll delete the line you've just typed.

Can anyone tell me how to undo that and get the line back? :->

PS in bash and other readline-using thingies, I can sometimes use Ctrl-Y as the just-deleted line went to a buffer that Ctrl-Y then yanks. This doesn't work in vim though.

over 1 year ago ·

@goblin Ctrl-R doesn't solve that?

over 1 year ago ·

It does indeed not seem to be possible to undo Ctrl-U. The state you want to undo to does not seem to be saved as a leaf in the undo tree.

over 1 year ago ·

Umh, not just saved as a leaf, saved as a node.

over 1 year ago ·

I asked the question about Ctrl-U on IRC a while back and got a perfect response. See the first line, here: https://github.com/sharpsaw/vim-dots/blob/master/.vim/plugin/betterdefaults.vim

over 1 year ago ·

This is a very nice tips and tricks. But I am a bit curious that how do you use it in your workflow ?

over 1 year ago ·

@nxqd whenever I do something, then undo it several times, then go too far, then need to rewind the whole thing to get something back.

over 1 year ago ·

This seriously just changed my life.

over 1 year ago ·

Awesome!!

over 1 year ago ·

Every time I learn a new VIM feature I feel amazed, thanks for sharing! 👍

over 1 year ago ·

Wow, this is amazing, I always lose work by compulsively pressing U

over 1 year ago ·

amazing! Thanks, man!

over 1 year ago ·