简体   繁体   English

Vim 错误格式:如何忽略一行但使其可见?

[英]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.我知道如何让 Vim 仅显示快速修复 window 中的错误消息,并隐藏其他所有内容,但这并不是我想要的。

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 .我希望快速修复 window 有我完整的构建日志,作为上下文,但只有实际的错误消息突出显示并为: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: vim 在这些行之前带有双杠,这很好:

|| 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.我可以添加一个%-G模式来忽略它,但这也会将它隐藏起来,这没有帮助。

Eg -DVAR="1:2" might get tagged as an error like this:例如-DVAR="1:2"可能会被标记为如下错误:

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. ...在这种情况下,我希望它隐藏cc行,但我确实想忽略它以进行错误处理。

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 .您可能需要在errorformat的开头放置一个格式字符串,它与cc匹配(并排除所有其他错误),但也让整个字符串(包括cc )被视为消息%m

If you say cc%m then the cc will not be part of %m .如果你说cc%m那么cc将不是%m的一部分。 Only the characters after cc will be part of %m .只有cc之后的字符才会成为%m的一部分。

A solution is to use a zero-width look-ahead regex, like explained here: Vim errorformat: include part of expression in message string一种解决方案是使用零宽度前瞻正则表达式,如下所述: Vim errorformat: include part of expression in message string

The order of the error strings in 'errorformat' is very important. 'errorformat'中错误字符串的顺序非常重要。 You'll want your new error string to earlier than any other error strings that may match this string the wrong way.您会希望新的错误字符串早于可能以错误方式匹配此字符串的任何其他错误字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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