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
%mused 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
%Aand%+A, or%Evs.%+E?
- does it mean the whole line will be appended to a
- finally, an example for Python in
:help errorformat-multi-lineends 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.
:makeand:cgetexpr) take the output of a compiler and parse it into aquickfixlist.errorformatis 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,%Cetc.), 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. shrugerrorformats usinglet &erf='...'rather thanset erf=.... The syntax is much more human-friendly.errorformatusingcgetexpr.cgetexprexpects a list, which it interprets as the lines in the compiler's output. The result is aqflist(or a syntax error).qflists are lists of errors, each error being a Vim "dictionary". See:help getqflist()for the (simplified) format.qflistwith 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).:ccwill take you to the place of the first error (assuming the first error inqflistactually refers to an error in a file).Now to answer your questions.
You don't.
%sreads a line from the compiler's output and translates it topatternin theqflist. That's all it does. To see it at work, create a fileefm.vimwith this content:Then run
:so%, and try to understand what's going on.%f:%s:%mlooks for three fields: a filename, the%sthing, 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:ccVim 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 %mwill look for a line in the compiler's output starting withfoobar, then assign the rest of the line to themessagefield in the corresponding error.%sreads a line from the compiler's output and translates it to apatternfield in the corresponding error.Yes, it appends the content of the line matched by
%+Cto themessageproduced 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 trailmatches^head .* trail$, then appends only the middle part to the previous%m(it discardsheadandtrail).%+Chead %m trailmatches^head .* trail$, then appends the entire line to the previous%m(includingheadandtrail).%+Gfoomatches a line starting withfooand simply adds the entire line as a message in theqflist(that is, an error that only has amessagefield).%Aand%Estart 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".