Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning to previous line with Vim

Tags:

vim

vi

I was wondering if there's a way to return to the previous line you were on in Vim.

Say, for example, I'm writing C code and I just wanted to add an #include at the top of the page: I press gg and go to the top, add the #include, and then I want to return to the line I left off of.

Is this possible in Vim?

like image 836
Amit Avatar asked Jan 29 '11 15:01

Amit


People also ask

How do I go back to the previous line with code?

Go back to previous line hotkey : r/vscode.

How do I go to a specific line in vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.


2 Answers

Yes. You can use `` in order to jump between the last two positions.

Otherwise, Ctrl+O and Ctrl+I can help you. See :help CTRL-I.

like image 90
Benoit Avatar answered Sep 20 '22 08:09

Benoit


Use a mark:

ma 

marks the spot (before the gg)

`a 

brings you back.

like image 43
Matteo Riva Avatar answered Sep 17 '22 08:09

Matteo Riva