Step 3 of 5

15. The Changelist Jumplist And Tag Stack

The jumplist

From looking at the changelist, we now understand the basic concept we’re working with here. Vim is keeping track of a list of locations, and there are maps to move back and forth between them.

The changelist is very useful, but most of the time we’re reading documents rather than editing them. For example: programmers often need to jump around various files, following a sequence of function calls, to understand how the code is working. In situations like these, we’re not editing anything, so the changelist isn’t applicable.

Thankfully, Vim has another useful list called the jumplist. The jumplist is all about jumps, which are anything that moves your cursor a “significant distance”. For example, moving one line upward with k isn’t a jump, but moving ten lines up with 10k is. The jumplist keeps track of the positions you were in before you made a jump, giving us an easy way to return to where we were before.

To use the jumplist, it’s <C-o> to jump one position back and <C-i> to jump one position forward.

One caveat for the embedded editor: on some platforms the browser reserves Ctrl-O for itself, so the chord never reaches Vim. If that happens to you, hand the job to a key the browser leaves alone — :nnoremap <BS> <C-o> makes Backspace jump back. (Going forward is easier: to Vim, <Tab> and <C-i> are literally the same key, so Tab already does it.)

The checklist below has you seed the jumplist with three G jumps, then ride <C-o> and <C-i> back and forward along the trail you left.

  1. Jump to line 10 Type 10G — a jump like this is exactly what the jumplist records.
  2. Jump to line 20 20G — another entry for the jumplist.
  3. Jump to line 30 30G — one more.
  4. Jump back with Ctrl-o You'll return to line 20, where you were before the last jump — hold Ctrl and press o once. (Browser stole the chord? Remap per the note below.)
  5. Go back once more This time you'll land on line 10 — press Ctrl-o again.
  6. Come forward again with Ctrl-i Hold Ctrl and press i — forward through the jumplist, back to line 20.
Jump to line 10 Type 10G — a jump like this is exactly what the jumplist records.

Next: Jump to line 20

Loading editor…