3

I use gf to open "filename.h" from line like:

#include "filename.h"

in some C\C++ file.

Sometimes there is more than one "filename.h" that gf command can find in path. But gf gets me to the first file it finds - sometimes that's not what I want.

Is there a way to open the next file matching that name?

3
  • 3
    gf accepts a count, so you can try 2gf. Is that what you want?
    – muru
    Commented Apr 19, 2017 at 8:49
  • Didn't expect that - but it works. Any idea if it's possible to cycle through the results? Commented Apr 19, 2017 at 10:53
  • @muru please add your comment as an answer so I can mark it as the correct response. Don't think there is anything better out of the box. Commented Apr 20, 2017 at 10:22

1 Answer 1

3

From :h gf:

                                                       gf E446 E447
[count]gf               Edit the file whose name is under or after the cursor.
 ...
                        If a [count] is given, the count'th file that is found
                        in the 'path' is edited.

So you can do 2gf.

To browse the list of matches is trickier. The only way I found was to use use :find and Vim's command-line tab completion:

:find <cfile>Tab

Vim will cycle through matches and <cfile>:

enter image description here

2
  • 1
    Shouldn't that be <cfile>? <cfile> is replaced with the path name under the cursor (like what gf uses)
    – Shahbaz
    Commented Apr 21, 2017 at 2:08
  • @Shahbaz indeed, corrected.
    – muru
    Commented Apr 21, 2017 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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