Going back to the previous line with Vim

I was wondering if there is a way to go back to the previous line that you were in Vim.

Say, for example, I am writing C code and I just wanted to add #include at the top of the page: I press gg and go to the beginning, add #include , and then I want to go back to the line I stopped with.

Is this possible in Vim?

+54
vim vi
Jan 29 '11 at 15:00
source share
2 answers

Yes. You can use `` to switch between the last two positions.

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

+83
Jan 29 '11 at 15:04
source share

Use the sign:

 ma 

marks a spot (up to gg )

 `a 

brings you back.

+29
Jan 29 '11 at 15:04
source share



All Articles