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?
Asked
Active
Viewed 833 times
13
-
1Great question that I'd just never thought to ask. – richo Jan 07 '11 at 06:12
-
1Tell 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 Answers
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
-
3Superb. You have no idea how much profanity you have saved me from uttering. – c00kiemonster Jan 07 '11 at 06:11
-
-
It evens works when you are jumping on a tag. I used to use Ctrl+T, now I use Ctrl+O/I all the way ! – Xavier T. Jan 07 '11 at 07:07
-
-
2out of curiosity, is there a mnemonic for `Ctrl-O` or is `O` just random? – Jeffrey Jose Jan 16 '11 at 01:25
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