Skip to main content

Introduction

Marks allow you to remember positions in files and jump between them instantly. Jump lists track your movements for easy navigation history.

Marks Overview

Mark Types

Local marks — valid within one file
ma              " Set mark 'a' at cursor
'a              " Jump to line of mark 'a'
`a              " Jump to position of mark 'a'
  • Persists while buffer is loaded
  • Erased if line is deleted
  • Restored with undo/redo
  • Each buffer has its own set
Marks ‘a-‘z are like bookmarks within a file. Marks ‘A-‘Z are like bookmarks that work across files.

Setting Marks

Basic Mark Commands

1

Set a mark

m{a-zA-Z}       " Set mark at cursor position
Examples:
ma              " Set local mark 'a'
mA              " Set global mark 'A'
mt              " Set mark 't' (for "top")
mb              " Set mark 'b' (for "bottom")
2

Set mark from Ex command

:mark {a-zA-Z}  " Set mark at current line
:k{a-zA-Z}      " Short form
Examples:
:42mark a       " Set mark 'a' at line 42
:100ka          " Set mark 'a' at line 100
Use mnemonic letters for marks:
  • mt for “top” of a section
  • mb for “bottom”
  • mc for “code” you’re working on
  • md for “definition”

Special Mark Commands

m'              " Set previous context mark
m`              " Same as m'
m[              " Set start of last change/yank
m]              " Set end of last change/yank
m<              " Set start of last visual selection
m>              " Set end of last visual selection

Jumping to Marks

Jump Commands

'{mark}         " Jump to first non-blank in line
Examples:
'a              " Go to line of mark 'a', first non-blank
'A              " Go to mark 'A' (may switch files)
''              " Go back to previous position
  • ' (single quote) jumps to the line (first non-blank character)
  • ` (backtick) jumps to the exact position (line and column)
Example:
" Set mark at column 20
ma

" Jump to line, column 1 (or first non-blank)
'a

" Jump to exact position, column 20
`a

Special Marks

Vim maintains several special marks automatically:
'[              " Start of last change/yank
']              " End of last change/yank
`[              " Exact start position
`]              " Exact end position
'.              " Position of last change
`^              " Position of last insert
Example:
yap             " Yank a paragraph
`]              " Jump to end of what was yanked

Listing and Deleting Marks

List Marks

:marks          " List all marks
Example output:
mark line  col file/text
a      5    0  first function
b     42   10  second function
A     10    0  ~/project/main.lua

Delete Marks

1

Delete specific marks

:delmarks a         " Delete mark a
:delm a             " Short form
:delmarks abc       " Delete marks a, b, c
:delmarks a-d       " Delete marks a through d
2

Delete all local marks

:delmarks!          " Delete all lowercase marks (a-z)
This also clears the changelist.

Jump Lists

Understanding Jump Lists

Vim maintains a list of positions where you’ve “jumped” to:
jump line  col file/text
  3     1    0 first line
  2    70    5 middle section  
  1   154   23 function definition
>
The > indicates your current position.

Jump Commands

CTRL-I and <Tab> are normally the same. In GUI or modern terminals, they can be mapped separately.

What Creates a Jump?

Commands that add to the jump list:
  • ' and ` — Jump to mark
  • G — Go to line
  • / and ? — Search
  • n and N — Next/previous search
  • % — Jump to matching bracket
  • ( and ) — Sentence movement
  • { and } — Paragraph movement
  • [[ and ]] — Section movement
  • :tag — Jump to tag
  • CTRL-] — Jump to definition
  • Starting to edit a new file
Commands that do not create jumps:
  • h, j, k, l — Basic movement
  • w, b, e — Word movement
  • 0, $, ^ — Line movement
Use g; and g, to navigate the change list instead of the jump list!

Change Lists

Change List Navigation

Vim remembers positions where you made changes:
g;              " Go to older change position
g,              " Go to newer change position
:changes        " List change positions
Example output:
change line  col text
    3     9    8 modified line 1
    2    11   57 modified line 2  
    1    14   54 modified line 3
