Step 1 of 5

15. The Changelist Jumplist And Tag Stack

Vim’s built-in lists

We’ve already seen how we can use marks to save locations that we might want to return to later. We’ve also seen how Vim automatically sets some marks for us, like the position of the last edit. Marks have some limitations, though:

  • manually set marks have to be, well, manually set
  • automatically set marks only allow you to step back one level — for example, the ". mark (which keeps track of where the last change was made) only keeps track of the very last change, so if you wanted to go to the second to last change, you’re out of luck
  • automatically set marks don’t work across files — so you can’t use "' to jump back to the previous position in another file

Fret not, though — Vim has some more robust tools for navigating called the changelist, jumplist, and tag stack. At a glance, these are like ‘marks on steroids’.

In this lesson, we’re going to explore each of these in order. We’ll take a look at what they are first, then we’ll learn how to use them. Generally speaking, these tools are more useful than marks for most situations primarily because they are automatic. You don’t have to worry about managing them yourself.

To kick us off, let’s understand where Vim’s marking system breaks down. The checklist below has you make a change on each of three lines, then use '. — the command that jumps to the ". mark — to try to get back to them. You’ll find that '. only ever takes you to where the most recent change took place. You can’t go any further back!

This is a good illustration of the limits of marks, and this is where the changelist, jumplist, and tag stack come in handy.

  1. Make a change on line 1 The cursor starts there — press x to delete a character.
  2. Make a change on line 11 Jump down with 11G, then press x again.
  3. Make a change on line 21 21G to get there, then x one more time.
  4. Jump back to the top With all three changes made, put them behind you — type gg.
  5. Jump to the last change with '. Apostrophe, then a dot — Vim takes you straight to the newest change, on line 21.
  6. Press '. again You stay on line 21 — the two earlier changes are out of reach. That's the limit we came to see.
Make a change on line 1 The cursor starts there — press x to delete a character.

Next: Make a change on line 11

Loading editor…