deadghost
deadghost

Reputation: 5217

Vim - Go to previous location

Say I open a file in vim. I start on line 1 column 1 and hold down j until I am on line 14. Pressing :7CR puts me on line 7. I press yy to "yank".

How do I return to line 14? Using CTRL + o takes me back to the top of the file. ` ` gives me the same results.

Upvotes: 101

Views: 51470

Answers (6)

NPE
NPE

Reputation: 500357

Why not set a mark using ma for example, and then return to it later using `a or 'a?

Upvotes: 29

kikuchiyo
kikuchiyo

Reputation: 3421

Mark the line you were originally on using ma, then 'a to return there.

Upvotes: 12

evnu
evnu

Reputation: 6680

One more way: To jump back to another line, you can use ''. This works similar to an automatic mark, which is set for certain jump movements.

Upvotes: 38

octopusgrabbus
octopusgrabbus

Reputation: 10695

If you want to return to a previous location, first you have to mark that location using the mark (m) command, followed by any letter a-z or A-Z, like ma to mark a location as 'a'.

To return to that location you would enter `a.

Upvotes: 3

kev
kev

Reputation: 161674

You can type 7G to jump to line#7, then type Ctrl-o to jump back.
:set showcmd to show what you have typed at the right bottom.


To yank line#7 (No cursor moving):

:7y

To paste line#7 below line#14:

:7t14

Upvotes: 126

romainl
romainl

Reputation: 196556

<C-o> and <C-i> allow you to go down and up the jumplist. They work with "jump" commands but not with jjjjjjjjjjj.

To take advantage of this feature — and save a lot of time and keypresses in the process — I'd advise you to get into the habit of using better ways to navigate through your code : /?^$fFtTbBeEwW{} and so on.

And yes, use marks.

Upvotes: 66

Related Questions