vimtricks.wiki Concise Vim tricks, one at a time.

How do I jump forward and backward through all marks in the current buffer?

Answer

]' and ['

Explanation

The ]' and [' motions let you traverse every lowercase mark set in the current buffer without needing to remember which registers you used. This is especially useful when you have scattered multiple marks during a long editing session and want to revisit them all systematically.

How it works

  • ]' — jump to the first line below the cursor that has a mark set
  • [' — jump to the first line above the cursor that has a mark set

Both motions move to the beginning of the line where the mark sits. If you prefer to land on the exact character position of each mark (not just the line start), use the backtick variants:

  • ]` — jump to the next mark's exact position
  • [` — jump to the previous mark's exact position

All four motions work with any lowercase mark (az) that has been set with m{letter}.

Example

Suppose you have marked several spots in a file:

1  func doSetup() {     ← mark a (ma)
2    initDB()
3    loadConfig()
4  }
5
6  func doTeardown() {  ← mark b (mb)
7    closeDB()
8  }
9
10 func main() {        ← mark c (mc)
11   doSetup()
12   doTeardown()
13 }

With the cursor anywhere on line 5, pressing ]' jumps to line 6 (mark b). Pressing ]' again jumps to line 10 (mark c). Pressing [' takes you back to line 6.

Tips

  • Use :marks to list all currently set marks and their positions
  • These motions also work as operators: d]' deletes from the cursor to the next mark's line
  • The uppercase ]' / [' form only recognizes marks az; global marks (AZ) require jumping by name with 'A

Next

How do I programmatically read and write Vim register contents including their type from Vimscript?