[英]How to make vim parse my multi-line error message for the quickfix window?
我想使用make
在vim下運行我的應用程序,我希望quickfix
窗口顯示我的錯誤。
所以我有這種格式,首先以Error:
開頭Error:
然后文件名,行和列分隔:
然后在下一行,這將是一個沒有特殊格式的多行消息,然后消息將以ErrorEnd
結束。
所以這是一個例子:
Error: /somefile/something/something.c:12:123
SOME MESSAGE
ANOTHER HELPFUL MESSAGE
ANOTHER MESSAGE
ErrorEnd
我在文檔中迷失了如何使它與這些線匹配。 一切看起來都很混亂,例子不像這個。 我知道如何使它與第一行匹配,但不知道如何使它與下一行匹配作為錯誤消息。 所以問題是什么是一個可以解析它的errorformat字符串。
從vim errorformat幫助頁面:
Multi-line messages *errorformat-multi-line*
It is possible to read the output of programs that produce multi-line
messages, i.e. error strings that consume more than one line. Possible
prefixes are:
%E start of a multi-line error message
%W start of a multi-line warning message
%I start of a multi-line informational message
%A start of a multi-line message (unspecified type)
%> for next line start with current pattern again |efm-%>|
%C continuation of a multi-line message
%Z end of a multi-line message
These can be used with '+' and '-', see |efm-ignore| below.
Using "\n" in the pattern won't work to match multi-line messages.
Example: Your compiler happens to write out errors in the following format
(leading line numbers not being part of the actual output):
1 Error 275
2 line 42
3 column 3
4 ' ' expected after '--'
The appropriate error format string has to look like this:
:set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
編輯:啊,你的意思是多行錯誤。 對。 那更難。
你是對的,解析quickfix的多行錯誤信息很困難。 我甚至不確定是否可以將錯誤解析為個別錯誤。
我用於笨拙的錯誤輸出的一種解決方法是將轉換步驟(通常使用sed
)附加到'makeprg'
,它將多行錯誤轉換為傳統的每行錯誤消息; 就像是
Error: /somefile/something/something.c:12:123 SOME MESSAGE
Error: /somefile/something/something.c:12:123 ANOTHER HELPFUL MESSAGE
Error: /somefile/something/something.c:12:123 ANOTHER MESSAGE
在你的情況下。
您可以使用%+
前綴捕獲錯誤消息中的多行文本,如下所述:help efm-ignore
結合多行錯誤格式說明符%E
, %C
, %Z
等描述於:help errorformat-multi-line
。 在您的具體示例中,以下似乎有效:
let &l:efm='%EError: %f:%l:%c,%-ZErrorEnd,%+C%.%#'
請注意與該行上的任何文本匹配的%+C
項,並將其添加到錯誤消息中。 另請注意我必須將%-Z
項放在此項之前才能使用它,因為在解析該行時將使用第一個匹配的errorformat項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.