6

I have several files that prefix file names with a character, for example

In →path/to/some/file, there is
a foo, in →path/to/other/file, there
is a bar. etc.

When the cursor is over such a path, I'd like to use gf to go the this file.

gf uses isfname to determine which characters belong to the file. Unfortunatly, help isfname explicitely states

Multi-byte characters 256 and above are always included, only the characters up to 255 are specified with this option.

Is there another way to exclude from the characters recognized as file name characters?

1 Answer 1

8

:h gf says:

If the file can't be found, 'includeexpr' is used to
modify the name and another attempt is done.

And for :h includeexpr:

                                                'includeexpr' 'inex'
'includeexpr' 'inex'    string  (default "")
                        local to buffer
                        {not in Vi}
                        {not available when compiled without the
                        +find_in_path or +eval features}
        Expression to be used to transform the string found with the 'include'
        option to a file name.  Mostly useful to change "." to "/" for Java: 
                :set includeexpr=substitute(v:fname,'\\.','/','g')
       The "v:fname" variable will be set to the file name that was detected.

        Also used for the gf command if an unmodified file name can't be
        found.  Allows doing "gf" on the name after an 'include' statement.
        Also used for <cfile>.

So, you could try something like:

:set includeexpr=substitute(v:fname,'^→','','')

Your Answer

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

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