Ah, errorformat , a function that everyone loves to hate. :)
Some meta first.
- Some Vim commands (such as
:make and :cgetexpr ) take the compiler output and parse it into a quickfix list. errorformat is a string that describes how this parsing is performed. This is a list of patterns, each of which is a hybrid between regular expression and scanf(3) format. Some of these patterns correspond to single lines at the output of the compiler, others try to match several lines ( %E , %A , %C , etc.), others retain different states ( %D , %X ), others change the parsing process continues ( %> ), while others simply create messages in qflist ( %G ) or ignore input lines ( %-G ). Not all combinations make sense, and it is likely that you will not find out all the details until you look at the sources of Vim. shrug - You probably want to write
errorformat using let &erf='...' rather than set erf=... The syntax is much more convenient for people. - You can experiment with
errorformat with cgetexpr . cgetexpr expects a list, which it interprets as strings in the compiler output. The result is a qflist (or syntax error). qflist is a list of errors, each error is a Vim dictionary. See :help getqflist() for the (simplified) format.- Errors can identify a place in a file, they can be simple messages (if important information that identifies a place is missing), and they can be valid or invalid (invalid - these are essentially parsing residues).
- You can display the current
qflist with something like :echomsg string(getqflist()) , or you can see it in a nice window with :copen (some important details are not displayed in the window, though). :cc will lead you to the place of the first error (if the first error in qflist actually refers to the error in the file).
Now to answer your questions.
um, first of all, trying to understand the sentence in general, where do I put “search text” after %s ? before that?
Not. %s reads a string from compiler output and translates it into pattern in qflist . That is all he does. To see it at work, create an efm.vim file with this content:
let &errorformat ='%f:%s:%m' cgetexpr ['efm.vim:" bar:baz'] echomsg string(getqflist()) copen cc " bar baz " bar " foo bar
Then run :so% and try to understand what is happening. %f:%s:%m searches for three fields: file name, object %s and message. The input line is efm.vim:" bar:baz , which is parsed for the file name efm.vim (that is, the current file), the pattern ^\V" bar\$ and the message baz . At startup :cc Vim tries to find the line matching ^\V" bar\$ and sends you there. This is the next line in the current file.
secondly, what does this template actually do, how does it differ from regular text in the template, like some kind of set efm+=,foobar ?
set efm+=foobar %m will search for a line in the compiler output, starting with foobar , and then assign the rest of the line to the message field in the corresponding error.
%s reads the string from the compiler output and translates it into the pattern field of the corresponding error.
%+ - for example, I saw something similar in one question: %+C%.%# does this mean that the whole line will be added to %m used in an earlier / later multi-line pattern?
Yes, it adds the contents of the string matched by %+C to message created by an earlier (not later) multiline pattern ( %A , %E , %W or %I )).
if yes, then what if there was no %.%# (== regexp .* ), but let's say %+Ccont.: %.%# - there will be something like this job to record only material after the cont.: line cont.: in %m ?
Not. With %+Ccont.: %.%# Only lines matching the regular expression ^cont\.: .*$ taken into account, lines not matching them are ignored. Then the whole line is added to the previous %m , and not just to the next part of cont.: . cont.: .
Also, what is the difference between %C%.%# and %+C%.%# and %+G ?
%Chead %m trail matches ^head .* trail$ , then adds only the middle part to the previous %m (it discards head and trail ).
%+Chead %m trail matches ^head .* trail$ , then adds the entire line to the previous %m (including head and trail ).
%+Gfoo matches the line starting with foo and simply adds the entire line as a message to qflist (i.e. an error that only has a message field).
also, what is the difference between %A and %+A , or %E vs. %+E ?
%A and %E start multiline patterns. %+ , apparently, means "add the whole line processed on message , regardless of the position of %m ".
finally, the Python example in :help errorformat-multi-line ends with the following characters: %\\@=%m - WTF means %\\@= mean?
%\\@= translates to the regexp qualifier \@= , "matches the previous atom with zero width".