user809409
user809409

Reputation: 511

Jumping to a file that is listed in Vim

In Vim you can use the [I command to list all of the locations where a specified function, class or struct is declared or used. Is there a simple shortcut to open one of the files in this resulting list in Vim? I'd prefer not to have to type in the full filename and line number.

Upvotes: 8

Views: 227

Answers (3)

romainl
romainl

Reputation: 196886

It's not very ergonomic, but after closing the list <C-w>i opens a new window with the cursor positioned on the first instance of the word.

Adding a count like 3<C-w>i opens a new window with the cursor positioned on the third instance of the word.

Upvotes: 0

Timothy Jones
Timothy Jones

Reputation: 22165

I use ctags in vim, which lets me use C-] to jump to a function/struct/whatever definition. You can use these simple steps to set it up, and once you have, this question has a bunch of useful shortcuts listed.

Actually, that question I just mentioned has a whole lot of tips which you might find useful (not just ctags related).

Upvotes: 0

Stephane Gosselin
Stephane Gosselin

Reputation: 9148

I remembered the old gF trick, that works great.

Shameless rip from vim tips:

The following commands open the file with the cursor on the specified line number:

gF   open in the same window
<c-w>F   open in a new window (Ctrl-w F)
<c-w>gF  open in a new tab (Ctrl-w gF)

When such file-name/line number pairs are the result of compiling code, the following commands are also useful:

:help :cn
:help :cl
:help :cfile

The file:line plugin allows you to use combinations of file name and line number, like global.h:123, as an argument to Vim. When you open file:line, the script checks if file exists and line is a number. If so, Vim opens file at the correct line line number.

Upvotes: 5

Related Questions