Vim Recipes ‣ Navigation ‣ Navigating Marks
You want to bookmark specific points in a file so you can easily jump to them from elsewhere.
Use Vim's marks feature. A mark is a character in the range a-zA-Z0-9. It's represented in the examples below as M.
| Command | Action |
|---|---|
| mM | Mark the current position as M. |
| 'M | Jump to the first character of the line containing M. |
| `M | Jump to the position of mark M. |
Marks 0-9 are mainly for Vim's internal use, so ignore them. Marks a-z are only available in the current file, and are deleted when it is closed. Marks A-Z are available across multiple files. If your .viminfo file is available, as it usually will be, they persist across sessions.
Marks have a multitude of uses. I use them often when I have a section of a file that I need to keep referring to: I mark that section with ma, jump to it with 'a, then return to where I was previously with ``. I use them almost implicitly when formatting and filtering text to define the text that I want to edit.
The :marks command shows a list of marks you have set, which is useful for the kind of person who fully embraced the idea of marking anything and everything but was unable to remember the significance of all 52 marks he used.