0

When pressing [I VIM shows a list of lines which match the word under the cursor. For instance, if the cursor is on the word Table and one presses [I the following is shown:

  1:   49 class Table(object):
  2:  220         new_table = Table(t, records)
  3:  241         tables.append(Table(row[0], row[1],))
  4:  392         tables.append(Table(t, records))
Press ENTER or type command to continue

How can one easily select an option from the list, i.e. jump to one of the lines? I have tried Tab, Ctrl-N, Ctrl-P, j, the arrow keys, and entering 1, 2, and so on. None of these work. I know that I could simply type the line number and then gg to jump to the line in question, but I would like to know if VIM has another trick up its sleeve.

2

The following vim mapping should do what you want (mapping is based on my memory word for this mapping: fast-search):

nmap <leader>fs [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR>

The above command first lists the lines matching the word under the cursor from the beginning of the file, and then asks you which match you want to jump to, and finally, jumps to that match.

If you prefer to lists lines beginning from the word under the cursor, as opposed to the beginning of the file, you can use:

nmap <leader>fs ]I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."]\t"<CR>

Note that the square brackets are inverted in the later command.

0
1

That list is not interactive, you are supposed to do the following to jump to the 2nd match:

:220<CR>
2
  • not necessarily. vim magically always has some way to do what you want it to do. – Stoic Dec 25 '13 at 9:49
  • What is "not necessarily"? – romainl Dec 25 '13 at 17:10

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.