3

I have completely clean vimrc, no plugins, and the following test file:

foo bar baz baz baz baz baz baz
baz baz

Now, I press / to start search, then type baz, press Enter, press n twice. It will move me to the beginning of 3rd baz. Then I press Ctrl+O and it will move me to the beginning of 2nd baz. But then, if I try to press Ctrl+I, nothing happens!

Why is jumplist not being updated properly with each search?

  • 1
    This is a nice question. I think jumps are only stored in the jump list if they are on different lines. I know jumplist store column position too, but that is only for moving the cursor to previous position. Of course this is my speculation. I'll get back after reading the manual. – klaus Mar 4 at 10:00
3

From :h jump-motions

8. Jumps                    *jump-motions*

A "jump" is a command that normally moves the cursor several lines away.  If
you make the cursor "jump" the position of the cursor before the jump is
remembered.  You can return to that position with the "''" and "``" command,
unless the line containing that position was changed or deleted.  The
following commands are "jump" commands: "'", "`", "G", "/", "?", "n", "N",
"%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and the
commands that start editing a new file. 

Here, the important part is, A "jump" is a command that normally moves the cursor several lines away. Even though n and N are jump-motions, i.e. invoking these keys will edit jumplist, if the next/previous search result is on the same line as the cursor was on prior to invoking the key, the jump-cursor is simply moved down to a new line effectively stating that you're currently on a line not listed in the jumplist. This is the case no matter where the jump-cursor was previously on. For example, if the jumplist is in following state.

The following is the text of test case:

foo bar baz baz baz baz baz baz
baz baz
foo bar baz baz baz baz baz baz
foo bar baz baz baz baz baz baz
foo bar baz baz baz baz baz baz

Following is output of :jumps:

 jump line  col file/text
   1     2    0 baz baz
>  0     1    8 foo bar baz baz baz baz baz baz
   1     3   12 foo bar baz baz baz baz baz baz

Now, if you use n or N, so that the cursor goes to next or previous search result but stays in same line, the jumplist will be edited to be in the following state:

 jump line  col file/text
   3     2    0 baz baz
   2     3   12 foo bar baz baz baz baz baz baz
   1     1    0 foo bar baz baz baz baz baz baz
>

Now, if you do Ctrl-I, nothing will happen; if you do Ctrl-O, you'll move back in jumplist. I don't know if there is a reasoning behind this, but it is what seems to be happening.

  • I haven't looked into the source code. This answer is simply observational statement. – klaus Mar 4 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.