Skip to content

Vim - Markers

Vim’s marks feature allows you to set bookmarks or waypoints in your files. This enables you to quickly jump back to specific locations within a file or even across different files, significantly speeding up navigation in larger projects or complex documents.

This chapter covers:

  • Creating local and global marks.
  • Jumping to marks.
  • Listing existing marks.
  • Deleting marks.

Vim supports several types of marks:

  • Lowercase marks (a-z): Local to a single buffer (file). Each buffer can have its own set of 26 lowercase marks. These are lost when the buffer is closed unless saved in a viminfo file.
  • Uppercase marks (A-Z): Global, also known as file marks. These store both the file and the position within that file. They persist across Vim sessions if viminfo is configured correctly. You can jump to a file mark from any buffer.
  • Numeric marks (0-9): Set automatically by Vim when it writes the viminfo file, storing positions in recently edited files. Mark 0 is the position in the last exited file.
  • Special marks: Predefined by Vim (e.g., . for last edit, ' for position before last jump, < and > for start/end of last visual selection).

To create a mark in Normal mode, use the m command followed by the mark character (a-z for local, A-Z for global).

m{mark-character}

Examples:

  • ma - Sets local mark ‘a’ at the current cursor position in the current file.
  • mM - Sets global mark ‘M’ at the current cursor position, associated with the current file.

Setting a mark does not move the cursor.

Once a mark is set, you can jump to it using either the backtick (`) or single quote (’) followed by the mark character.

CommandDescription
“{mark-character}`
(backtick)
Move cursor to the exact line and column where the mark was set.
'{mark-character}
(single quote)
Move cursor to the beginning (first non-blank character) of the line where the mark was set.

Examples:

  • “a` - Jump to the exact position of local mark ‘a’.
  • 'M - Jump to the beginning of the line of global mark ‘M’ (this might open the file if it’s not currently open).
  • '' - Jump to the beginning of the line before the latest jump.

To see a list of all currently set marks (local, global, and some special ones), use the :marks command:

:marks

This will display a list showing the mark character, line number, column, and the filename (especially for global marks). For example:

mark line col file/text
' 14 0 # Previous jump
a 5 10 print('Hello')
M 73 4 /home/user/project/main.py

You can also list specific marks:

:marks aM

To delete one or more marks, use the :delmarks command:

:delmarks {mark-characters}

Examples:

  • :delmarks a - Deletes local mark ‘a’.
  • :delmarks xyz - Deletes local marks ‘x’, ‘y’, and ‘z’.
  • :delmarks a-d - Deletes local marks ‘a’, ‘b’, ‘c’, and ‘d’.
  • :delmarks AB - Deletes global marks ‘A’ and ‘B’.
  • :delmarks! - Deletes all lowercase marks (a-z) for the current buffer. (Note: this does not delete global marks by default; see :help :delmarks! for more nuances).

Global marks are usually saved in the viminfo file (typically ~/.viminfo). If you delete a global mark, it will also be removed from viminfo the next time Vim writes to it.

Practical Application: Marks are extremely useful for:

  • Quickly navigating between a function definition and its call sites within a large file.
  • Setting a temporary placeholder before performing a complex operation, allowing you to easily return.
  • Jumping between frequently accessed files in a project using global marks.