I tried reading :help errorformat
and googling (mostly stackoverflow), but can't understand some of the patterns mentioned there:
%s
- "specifies the text to search for to locate the error line. [...]"- um, first of all, trying to understand the sentence at all, where do I put the "text to search", after the
%s
? before it? or, I don't know, does it maybe taint the whole pattern? WTF? - secondly, what does this pattern actually do, how does it differ from regular text in a pattern, like some kinda
set efm+=,foobar
? the "foobar" here is for me also "text to search for"... :/
- um, first of all, trying to understand the sentence at all, where do I put the "text to search", after the
%+
- e.g. I I've seen something like that used in one question:%+C%.%#
- does it mean the whole line will be appended to a
%m
used in an earlier/later multiline pattern? if yes, then what if there was not%.%#
(== regexp.*
), but, let's say,%+Ccont.: %.%#
- would something like that work to capture only stuff after acont.:
string into the%m
? - also, what's the difference between
%C%.%#
and%+C%.%#
and%+G
? - also, what's the difference between
%A
and%+A
, or%E
vs.%+E
?
- does it mean the whole line will be appended to a
- finally, an example for Python in
:help errorformat-multi-line
ends with the following characters:%\\@=%m
-- WTF does the%\\@=
mean?
I'd be very grateful for some help understanding this stuff.
Ah,
errorformat
, the feature everybody loves to hate. :)Some meta first.
:make
and:cgetexpr
) take the output of a compiler and parse it into aquickfix
list.errorformat
is a string that describes how this parsing is done. It's a list of patterns, each pattern being a sort of hybrid between a regexp and ascanf(3)
format. Some of these patterns match single lines in the compiler's output, others try to match multiple lines (%E
,%A
,%C
etc.), others keep various states (%D
,%X
), others change the way parsing proceeds (%>
), while yet others simply produce messages in theqflist
(%G
), or ignore lines in the input (%-G
). Not all combinations make sense, and it's quite likely you won't figure out all details until you look at Vim' sources. shrugerrorformat
s usinglet &erf='...'
rather thanset erf=...
. The syntax is much more human-friendly.errorformat
usingcgetexpr
.cgetexpr
expects a list, which it interprets as the lines in the compiler's output. The result is aqflist
(or a syntax error).qflist
s are lists of errors, each error being a Vim "dictionary". See:help getqflist()
for the (simplified) format.qflist
with something like:echomsg string(getqflist())
, or you can see it in a nice window with:copen
(some important details are not shown in the window though).:cc
will take you to the place of the first error (assuming the first error inqflist
actually refers to an error in a file).Now to answer your questions.
You don't.
%s
reads a line from the compiler's output and translates it topattern
in theqflist
. That's all it does. To see it at work, create a fileefm.vim
with this content:Then run
:so%
, and try to understand what's going on.%f:%s:%m
looks for three fields: a filename, the%s
thing, and the message. The input line isefm.vim:" bar:baz
, which is parsed into filenameefm.vim
(that is, current file), pattern^\V" bar\$
, and messagebaz
. When you run:cc
Vim tries to find a line matching^\V" bar\$
, and sends you there. That's the next-to-last line in the current file.set efm+=foobar %m
will look for a line in the compiler's output starting withfoobar
, then assign the rest of the line to themessage
field in the corresponding error.%s
reads a line from the compiler's output and translates it to apattern
field in the corresponding error.Yes, it appends the content of the line matched by
%+C
to themessage
produced by an earlier (not later) multiline pattern (%A
,%E
,%W
, or%I
).No. With
%+Ccont.: %.%#
only the lines matching the regexp^cont\.: .*$
are considered, the lines not matching it are ignored. Then the entire line is appended to the previous%m
, not just the part that followscont.:
.%Chead %m trail
matches^head .* trail$
, then appends only the middle part to the previous%m
(it discardshead
andtrail
).%+Chead %m trail
matches^head .* trail$
, then appends the entire line to the previous%m
(includinghead
andtrail
).%+Gfoo
matches a line starting withfoo
and simply adds the entire line as a message in theqflist
(that is, an error that only has amessage
field).%A
and%E
start multiline patterns.%+
seems to mean "add the entire line being parsed tomessage
, regardless of the position of%m
".%\\@=
translates to the regexp qualifier\@=
, "matches preceding atom with zero width".