I use gF a good amount when getting to the bottom of compilation errors in different tech stacks. With Dart/Flutter, I'm getting the error messages in the following format:

lib/main.dart:58:34: Error: 'FooStates' isn't a type.
Try again after fixing the above error(s).

placing the cursor on the path and running gF results in a E447: Cannot find file "lib/main.dart:58:34" in path error, which is to be expected. The help says:

[count]gF       Same as "gf", except if a number follows the file
            name, then the cursor is positioned on that line in
            the file.
            The file name and the number must be separated by a
            non-filename (see 'isfname') and non-numeric
            character. " line " is also recognized, like it is
            used in the output of `:verbose command UserCmd`
            White space between the filename, the separator and
            the number are ignored.
                eval.c:10 ~
                eval.c @ 20 ~
                eval.c (30) ~
                eval.c 40 ~

From what I can understand I can add a "filter" to the strings passed to gF, so that when no file is matched, a substitution is performed and the modified string is matched again against the files in the workspace.

I can't seem to get the correct invocation for it though. Here's what I tried:

autocmd FileType log setlocal includeexpr=substitute(v:fname, ':\\d+$', '', '')

This spits out the following error when trying to open a log type buffer:

Error detected while processing BufEnter Autocommands for "__FLUTTER_DEV_LOG__":                                                                                                                                                                                                                 
E5108: Error executing lua ...vim/plugged/flutter-tools.nvim/lua/flutter-tools/log.lua:104: Vim(setlocal):E518: Unknown option: ':\\d+$', 

When I skip the per-filetype logic and add something like this to init.vim:

:set includeexpr=smagic(v:fname,':[0-9]+$','','g')

it just doesn't seem to have any effect on gF - the file.ext:line:column format is still not recognized

  • 1
    The Unknown option: ':\\d+$', part is because you can't have spaces in a :set or :setlocal command. If you need spaces in the value of an option, you need to backslash escape them. (This gets very tricky in an autocmd, so I won't even try to guess what the right syntax for it would be.)
    – filbranden
    Dec 16 '21 at 13:26
  • Using let &l:includeexpr = … is thus much nicer, but you may have two levels of strings :)
    – D. Ben Knoble
    Dec 16 '21 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.