Monday, January 14, 2013

Vim tips: Moving around using marks and jumps



Editing in Vim can be a breeze, if you know how to make use of its more advanced features. Moving around files can feel like a slog if you're stuck with the basic movement keys, but editing is effortless when you have command of marks and jumps.
Basically, a mark is a bookmark or placeholder that allows you to return to a spot in the file where you were editing. This can be handy when you're working on longer projects, whether you're writing a long paper, making changes to your Apache configuration, or writing code.

Jumps are movements within a file. For example, when you use G to move to the last line of a file from your current position, that's a jump. Vim not only makes it easy to move from one point in the file to another, it also makes it easy to retrace your steps.



Vim mark quick reference
mx tells Vim to add a mark called x.
`x tells Vim to return to the line and column for mark x.
'x tells Vim to return to the beginning of the line where mark x is set.
`. moves the cursor to the line and column where the last edit was made.
'. moves the cursor to the line where the last edit was made.
'" moves the cursor to the last position of the cursor when you exited the previous session.
:marks shows all marks set.
:marks x shows the mark named x.
:jumps shows the jumplist.
Ctrl-o moves the cursor to the last jump.
Ctrl-i moves the cursor to the previous jump.
H moves the cursor to the top of the screen or viewport.
M moves the cursor to the middle of the screen or viewport.
L moves the cursor to the bottom of the screen or viewport.









Reference :

By Joe 'Zonker' Brockmeier