[英]What's the meaning of some advanced patterns in vim errorformat? (%s, %+, %\\@=)
I tried reading :help errorformat
and googling (mostly stackoverflow), but can't understand some of the patterns mentioned there: 我试过阅读
:help errorformat
和googling(主要是stackoverflow),但无法理解那里提到的一些模式:
%s
- "specifies the text to search for to locate the error line. [...]" %s
- “指定要搜索的文本以找到错误行。[...]”
%s
? %s
之后我在哪里放“搜索文本”? before it? set efm+=,foobar
? set efm+=,foobar
? the "foobar" here is for me also "text to search for"... :/ %+
- eg I I've seen something like that used in one question : %+C%.%#
%+
- 例如,我在一个问题中看到过类似的东西 : %+C%.%#
%m
used in an earlier/later multiline pattern? %m
? if yes, then what if there was not %.%#
(== regexp .*
), but, let's say, %+Ccont.: %.%#
- would something like that work to capture only stuff after a cont.:
string into the %m
? %.%#
(== regexp .*
),但是,让我们说, %+Ccont.: %.%#
- 就像这样的工作只捕获一个cont.:
后的东西cont.:
字符串进入%m
? %C%.%#
and %+C%.%#
and %+G
? %C%.%#
和%+C%.%#
和%+G
之间有什么区别? %A
and %+A
, or %E
vs. %+E
? %A
和%+A
或%E
与%+E
之间有什么区别? :help errorformat-multi-line
ends with the following characters: %\\\\@=%m
-- WTF does the %\\\\@=
mean? :help errorformat-multi-line
以下列字符结尾: %\\\\@=%m
- WTF执行%\\\\@=
是什么意思? I'd be very grateful for some help understanding this stuff. 我非常感谢帮助理解这些东西。
Ah, errorformat
, the feature everybody loves to hate. 啊,错误
errorformat
,每个人都喜欢讨厌的功能。 :) :)
Some meta first. 有些元首先。
:make
and :cgetexpr
) take the output of a compiler and parse it into a quickfix
list. :make
和:cgetexpr
)获取编译器的输出并将其解析为quickfix
列表。 errorformat
is a string that describes how this parsing is done. errorformat
是一个描述如何完成此解析的字符串。 It's a list of patterns, each pattern being a sort of hybrid between a regexp and a scanf(3)
format. scanf(3)
格式之间的混合。 Some of these patterns match single lines in the compiler's output, others try to match multiple lines ( %E
, %A
, %C
etc.), others keep various states ( %D
, %X
), others change the way parsing proceeds ( %>
), while yet others simply produce messages in the qflist
( %G
), or ignore lines in the input ( %-G
). %E
, %A
, %C
等),其他模式保持各种状态( %D
, %X
),其他模式改变解析进行的方式( %>
),而其他人只是在qflist
( %G
)中生成消息,或忽略输入中的行( %-G
)。 Not all combinations make sense, and it's quite likely you won't figure out all details until you look at Vim' sources. errorformat
s using let &erf='...'
rather than set erf=...
. let &erf='...'
而不是set erf=...
来编写errorformat
。 The syntax is much more human-friendly. errorformat
using cgetexpr
. cgetexpr
试验errorformat
。 cgetexpr
expects a list, which it interprets as the lines in the compiler's output. cgetexpr
需要一个列表,它将其解释为编译器输出中的行。 The result is a qflist
(or a syntax error). qflist
(或语法错误)。 qflist
s are lists of errors, each error being a Vim "dictionary". qflist
是错误列表,每个错误都是Vim“字典”。 See :help getqflist()
for the (simplified) format. :help getqflist()
获取(简化)格式。 qflist
with something like :echomsg string(getqflist())
, or you can see it in a nice window with :copen
(some important details are not shown in the window though). qflist
:echomsg string(getqflist())
,或者您可以在一个漂亮的窗口中看到它:copen
(尽管窗口中没有显示一些重要的细节)。 :cc
will take you to the place of the first error (assuming the first error in qflist
actually refers to an error in a file). :cc
将带您到第一个错误的位置(假设qflist
的第一个错误实际上是指文件中的错误)。 Now to answer your questions. 现在回答你的问题。
um, first of all, trying to understand the sentence at all, where do I put the "text to search", after the
%s
?嗯,首先,尝试理解句子,在
%s
之后我在哪里放“搜索文本”? before it?在它之前?
You don't. 你没有。
%s
reads a line from the compiler's output and translates it to pattern
in the qflist
. %s
读取来自编译器的输出线,并将其转换到pattern
在qflist
。 That's all it does. 就是这样。 To see it at work, create a file
efm.vim
with this content: 要查看它的工作原理,
efm.vim
使用以下内容创建一个文件efm.vim
:
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's going on. 然后运行
:so%
,并尝试了解发生了什么。 %f:%s:%m
looks for three fields: a filename, the %s
thing, and the message. %f:%s:%m
查找三个字段:文件名, %s
事物和消息。 The input line is efm.vim:" bar:baz
, which is parsed into filename efm.vim
(that is, current file), pattern ^\\V" bar\\$
, and message baz
. 输入行是
efm.vim:" bar:baz
,它被解析为文件名efm.vim
(即当前文件),模式^\\V" bar\\$
和消息baz
。 When you run :cc
Vim tries to find a line matching ^\\V" bar\\$
, and sends you there. That's the next-to-last line in the current file. 当你运行
:cc
Vim试图找到一个匹配^\\V" bar\\$
,然后发送给你。这是当前文件中的倒数第二行。
secondly, what does this pattern actually do, how does it differ from regular text in a pattern, like some kinda
set efm+=,foobar
?其次,这个模式实际上做了什么,它与模式中的常规文本有什么不同,比如某种
set efm+=,foobar
?
set efm+=foobar %m
will look for a line in the compiler's output starting with foobar
, then assign the rest of the line to the message
field in the corresponding error. set efm+=foobar %m
将从foobar
开始在编译器的输出中查找一行,然后将该行的其余部分分配给相应错误中的message
字段。
%s
reads a line from the compiler's output and translates it to a pattern
field in the corresponding error. %s
从编译器的输出中读取一行,并将其转换为相应错误中的pattern
字段。
%+
- eg I I've seen something like that used in one question:%+C%.%#
does it mean the whole line will be appended to a%m
used in an earlier/later multiline pattern?%+
- 例如,我在一个问题中看到了类似的东西:%+C%.%#
是否意味着整条线将附加到早期/后期多线模式中使用的%m
?
Yes, it appends the content of the line matched by %+C
to the message
produced by an earlier (not later) multiline pattern ( %A
, %E
, %W
, or %I
). 是的,它由附加的匹配线的含量
%+C
的message
通过对早期(不晚)多模式(产生%A
, %E
, %W
,或%I
)。
if yes, then what if there was not
%.%#
(== regexp.*
), but, let's say,%+Ccont.: %.%#
- would something like that work to capture only stuff after acont.:
string into the%m
?如果是的话,那么如果没有
%.%#
(== regexp.*
),但是,让我们说,%+Ccont.: %.%#
- 就像这样的工作只捕获一个cont.:
后的东西cont.:
字符串进入%m
?
No. With %+Ccont.: %.%#
only the lines matching the regexp ^cont\\.: .*$
are considered, the lines not matching it are ignored. %+Ccont.: %.%#
只考虑与regexp ^cont\\.: .*$
匹配的行,忽略不匹配的行。 Then the entire line is appended to the previous %m
, not just the part that follows cont.:
. 然后整行被附加到前一个
%m
,而不仅仅是跟随cont.:
的部分。
also, what's the difference between
%C%.%#
and%+C%.%#
and%+G
?另外,
%C%.%#
和%+C%.%#
和%+G
之间有什么区别?
%Chead %m trail
matches ^head .* trail$
, then appends only the middle part to the previous %m
(it discards head
and trail
). %Chead %m trail
匹配^head .* trail$
,然后仅将中间部分附加到前一个%m
(它丢弃head
和trail
)。
%+Chead %m trail
matches ^head .* trail$
, then appends the entire line to the previous %m
(including head
and trail
). %+Chead %m trail
匹配^head .* trail$
,然后将整行附加到前一个%m
(包括head
和trail
)。
%+Gfoo
matches a line starting with foo
and simply adds the entire line as a message in the qflist
(that is, an error that only has a message
field). %+Gfoo
匹配以foo
开头的行,只是将整行添加为qflist
的消息(即,只有message
字段的错误)。
also, what's the difference between
%A
and%+A
, or%E
vs.%+E
?另外,
%A
和%+A
或%E
与%+E
之间有什么区别?
%A
and %E
start multiline patterns. %A
和%E
开始多行模式。 %+
seems to mean "add the entire line being parsed to message
, regardless of the position of %m
". %+
似乎意味着“将正在解析的整行添加到message
,无论%m
的位置如何”。
finally, an example for Python in
:help errorformat-multi-line
ends with the following characters:%\\\\@=%m
-- WTF does the%\\\\@=
mean?最后,Python的示例
:help errorformat-multi-line
以下列字符结尾:%\\\\@=%m
- WTF执行%\\\\@=
是什么意思?
%\\\\@=
translates to the regexp qualifier \\@=
, "matches preceding atom with zero width". %\\\\@=
转换为regexp限定符\\@=
,“匹配前面的原子与零宽度”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.