Setting Marks in Neovim


When editing a file one often needs to move to another location in the file, make an edit, then return to the original location to continue editing. While Vim offers many commands that ease navigating the file, it can often be convenient to set a bookmark, move to the other location in the file to make edits, then jump directly back to the bookmark to continue editing.

To set a mark, first move the cursor to the desired position in the buffer, as shown below:

Initial Conditions
I·have·always·believed,·and·I·still·believe,
that·whatever·good·or·bad·fortune·may·come·our·way
we·can·always·give·it·meaning·and
transform·it·into·something·of·value.
NORMAL40%2:21
 

Note that the status line indicates that the cursor position is 2:21.

To create a mark, type m followed by a single letter, as in m{A-Za-z}. For example, to name this mark x:

Set the Markmx
I·have·always·believed,·and·I·still·believe,
that·whatever·good·or·bad·fortune·may·come·our·way
we·can·always·give·it·meaning·and
transform·it·into·something·of·value.
NORMAL40%2:21
 

The :marks command is very useful for checking which marks are currently set.

Review Current Marks
I·have·always·believed,·and·I·still·believe,
that·whatever·good·or·bad·fortune·may·come·our·way
we·can·always·give·it·meaning·and
transform·it·into·something·of·value.
NORMAL40%2:21
 
:marksmark line  col file/text '      1    0 I have always believed, and I still believe, x      2   20 that whatever good or bad fortune may come our way "      1    0 I have always believed, and I still believe, [      1    0 I have always believed, and I still believe, ]      4    0 transform it into something of value.

Executing this command opens a window providing information about the marks that are currently set. We will review the different information in this window shortly.

Recall from above that the cursor was located at position 2:21 when we set the mark, but the output of :marks shows that the mark is located at column 20. This is due to unfortunate differences in how data has been stored and accessed in different parts of Vim, that have been retained for backwards-compatibility reasons. In this case, while the buffer is (1, 1)-indexed, meaning that the top-left corner of the buffer is (1, 1), the output of :marks is (1,0)-indexed (meaning that rows start at 1, while columns start at 0), so reported columns are always 1 less than what was set.