Vim is no doubt one of the most feature rich command line editors. But that also means it's difficult to remember all the features it offers. Here at FAQForge, we have already discussed some really useful Vim features, with the latest tutorial focusing on opening multiple files using a single command.

In this article, we will discuss another small but useful Vim functionality: ability to jump to recently visited locations. Please note that all commands/instructions mentioned here have been tested on Ubuntu 16.04 system running Vim 7.4.

How to easily hop around in a file?

Whether you're working on a software project, or working on a series of articles/stories. There may be situations where-in you make some changes at certain places, and then would want to revisit those places for whatever reason. Vim makes this super easy for you.

Here's an excerpt from the official Vim documentation: "Vim remembers the locations you have recently visited (where you jumped from). Each position (file name, column number, line number) is recorded in a jump list, and each window has a separate jump list that records the last 100 positions where a jump occurred."

So now suppose, you are editing a file, and you want to jump back to your previous location, all you have to do is to press Ctrl+o. Similarly, to jump forward, press Ctrl+l. Please note that this jump list that Vim maintains is only updated within edits - you need to save the file in order to register a location in jump list.

The beauty of these controls is that they work across files. So if you are continuously pressing Ctrl+o in a Vim window, and the editor is done with showing all previous locations for a file, then other files that you previously edited will show up one by one.

To display the jump list for the current window, run the following command:

jumps

Here's the above command in action:

vim-jump-list

For more information related to this feature, head here.

How to jump to recently visited locations in Vim

Leave a Reply

Your email address will not be published. Required fields are marked *

*