Vim provides several types of marks, with different behaviors and uses. Our previous examples set
the x
mark, so lets start by explaining those examples in a bit more details.
Lower-case Marks
Note that the x
character used in our previous examples is a
lower-case character. Although we chose x
, those examples could have used any lower-case letter in
the range from [a-z].
The main characteristics of lower-case marks are:
-
Lower-case marks are local to a buffer, meaning that the
x
mark from our examples can be independently set in multiple buffers, without conflict. For this reason, lower-case marks are sometimes called "local marks". -
They are remembered for as long as the buffer is in memory (or more specifically, as long as it remains in the buffer list). If you set a mark then close the buffer, next time you open the file the marks will be lost.
-
Lower-case marks are automatically deleted if the line containing the mark is deleted.
Upper-case Marks
Upper-case marks refer to marks that are defined using upper-case letters, in the [A-Z] range. Upper-case marks are used just like the lower-case marks, though they have a few important differences:
-
Unlike lower-case marks which are references within a single buffer, upper-case marks contain references to the files that they are defined in, allowing jumps between files. For this reason, the are sometimes called "file marks".
-
Upper-case marks persist between sessions, and are not lost when a buffer is closed.
-
Upper-case marks are globally-available, meaning that the
A
mark means the same thing in all files. In other words, only 26 upper-case marks can be defined at a time. Redefining an upper-case mark in one file redefines it in all files. For this reason, upper-case marks are sometimes called "global marks".
Read-only Marks
The lower-case and upper-case marks allow users to mark positions in buffers and files then quickly return to them. Vim additionally provides a variety of "read-only" marks, which are set automatically by Vim, but allow users to quickly jump to them. Some of the common read-only marks are:
Mark | Action |
---|---|
`` | Move the cursor to the position before the most recent jump |
`. | Move the cursor to the position of the most recent edit |
`^ | Move the cursor to the position when the editor entered INSERT mode |
`[ | Move the cursor to the start of the most-recently yanked or changed text |
`] | Move the cursor to the end of the most-recently yanked or changed text |
`< | Move the cursor to the start of the most-recent visual selection |
`> | Move the cursor to the end of the most-recent visual selection |
`" | Move the cursor to the position when this buffer was most-recently exited |
`0 | Move the cursor to the location when Vim was most-recently exited |
`( | Move the cursor to the start of the current sentence |
`) | Move the cursor to the end of the current sentence |
`{ | Move the cursor to the start of the current paragraph |
`} | Move the cursor to the end of the current paragraph |
As with all marks, use either `` or
'` followed by the read-only mark to jump to the
desired location.
There are also a few commands that help navigate with marks.
Command | Action |
---|---|
]` | Move the cursor to the next lower-case mark |
[` | Move the cursor to the previous lower-case mark |
]' | Move the cursor to the start of the next line that contains a lower-case mark |
[' | Move the cursor to the start of the previous line that contains a lower-case mark |