vimerrorformat

Vim errorformat multiple entries


The c++ compiler Im using (kicked off by ant) produces errors in different formats. For example:

[apply] /localdev/foo.cc:10:29: error: foo.h: No such file or directory

(lets call that Format A)

and in formats such as:

[apply] /localdev/foo.cc:307: error: expected ';' before 'std'

(lets call that Format B)
Note Format A has an additional column specifier.
I am trying to create a vim errorformat that will match both.
I have:

set errorformat=\ %#[apply]\ %f:%l:%c:\ error:\ %m
set errorformat+=\ %#[apply]\ %f:%l:\ error:\ %m

But I can't seem to get Vim to match Format B with that.
I know the errorformat itself is correct because if I comment out the first errorformat setting, I can match error Format B. and if I comment out the second errorformat setting, I can match error Format A.
Note that if I reverse the errorformat settings, then when Vim encounters error Format A, it trys to open a file called "/localdev/foo.cc:10", which of course is not found. (looks like vim has a greedy matching algorithm and the string that is matching the file is also including the line number in this case).

What is the proper errorformat setting that will match both Format A and Format B?
I have looked on the internet and vim documentation for ways to make the %c "optional", but I have not found the secret.
thank you.


Solution

  • You can do it like this:

    let &errorformat =
        \ '%\s%#[apply] %f:%l:%c: %trror: %m,' .
        \ '%\s%#[apply] %f:%l: %trror: %m'