9

我不确定%tVim 的快速修复列表中的格式说明符。它如何影响快速修复缓冲区的行为/显示?

我试图用以下测试文件找出它:

$ cat test.out
foo              Error         1 foo.h            foobar
bar              Error         2 foo.h            foobar
foobar           Warning       3 foo.h            foobar
barfoo           Warning       4 foo.h            foobar

首先是以下内容errorformat

set errorformat+=%.%#%*\\s%.%#%*\\s%l\ %f%*\\s%m

有了这个errorformat,我可以使用:cgetfile test.out并跳转到中的行号foo.h,但是使用以下内容errorformat

set errorformat+=%.%#%*\\s%t%.%#%*\\s%l\ %f%*\\s%m

改变的只是现在我在快速修复缓冲区中的行号之后看到一些空格,例如我看到(1 之后的两个空格)

foo.h|1  | foobar

代替

foo.h|1| foobar

所以我有两个问题:

  1. 我怎么了errorformat
  2. 如果可以提取错误类型,我应该查看什么?
4

3 回答 3

8

我不确定 Vim 的快速修复列表中的 %t 格式说明符,它如何影响快速修复缓冲区的行为/显示?

它告诉快速修复缓冲区匹配的错误类型(错误、警告或信息)。然后,快速修复缓冲区将在行号之后显示该信息并以不同的颜色突出显示它。例如,这是一个警告和一个错误:

hosts.cfg|3473 error| Could not add object property
hosts.cfg|3790 warning| Duplicate definition found for host 'mailgateway'

在快速修复窗口中,“警告”一词为黄色,“错误”一词为红底白字。在我的错误格式中,我使用 %t ,其中 E 或 W 将处于错误或警告中。例如:

%trror: %m in file '%f' on line %l
于 2011-01-26T22:00:29.357 回答
5

这并不是您问题的真正答案,而是我自己使用的替代解决方案。就我个人而言,我发现错误格式系统过于复杂,而是使用由真实函数的输出提供的常见非常简单的错误格式,我将 make 命令的输出通过管道传输。我使用这个:“%f\ %l\ %c\ %m”。我在 python 中编写了这些错误解析函数,但是任何支持的脚本语言都应该这样做,甚至 vimL。这样做的逻辑是这样的函数更容易调试,可以在 vim 之外使用,并且(至少对我而言)比编写错误格式字符串更快。

于 2010-12-10T02:20:26.803 回答
2

我在 quickfix.txt 中找到了以下示例,其中使用了%t

Examples
The format of the file from the Amiga Aztec compiler is:
filename>linenumber:columnnumber:errortype:errornumber:errormessage

filename    name of the file in which the error was detected  
linenumber  line number where the error was detected  
columnnumber    column number where the error was detected  
errortype   type of the error, normally a single 'E' or 'W'  
errornumber number of the error (for lookup in the manual)  
errormessage    description of the error    

This can be matched with this errorformat entry:
%f>%l:%c:%t:%n:%m

似乎某些编译器将错误类型存储在单个字符 E 或 W 中,可能是错误和警告。

请记住,它是单个字符,因此它不会匹配“警告”或“错误”。
%t error type (finds a single character)

于 2010-12-10T08:52:50.070 回答