简体   繁体   中英

Vim errorformat: how to ignore a line but leave it visible?

I know how to get Vim to show only the error messages in the quick fix window, and hide everything else, but that's not quite what I want.

I would like the quick fix window to have my complete build log, for context, but with only the actual error messages highlighted and enabled for :cnext .

I can almost get this: the default behaviour when no pattern matches is to do the right thing; vim preceeds these lines with double bar, and that's fine:

|| cc -c myfile.c -o myfile.o
myfile.c|123| error: ......

The problem is when I have a line that matches an error pattern, but shouldn't (basically anything that has a random colon). I can add a %-G pattern to ignore it, but this also hides it from view, which isn't helpful.

Eg -DVAR="1:2" might get tagged as an error like this:

cc -DVAR="1 |2| " -c myfile.c -o myfile.o
myfile.c|123| error: ......

... in which case I don't want it to hide the cc line, but I do want to ignore it for error processing.

How can I write an exception pattern that just says "pretend nothing matched and do the default double-bar thing"?

You probably need to put an format string at the beginning of errorformat which matches cc (and excludes all other errors) but also lets the entire string (including cc ) be considered as the message %m .

If you say cc%m then the cc will not be part of %m . Only the characters after cc will be part of %m .

A solution is to use a zero-width look-ahead regex, like explained here: Vim errorformat: include part of expression in message string

The order of the error strings in 'errorformat' is very important. You'll want your new error string to earlier than any other error strings that may match this string the wrong way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM