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.