>
  • Maximum 100 entries per buffer
  • Same limit as jump list
  • Changes close together are merged (within ‘textwidth’ distance)
  • Only actual changes count (not just cursor movement)
  • Persists across undo/redo

Practical Uses

Mark Usage Patterns

" Mark important locations
mf              " Mark function definition
mc              " Mark caller
mt              " Mark test

" Jump between them
'f              " Go to function
'c              " Go to caller
't              " Go to test
" In main.lua
mM              " Mark Main file

" In config.lua
mC              " Mark Config file

" In utils.lua
mU              " Mark Utils file

" Jump between files
'M              " Go to main.lua
'C              " Go to config.lua
'U              " Go to utils.lua
" Before exploring
mm              " Mark current position

" Explore code...
/some_function<CR>
gd              " Go to definition
CTRL-O          " Go back

" Return to mark
'm              " Jump back to mark m

Combining with Operators

Marks work with operators:
" Delete from here to mark a
d'a

" Yank from mark a to mark b  
y'a'b

" Change from here to mark t
c't

" Format from mark s to mark e
='s'e

Visual Selection with Marks

" Select from mark a to mark b
v'a'b

" Select from here to mark end
v'e

" Linewise select to mark
V'a

Advanced Techniques

Restore Position After Operation

" Save position
ma

" Do operations
:%s/old/new/g

" Restore position
'a
" Mark sections
gg              " Top of file
mt              " Mark top

50%             " Middle
mm              " Mark middle

G               " Bottom
mb              " Mark bottom

" Quick navigation
't              " Go to top
'm              " Go to middle
'b              " Go to bottom

Mark Multiple Locations for Reference

" While reading code
ma              " Mark interesting function
" Keep reading...
mb              " Mark another function
" Keep reading...
mc              " Mark another

" Review marked locations
'a              " Check first
'b              " Check second
'c              " Check third

Jump Patterns

Exploring Code

" Jump to definition
gd

" Look around
/related_function<CR>

" Go back through history
CTRL-O
CTRL-O

" Go forward
CTRL-I

Browsing Changes

" Make some changes in different locations
" ...

" Review changes
g;              " Go to previous change
g;              " And the one before
g,              " Go back forward

Search and Return

" Current position is remembered
/search_term<CR>

" Explore results
n
n
n

" Return to where you started
''              " Jump back

Configuration

" Jump options
set jumpoptions=stack       " Use stack-based jumplist

" ShaDa settings (save marks)
set shada='100,<50,s10,h
"         |    |   |   |
"         |    |   |   +-- no hlsearch on startup
"         |    |   +------ max 10KB per register
"         |    +---------- max 50 lines per register  
"         +--------------- remember marks for 100 files

" Show marks in sign column (with plugin)
" Plugin: vim-signature or similar

" Convenient mark mappings
nnoremap <Leader>m :marks<CR>
nnoremap <Leader>j :jumps<CR>
nnoremap <Leader>c :changes<CR>

Tips and Tricks

Remember last position: Add to your config to restore cursor position:
vim.api.nvim_create_autocmd('BufReadPost', {
  callback = function()
    local mark = vim.api.nvim_buf_get_mark(0, '"')
    if mark[1] > 0 and mark[1] <= vim.api.nvim_buf_line_count(0) then
      vim.api.nvim_win_set_cursor(0, mark)
    end
  end,
})
  1. Use lowercase for local navigation (within file)
  2. Use uppercase for file bookmarks (between files)
  3. Use mnemonic letters:
    • mt = top, mb = bottom
    • mf = function, mc = class
    • md = definition, mr = reference
  4. Don’t overuse marks — jump list and change list often suffice
  5. Clear old marks with :delmarks periodically
  1. Use search (/) to explore code
  2. Jump to definitions with gd or CTRL-]
  3. Return with CTRL-O (not '' unless you want to add to jumplist)
  4. Use :jumps when lost in navigation
  5. Clear jumplist with :clearjumps when starting new task

Build docs developers (and LLMs) love