What's the syntax for optional tokens in an 'errorformat'?


Using Visual Studio, I have a compiler/msvc.vim setup like this:

CompilerSet errorformat&
CompilerSet errorformat^=%f(%l):\ %trror\ C%n:\ %m

It successfully captures errors like this (including capturing the error number):

c:\proj\stuff.cpp(71): error C2660: 'Stuff::Tick': function does not take 1 arguments

However, when I build a project with parallel project compilation enabled, I get output prefixed with a number and > (to identify each project's output):

1>c:\proj\stuff.cpp(71): error C2660: 'Stuff::Tick': function does not take 1 arguments
2>c:\proj\heavy\grill.cpp(71): error C2660: 'Grill::Tick': function does not take 1 arguments

I can change my errorformat to match the 1>:

CompilerSet errorformat^=%*\\d>%f(%l):\ %trror\ C%n:\ %m

How do I modify my errorformat to merge these two lines? How do I do the equivalent of a capture ^\(\d>\)\?

:help efm-ignore mentions:

Important note: The (...) grouping of sub-matches can not be used in format specifications because it is reserved for internal conversions.

Does that mean the only way is to include lines with and without the 1> matching pattern (all above lines) in my compiler script?

How to ignore beginning of line in errorformat doesn't answer my question because it's for discarding preamble that's always there.

  • I found that the build log file doesn't include the 1> characters. :cgetfile c:\proj\obj\x64\debug\proj\proj.log is a better solution than pasting from Visual Studio's Output Window for my example problem, but I'd still like to know if there's an answer.
    – idbrii
    Commented Sep 30, 2023 at 14:02
  • The syntax for optional items would just be %\\?, I think, but the lack of grouping is a problem. Fortunately, there's really nothing wrong with multiple entries… You could also :help errorformat and /^Filtering messages: set makeprg to filter the numbers out?
    – D. Ben Knoble
    Commented Sep 30, 2023 at 17:55


Your Answer

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

Browse other questions tagged or ask your own question.