1

Sometimes I want to get back and copy some old code that I deleted and use it. For example, I'll do:

:earlier 12h

and then yank the deleted code.

To get back to where I was, I'll issue a command like:

:later 13h

with the time argument for the :later command being longer than the time argument I supplied for the :earlier command.

This works, but it seems like there should be a cleaner way to jump back to the latest version of the code. I can't seem to find a command to do that, though.

2
  • Change your workflow with git and fugitive?
    – D. Ben Knoble
    Jul 12 '18 at 21:49
  • @D.BenKnoble that's a good point. You can always use :Glog in fugitive to load older revisions of the file, or :Gdiff <revision> to view the differences in vimdiff mode. I would consider that a better practice than :earlier
    – Ocab19
    Jul 13 '18 at 11:00
2

As long as you don't write the current buffer, and you probably don't need to if you are just looking back to yank some stuff, you can use :edit! (or simply :e!) to reload the file from disk, thus undoing all those changes.

2

How about, in Normal mode, 9 9 9 Ctrl+R ?

From :h CTRL-R:

CTRL-R      Redo [count] changes which were undone.

If you overshoot it's okay. You can't go past the most recent change. (To the future?)

Of course, you can use any sufficiently high number. 999 is just a quick way to a number likely to do the job. If not add another 9 or two. Just hammer on it until you feel good about it. ;)

4
  • If my boss finds out I only make 99 edits in 12 hours of work I am going to be in trouble.
    – Rich
    Jul 12 '18 at 5:46
  • @Rich Heh. Do you spend a lot of time 100+ entries back looking for stuff? Boss might wonder why you are making slow progress...stuck in the past. ;) Seriously, though, how many is it? Would 999 do it? (My max is 3000 but I've never looked that far back.)
    – B Layer
    Jul 12 '18 at 6:10
  • I actually have no idea. I’d imagine 999 would cover it, but to be on the safe side I’d probably go with 9999. Like you said, you can’t overshoot!
    – Rich
    Jul 12 '18 at 6:16
  • Either way...you convinced me. I'm going with 999..9999. Fortunately it's about 100ms difference. :)
    – B Layer
    Jul 12 '18 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.