Vim: Marks
Marks enable you to remember a location in a buffer or file so you can quickly jump back to it.
Local marks are specific to the current file and are indicated by lowercase characters. Global marks can be across any files and are indicated by uppercase characters.
Setting marks:
m{a-z}
Set a local mark at the cursor position.m{A-Z}
Set a global mark at the cursor position.
Local marks are lost when the file is removed from the buffer list. Local marks can be used with operators.
Global marks include the filename and can be used to jump to another file. These are remembered across Vim sessions. Global marks can only be used as motions if they are defined in the file that the current buffer is displaying.
You can move to a mark with either the backtick or single quote characters:
`h
jump to markh
. The cursor is positioned at the exact location. The motion is charwise,'h
jump to markh
. The cursor is positioned on the first non-blank character of the line indicated by the location. The motion is linewise.
A mark is not visible in any way.
:marks
list all marks,
Marks are independent from registers (these two concepts are often confused).
Numbered Marks
Marks {0-9}
are used to indicate the location of the cursor the last time
you exited vim. 0
is the location the very last time you exited Vim, 1
the
time before that and so on. These marks can not be manually set.
Special Marks
Remember that `
jumps to the actual cursor position and '
jumps to the
first non-blank character on the target line.
`[
and'[
move to the first character of the previously yanked or changed text.`]
and']
move to the last character of the previously yanked or changed text.`<
and'<
move to first line or character of the last visual area in the current buffer. You often see this inranges
.`>
and'>
move to last line or character of the last visual area in the current buffer. You often see this inranges
.``
and''
move to position before latest jump. An easy way to jump back.
There are more special marks.
Do I Use Marks?
I have never been a big user of marks, but there are a couple of use cases that do work for me.
The first is using `0
to jump to where I left off the last Vim session.
This can save some time if you’re not quite in the groove yet.
The second is if I’m spending a lot of time in a particular code base it can be
useful to associate commonly referenced files with an uppercase mark. Even
then, I mostly use something like CtrlP
to jump around the code base.
So, I guess marks are good to know about, but I don’t use them much.
If there was a plugin that displays marks, perhaps in the gutter, that might be useful (but, I have never bothered to look).
Resources
:help mark
:help mark-motions