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. We’re going to try this in the editor. Make a few edits on each of the lines, then try using the '. command in normal mode to jump to the ". mark (which keeps track of the last edit). You’ll notice that the '. command will only ever take 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.