Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim return to second last edited line

Tags:

vim

In vim you can go back to the last edited line with '. , but is there a way to go back to the second-last edited line? Suppose I did some edits at line 100, then some edits at line 1, is there a quick way to return to line 100? I know a mark can be used but that requires forethought...

like image 658
Mike B Avatar asked Jan 16 '11 08:01

Mike B


2 Answers

You can use the jumplist (:help jumplist). Simply use Ctrl-O to go back (and Ctrl-I to go forward) in the list of the last places you either edited or jumped to (via %, /, [[ etc: see :help jumplist for the full list).

To go back to the place you edited before last then assuming you've done no other jumps in the meantime, this would be Ctrl-O Ctrl-O or (I think) 2 Ctrl-O.

like image 116
DrAl Avatar answered Nov 03 '22 09:11

DrAl


In addition to jumplist, vim has also a changelist, which can be iterated over using g; (to older item) and g, (to newer item) motions.

like image 9
ZyX Avatar answered Nov 03 '22 11:11

ZyX