简体   繁体   English

Vim错误格式化多个条目

[英]Vim errorformat multiple entries

The c++ compiler Im using (kicked off by ant) produces errors in different formats. 使用的c ++编译器Im(由ant踢出)会产生不同格式的错误。 For example: 例如:

[apply] /localdev/foo.cc:10:29: error: foo.h: No such file or directory [应用] /localdev/foo.cc:10:29:错误:foo.h:没有这样的文件或目录

(lets call that Format A) (让我们将其称为格式A)

and in formats such as: 并采用以下格式:

[apply] /localdev/foo.cc:307: error: expected ';' [应用] /localdev/foo.cc:307:错误:预期为';' before 'std' 在“ std”之前

(lets call that Format B) (让我们称之为格式B)
Note Format A has an additional column specifier. 注意格式A有一个附加的列说明符。
I am trying to create a vim errorformat that will match both. 我正在尝试创建将两者都匹配的vim错误格式。
I have: 我有:

set errorformat=\\ %#[apply]\\ %f:%l:%c:\\ error:\\ %m 设置errorformat = \\%#[apply] \\%f:%l:%c:\\ error:\\%m
set errorformat+=\\ %#[apply]\\ %f:%l:\\ error:\\ %m 设置errorformat + = \\%#[apply] \\%f:%l:\\ error:\\%m

But I can't seem to get Vim to match Format B with that. 但是我似乎无法使Vim与此匹配。
I know the errorformat itself is correct because if I comment out the first errorformat setting, I can match error Format B. and if I comment out the second errorformat setting, I can match error Format A. 我知道errorformat本身是正确的,因为如果我注释掉第一个errorformat设置,我可以匹配错误格式B。如果我注释掉第二个errorformat设置,我可以匹配错误格式A。
Note that if I reverse the errorformat settings, then when Vim encounters error Format A, it trys to open a file called "/localdev/foo.cc:10", which of course is not found. 请注意,如果我反转错误格式设置,那么当Vim遇到错误格式A时,它会尝试打开一个名为“ /localdev/foo.cc:10”的文件,当然找不到该文件。 (looks like vim has a greedy matching algorithm and the string that is matching the file is also including the line number in this case). (看起来vim具有贪婪的匹配算法,在这种情况下,与文件匹配的字符串也包括行号)。

What is the proper errorformat setting that will match both Format A and Format B? 将同时与格式A和格式B匹配的正确的errorformat设置是什么?
I have looked on the internet and vim documentation for ways to make the %c "optional", but I have not found the secret. 我在Internet和vim文档中查找了使%c“可选”的方法,但是我没有找到秘密。
thank you. 谢谢。

You can do it like this: 您可以这样做:

let &errorformat =
    \ '%\s%#[apply] %f:%l:%c: %trror: %m,' .
    \ '%\s%#[apply] %f:%l: %trror: %m'

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

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