Vim tip 31: mark frequently used locations
You can save frequently visited locations using marks for quicker navigation to those positions in the file. You can also pair marks with motion commands for tasks like copying, deleting, etc.
- ma mark location in the file using the alphabet
a
- you can use any of the 26 alphabets
- use lowercase alphabets to work within the current file
- use uppercase alphabets to work from any file
- :marks will show a list of the existing marks
- `a move to the exact location marked by
a
- 'a move to the first non-blank character of the line marked by
a
- 'A move to the first non-blank character of the line marked by
A
(this will work for any file where the mark was set) - d`a delete from the current character to the character marked by
a
- marks can be paired with any command that accept motions like
d
,y
,>
, etc
- marks can be paired with any command that accept motions like
Motion commands that take you across lines (for example, 10G) will automatically save the location you jumped from in the default `
mark. You can move back to that exact location using ``
or the first non-blank character using '`
. Note that the arrow and word motions aren't considered for the default mark even if they move across lines.
See :h mark-motions for more ways to use marks.
Video demo:
See also my Vim Reference Guide and curated list of resources for Vim.