0

A common action I perform in Vim is to do $ grep or $ git grep (in a vim :terminal), and then open the files discovered.

This works great most of the time. However, I noticed that considering the following output from grep/git grep:

my-file:    some code
my-file:// my comments
my-file:/ test
my-file:/// test

The first line will work properly with Vim gf and the like, so we know that vim is ignoring the colon as expected.Similarly, the third line also works.

However, the second and fourth line don't work, with vim reporting E447: Can't find file "my-file://" in path.

It seems that with two or more slashes after the colon, gf no longer works as expected. This suggests that Vim is parsing the text as a URL? I don't think I have ever or will ever find a use for URLs and gf.

My isfname does not contain the : character.

What is causing Vim to behave unexpectedly for gf, and how do I make it behave the way I expect it to?

7
  • Could you tell us what is the value returned by :set includeexpr? and by: :set ft?? Dec 26, 2023 at 7:27
  • 1
    @VivianDeSmedt :set includeexpr? gives an empty includeexpr=. As mentioned, I call this from the vim terminal, which likewise gives for :set ft? an empty value filetype=. Dec 26, 2023 at 7:31
  • 1
    Thanks for the feedback. I'll try to reproduce the problem at my end. Dec 26, 2023 at 7:32
  • 1
    I can reproduce the problem on my end :-) Dec 26, 2023 at 7:59
  • 1
    FWIW, using Vim's :help :grepin combination with :help quickfix seems more efficient than your current strategy.
    – romainl
    Dec 26, 2023 at 8:37

1 Answer 1

1

You can solve the problem by setting the includeexpr option to the following value:

set includeexpr=substitute(v:fname,'\\(^[^:]*\\).*','\\1','')

But the mystery about why this is needed in case : is not part of isfname remains.

1
  • 1
    I discovered that this fixes CTRL-W_f but apparently doesn't fix gf... Jan 18 at 15:08

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.