Vim错误格式

10

我读了文档,但越看越困惑。
编译器生成了以下错误:

          rot;
          ^
"cpp\c1.cpp", line 13: error(114): identifier
          "rot" is undefined


1 error detected in the compilation of "c1.cpp".

我知道如何检测给定错误行的行号,但我的错误列表中会有很多额外无用的信息,并且错误消息被分成了两行,我希望将其合并。

我的起始错误格式为:

:set efm=\"%f\"\\,\ line\ %l:\ error(%n):\ %m

既然我们在这里,是否有一种快速测试 efm 的方法,而不必总是运行 make all?


1
无用信息是什么样的东西?它是实际编译器错误输出中被一个特定符号错误地抓取的内容吗?这也可能解释为什么会出现两行消息。如果有帮助的话,以下是默认值,取自源代码(我在帮助文件中找不到):"%f>%l:%c:%t:%n:%m,%f:%l: %t%*\\D%n: %m,%f %l %t%*\\D%n: %m,%*[^\"]\"%f\"%*\\D%l: %m,%f:%l:%m,%f|%l| %m" - Cascabel
1个回答

28

首先,我谈一下调试。不幸的是,没有特别简单的方法,但有一个有用的可能性是运行make,并将输出写入文件,然后:

:let &makeprg="cat ~/outputfile.log"
:make

关于制作错误格式,这确实需要一些尝试和错误。您可以使用%A,%C和%Z来处理多行消息,并且您可以使用%-G来忽略某些内容。顺序非常重要,注意有时%C甚至%Z在%A之前出现!在您的情况下,您可以尝试以下efm。我倾向于使用let&efm =let&efm .=而不是set,因为你不必逐个转义每个空格或引号,并且可以逐步构建它。它也更易读。

" Start of the multi-line error message (%A),
" %p^ means a string of spaces and then a ^ to
" get the column number
let &efm  = '%A%p^' . ','
" Next is the main bit: continuation of the error line (%C)
" followed by the filename in quotes, a comma (\,)
" then the rest of the details
let &efm .= '%C"%f"\, line %l: error(%n): %m' . ','
" Next is the last line of the error message, any number
" of spaces (' %#': equivalent to ' *') followed by a bit
" more error message
let &efm .= '%Z %#%m' . ','
" This just ignores any other lines (must be last!)
let &efm .= '%-G%.%#'

6
感谢调试提示。在Windows上,由于cat工具不可用,可以使用:let &makeprg="type outputfile.log"命令来代替。注意不要改变原意,使翻译更加通俗易懂。 - mMontu
1
根据您更改efm的位置,您可能希望使用let &l:efm=而不是let &efm=来获得与setlocal等效的行为。我特别考虑了文件类型插件或类似的vim文件。 - Dave Goodell
事实证明,在我的 C++ 代码中使用空格而不是制表符的第一个真正好的理由出现了。如果您使用制表符并且编译器输出也使用了制表符,那么%p^将会失败:( - Paul

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接