Nvim Session 05: Marks & Jump Lists

Set bookmarks anywhere, jump back to where you were, navigate your edit history. Never lose your place in a large file.

Pre-Session State

  • Comfortable navigating files

  • Know basic search

  • Use marks for bookmarks

  • Navigate jump/change lists

Lesson 1: Marks - Manual Bookmarks

Concept: Set named positions you can return to instantly.

Exercise 1.1: Setting local marks

ma       " Set mark 'a' at current position
mb       " Set mark 'b'
mc       " Set mark 'c'

Lowercase marks (a-z) are local to the buffer.

Exercise 1.2: Jumping to marks

'a       " Jump to line of mark 'a' (first non-blank)
`a       " Jump to exact position of mark 'a'

Difference: - 'a (single quote) = line - `a (backtick) = exact column

Exercise 1.3: Global marks

mA       " Set GLOBAL mark 'A' (works across files)
mH       " Set global mark for "hosts" file
mV       " Set global mark for "vault" config

Jump from anywhere:

'H       " Jump to hosts file, to marked line
`V       " Jump to vault config, exact position

Exercise 1.4: Viewing marks

:marks       " Show all marks
:marks aBC   " Show specific marks

Exercise 1.5: Deleting marks

:delmarks a      " Delete mark 'a'
:delmarks a-d    " Delete marks a through d
:delmarks!       " Delete all lowercase marks

Lesson 2: Automatic Marks

Concept: Vim sets marks automatically. Learn them!

Exercise 2.1: Last positions

''       " Last jump position (line)
``       " Last jump position (exact)

After any jump (gg, G, /search, etc.):

``       " Go back to where you were
``       " Toggle back and forth

Exercise 2.2: Edit positions

'.       " Last change position (line)
`.       " Last change position (exact)
'^       " Last insert position
`[       " Start of last change/yank
`]       " End of last change/yank

Exercise 2.3: Visual selection marks

After visual selection:

'<       " Start of last visual
'>       " End of last visual

Reselect last visual:

gv       " Reselect last visual selection

Exercise 2.4: Special file marks

'"       " Position when last exited buffer
'0       " Position in last edited file (across sessions!)
'1-'9    " Previous files from shada/viminfo

Reopen file at last position:

'" (then use :e#)

Lesson 3: Jump List

Concept: Vim tracks everywhere you’ve jumped. Navigate it.

Exercise 3.1: Jump list navigation

Ctrl-o   " Go to OLDER position in jump list
Ctrl-i   " Go to NEWER position in jump list

Mental model: Ctrl-o = "go OUT/back", Ctrl-i = "go IN/forward"

Exercise 3.2: What counts as a jump?

Jumps that add to the list: - gg, G, {n}G (go to line) - /search, ?search, n, N - 'mark, mark - `{, } (paragraph) - % (matching bracket) - [[, ]] (sections) - :e file (open file)

NOT jumps (small motions): - h j k l - w b e - f t ; ,

Exercise 3.3: View jump list

:jumps   " Show jump list

Output:

 jump line  col file/text
   4    10    0 some_file.lua
   3   145   15 another_file.py
   2    32    8 config.yaml
   1    88    0 current position
>  0    50   10 <<< you are here

Exercise 3.4: Practical jump workflow

Edit workflow:

gg           " Jump to top
/function    " Search for function
n            " Next match
" ... make some edits ...
Ctrl-o       " Back to search match
Ctrl-o       " Back to gg position
Ctrl-i       " Forward to search match

Lesson 4: Change List

Concept: Navigate where you’ve made changes.

Exercise 4.1: Change list navigation

g;       " Go to OLDER change position
g,       " Go to NEWER change position

Exercise 4.2: View change list

:changes

Output:

change line  col text
    3    45   12 hostname = "old"
    2    67    5 port = 8080
    1    89    0 enabled = true
>   0   100   15 <<< you are here

Exercise 4.3: Jump to last edit and continue

gi       " Go to last insert position AND enter insert mode

Power move: You were typing, did something else, want to continue:

gi       " Back to insert mode at exact position

Lesson 5: Practical Mark Patterns

Exercise 5.1: Mark while reading

Reading a long file:

mT       " Mark "TODO" section
mI       " Mark "Implementation" section
mE       " Mark "Examples" section

Navigate:

'T       " Jump to TODO
'I       " Jump to Implementation
'E       " Jump to Examples

Exercise 5.2: Mark for editing context

Before making changes:

mm       " Mark current position ("m" for "me")
" ... navigate away, look at other code ...
'm       " Return to where you were working

Exercise 5.3: Global marks for projects

mC       " Mark main Config file
mM       " Mark Main entry point
mT       " Mark Test file
mD       " Mark Documentation

From any file:

'C       " Jump to config
'M       " Jump to main

Exercise 5.4: Using marks with operators

Delete from mark to current position:

ma       " Set mark at start
" move down
d'a      " Delete from current line back to mark 'a'

Yank between marks:

ma       " Mark start
" move to end
mb       " Mark end
'a       " Go back to start
y'b      " Yank from here to mark 'b'

Summary: Marks Reference

Command Effect

m{a-z}

Set local mark

m{A-Z}

Set global mark

'{mark}

Jump to mark line

`{mark}

Jump to mark exact position

''

Last jump position (line)

` `

Last jump position (exact)

'.

Last change position

'^

Last insert position

:marks

Show all marks

:delmarks a

Delete mark

Jump/Change List Reference

Command Effect

Ctrl-o

Older jump position

Ctrl-i

Newer jump position

:jumps

Show jump list

g;

Older change position

g,

Newer change position

:changes

Show change list

gi

Insert at last insert position

gv

Reselect last visual

Mark Naming Conventions

Mark Suggested Use

mm

"Me" - current working position

mT

Top/Todo section

mB

Bottom/Build section

mF

Function I’m editing

mC

Config file (global)

mM

Main file (global)

mH

Hosts/HTTP file (global)

Exercises to Complete

  1. [ ] Set marks a, b, c at different positions, jump between them

  2. [ ] Use ` vs ' - feel the column difference

  3. [ ] Make jumps with gg, /search, use Ctrl-o to go back

  4. [ ] Make some edits, navigate with g; and g,

  5. [ ] Set a global mark, open another file, jump back

Next Session

Session 06: Registers Deep Dive - The real clipboard system.

Session Log

Timestamp Notes

Start

<Record when you started>

End

<Record when you finished>

Discoveries

<What surprised you?>