Skip to content
Vim

Marks (Bookmarks)

Jump back to positions in a file or across files with marks.

By EZ4Code Team
marknavigationbookmark

Code

ma                  " set mark 'a' at cursor (lowercase = local to buffer)
mA                  " set mark 'A' (uppercase = global, file-level)
'a                  " jump to line of mark a (linewise)
`a                  " jump to exact column of mark a
:marks              " list marks in current buffer
:delmarks a         " delete mark a
:delmarks!          " delete all lowercase marks

" Built-in marks
`.                  " position of last change
``                  " position before last jump (toggle)
`<  `>              " start/end of last visual selection
`[  `]              " start/end of last yanked/pasted text
`^                  " position of last insert-mode exit

Explanation

Marks are named positions. Lowercase (a–z) are local to a buffer; uppercase (A–Z) are global and associate with the file — jump to 'B from any buffer and Vim opens the right file at the mark. 'a jumps linewise; `a jumps to the exact column. Built-in marks are extremely useful: `` toggles between the last two positions, `. goes to the last edit, `<`/`>` delimit the last visual selection (great for re-selecting an indent). Use marks in commands: :'a,'bs/old/new/g replaces between marks a and b.

More Vim Snippets