Vim errorformat

时间:2009-10-06 12:47:33

标签: vim errorformat

我阅读了文档,但更加困惑 我有编译器生成以下错误:

          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?

1 个答案:

答案 0 :(得分:26)

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

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

关于制作错误格式,这确实需要一些试验和错误。您可以将%A,%C和%Z用于多行消息,并且可以使用%-G忽略内容。订单非常重要,请注意有时%C甚至%Z来自%A!在您的情况下,您可能能够获得以下efm的某个地方。我倾向于使用let &efm =let &efm .=而不是设置,因为你不必逃避每个空格或引号,你可以逐步建立它。它也更具可读性。

" 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%.%#'