Vim 错误格式

发布于 2024-08-07 01:15:58 字数 420 浏览 4 评论 0原文

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

          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?

I read the docs, but got even more confused.
I have the following error generated by the compiler:

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


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

I know how to detect the line where the error line is given, but I get loads of extra useless info in my errorlist, and the error message is split in two lines, whcih i would prefer to merge.

My starting errorformat is:

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

Since we are at it, is there a quick way of testing the efm without resorting to run make all the time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2024-08-14 01:15:58

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

First of all, I talk about debugging. Unfortunately, there's no particularly easy way of doing it, but one useful possibility is to run make and spit the output into a file and then:

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

Regarding making the errorformat, this does require a bit of trial and error. You can use %A, %C and %Z for multiline messages and you can use %-G to ignore stuff. The order is very important and note that sometimes the %C or even %Z come before the %A! In your case, you may be able to get somewhere with the efm below. I tend to use let &efm = and let &efm .= rather than set as you don't have to escape every space or quotation mark and you can build it up gradually. It's also much more readable.

" 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%.%#'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文