Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get back to where I was before after hitting gg in Vim?

Tags:

vim

macvim

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?

like image 363
c00kiemonster Avatar asked Jan 07 '11 06:01

c00kiemonster


2 Answers

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.

like image 144
David Tang Avatar answered Sep 18 '22 10:09

David Tang


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.

like image 34
Brian Carper Avatar answered Sep 20 '22 10:09

Brian Carper