13

For example, let's say I am happily editing a document in Vim when I accidentally hit gg. I then end up on the first row of the document, and of course I have no idea which was the exact row that I last edited. Is there any way of magically get back to the last edited row before the gg jump?

c00kiemonster
  • 22,241
  • 34
  • 95
  • 133
  • 1
    Great question that I'd just never thought to ask. – richo Jan 07 '11 at 06:12
  • 1
    Tell me about it. I have used Vim for a few months now and the involuntary gg jumps have been pretty much my only 'bad' experience with Vim. But still I never figured out how to reverse it. Until today that is when I reached the tipping point and spent a few seconds here to get an answer! – c00kiemonster Jan 07 '11 at 06:17

2 Answers2

21

The shortcut is Ctrl+O (that's the letter 'O') to move back to previous position.

And Ctrl+I to undo that (move back to the position before you pressed Ctrl+O).

These can be used multiple times like the back and forward buttons on your browser to travel to previously "jumped to" positions.

David Tang
  • 92,262
  • 30
  • 167
  • 149
10

To bounce back and forth between your current position and the last place you jumped from, you can use `` (two backticks). See :h `` for a list of this and other shortcuts for jumping around.

Brian Carper
  • 71,150
  • 28
  • 166
  • 168
  • Backticks instead of Ctrl-because the backticks jump once, since the shortcut ctrol it takes us more deeply to the list of jumps – SergioAraujo Jan 07 '11 at 11:13