Traversing Neovim's Jump List

We saw in the previous section how the jump list records each jump that we make, and how we can review current jump using the :jumps command. In this section we will look at how to traverse the jump list to easily navigate back to previous locations in our project.

Neovim provides two commands for traversing the jump list, forwards and backwards, respectively:

CommandAction
C-OJump one step backward within jump list
C-Isame as <Tab>

Let's see how these work. For reference, here is the most recent jump and the current state of the jump list:

The most-recent Jump
N
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
50%
5:5
 
Current Jump List
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
50%
5:5
 
:jumps
 jump line  col file/text
   5     1    0 <!DOCTYPE html>
   4     3    0 <html lang="en">
   3     5    4 <head>
   2     7    8 <title>Title</title>
   1     6    8 <meta charset="utf-8">
>

Our most recent jump was from the <meta> tag to the <head> tag, so let's hit C-O to traverse backwards one step, returning to the <meta> tag, then check the jump list:

Traverse one step back
<C-o>
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
60%
6:9
 
View the Jump List
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
60%
6:9
 
:jumps
 jump line  col file/text
   3     1    0 <!DOCTYPE html>
   2     3    0 <html lang="en">
   1     7    8 <title>Title</title>
>  0     6    8 <meta charset="utf-8">
   1     5    4 <head>

Comparing the new jump list to that in step 12, we can see a few interesting things. First, as before the line we just jumped from now appears at the top of the list. However, two things are different: First, the > marker has moved up one step, and now has the number 0 next to it. Second, the numbers assigned to each jump count the number of steps away from step 0.

Note

This is actually how the jump numbers have been computed all along. However, since (up to now) we have always been at the top of the jump list, we only saw one half of the counts.

Let's see how to use the jump numbers. Like many commands, C-I and C-O accept counts, allowing us to quickly jump directly to a specific location while traversing the jump list list. To jump directly to a specific jump in the list, simply prefix the appropriate command with the jump number. For example, to jump directly to the <html> tag we simply check the jump list to see that this location is currently numbered 2, then execute 2C-O:

Traverse back two Steps
2<C-o>
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
30%
3:1
 
View the Jump List
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
30%
3:1
 
:jumps
 jump line  col file/text
   1     1    0 <!DOCTYPE html>
>  0     3    0 <html lang="en">
   1     7    8 <title>Title</title>
   2     6    8 <meta charset="utf-8">
   3     5    4 <head>

As expected we have jumped back to the desired location. After making a few edits we can quickly return to our original location (the <meta> tag) by hitting 2C-I, then continue editing:

Traverse forward two Steps
2<C-i>
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
60%
6:9
 
View the Jump List
<!DOCTYPE·html>
 
<html·lang="en">
 
····<head>
········<meta·charset="utf-8">
········<title>Title</title>
········<meta·name="description"·content="Description">
········<meta·name="author"·content="Author">
NORMAL
60%
6:9
 
:jumps
 jump line  col file/text
   3     1    0 <!DOCTYPE html>
   2     3    0 <html lang="en">
   1     7    8 <title>Title</title>
>  0     6    8 <meta charset="utf-8">
   1     5    4 <head>

Finally, from time to time one might want to clear the jump list and start fresh. This can be achieved using the :clearjumps command.

Now that we have seen how the jump list is created and organized, as well as how to traverse it, there is the final topic to discuss: what does Neovim consider to be a jump?