代码之家  ›  专栏  ›  技术社区  ›  Ayman

VIM错误格式

  •  10
  • Ayman  · 技术社区  · 17 年前

    我读了这些文件,但更加困惑了。
    编译器生成了以下错误:

              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而不必一直使用Run Make?

    1 回复  |  直到 17 年前
        1
  •  26
  •   DrAl    17 年前

    首先,我讲的是调试。不幸的是,没有特别简单的方法可以做到这一点,但是一个有用的可能性是运行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%.%#'