The Vim jump list
Summary
The Vim jump list helps you move efficiently between recently visited locations in a file. Use Ctrl-o
to go back and Ctrl-i
to go forward through these locations. It differs from the change list, which tracks edits instead of movement.
Introduction #
One of its most useful but often overlooked features of Vim is the jump list. The jump list helps you navigate between previously visited locations within your editing session.
What is the jump list in Vim? #
The jump list in Vim is an internal mechanism that tracks cursor positions where you have jumped during your session.
This feature is especially helpful when editing complex documents or navigating through source code. Instead of manually retracing your steps, you can quickly move backward and forward through your navigation history.
How the jump list works #
A jump is typically defined as a movement of the cursor that changes its position significantly, such as:
- Using the
/
or?
commands to search within the file. - Using
G
,gg
, or line numbers to jump to different lines. - Jumping to a mark using
'a
,'b
, and so on. - Switching between files with
:e
or:b
.
Each of these actions is recorded in the jump list, creating a trail of locations you can return to.
Vim stores the jump list per window. This means if you split your window using :split
or :vsplit
, each window maintains its own jump list. This design provides localized history tracking, allowing for independent navigation within each view.
The jump list has a finite size (default is 100 entries), and it automatically updates as you continue working. When you reach the limit, older entries are discarded to make room for new ones.
Viewing the jump list #
To view your current jump list, you can use the following command:
:jumps
This displays a numbered list of jump locations along with the file name and line number. The current position in the list is marked with a >
character. Each entry shows enough information to understand where you have been and where you might want to return.
Navigating the jump list #
You can navigate through the jump list using the following key combinations in normal mode:
- Press
Ctrl-o
to move backward through the jump list. - Press
Ctrl-i
to move forward through the jump list.
Here is a basic example:
/keyword
gg
Ctrl-o " takes you back to the line you searched for
Ctrl-o " takes you back to where you started
Ctrl-i " moves forward again in the list
This makes it easy to explore a document or project and return to previous points of interest without losing your place.
Pressing Ctrl-i
might behave differently in some terminal emulators, especially those that interpret it as the <Tab>
key. In such cases, consider remapping the key or using graphical Vim variants like GVim.
Difference between jump list and change list #
While both the jump list and change list are used to keep track of cursor positions, they serve different purposes:
- The jump list keeps track of cursor movements to different locations.
- The change list keeps track of edits or changes made to the text.
To navigate the change list, you use:
g;
to go to the previous change.g,
to go to the next change.
If you are editing a file and want to revisit places where you made changes, use the change list. If you want to revisit locations you navigated to, use the jump list.
FAQ's #
Most common questions and brief, easy-to-understand answers on the topic:
What is the Vim jump list used for?
The Vim jump list tracks locations in a file where the cursor has been, allowing you to jump backward and forward between them efficiently.
How do I view the jump list in Vim?
You can view the jump list by typing :jumps
in command mode, which displays a list of recent cursor positions.
What is the difference between a jump list and a change list in Vim?
The jump list tracks cursor movements, while the change list tracks edits you have made to the text.
Can I clear the jump list in Vim?
There is no built-in command to clear the jump list directly, but you can start a new session or use a plugin that resets it.
What Vim commands allow navigation through the jump list?
Use Ctrl-o
to move backward in the jump list and Ctrl-i
to move forward.
Further readings #
Sources and recommended, further resources on the topic:
License
The Vim jump list by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/vim-jump-list">The Vim jump list</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>
For more information see the Ditig legal page.