Vim:错误格式匹配所有内容
我试图将以下错误与 efm
匹配:
AssertionError: 1 == 2
at /home/strager/projects/blah/blah.js:13:37
错误消息可以是任何内容(即它并不总是与 AssertionError: .*
或 .*Error: .*
格式匹配)。一般格式为:
errormessage
at filename:line:column
我的问题是错误消息与任意行匹配;我需要将错误消息限制为仅一行,并且仅在其后跟匹配的“at”行时才匹配。
我尝试过以下efm
:
set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m
" %Z at %f:%l:%c,%E%m
这几乎可以工作,但除了错误之外,它还匹配状态行(例如,错误之前和之后的非错误)。如何强制 %E%m ... %Z
总共只有两行(一行用于错误消息,一行用于 at
行)?如果需要,我可以使用 makeprg
的标准 UNIX 工具。
I am trying to match the following error with efm
:
AssertionError: 1 == 2
at /home/strager/projects/blah/blah.js:13:37
The error message can be anything (i.e. it doesn't always match the AssertionError: .*
or .*Error: .*
formats). The general format is:
errormessage
at filename:line:column
My problem is that the error message matches any line; I need to restrict the error message to one line only, and only match if it's followed by a matching "at" line.
I have tried the following efm
:
set efm=%Z\ \ \ \ at\ %f:%l:%c,%E%m
" %Z at %f:%l:%c,%E%m
This almost works, but it matches status lines (e.g. non-errors before and after the error) in addition to the errors. How can I force %E%m ... %Z
to be only two lines total (one for the error message, and one for the at
line)? I have access to the standard UNIX tools for makeprg
if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有效吗?
%-G%.%# 告诉 vim 忽略与其他模式不匹配的整行。
Does this work?
The %-G%.%# tells vim to ignore entire lines that do not match the other patterns.
您真的想花时间学习一种在其他地方没有应用的晦涩模式语言吗?除非有人付钱让你编写 vim 编译器插件,否则我不会(而且我喜欢 vim!)。既然您愿意打开工具箱,只需在检查器周围编写一个包装器并输出易于解析的格式即可。例如:
Do you really want to spend your time learning an obscure pattern language that has no application anywhere else? Unless someone is paying you to write vim compiler plug-ins, I wouldn't (and I love vim!). Since you're willing to open the toolbox, just write a wrapper around your checker and spit out an easy-to-parse format. Eg:
怎么样...
What about ...
也许
检查这个
Maybe
Check this