What's the error type for in errorformat for Vim’s quickfix list?
I’m unsure about the %t
format specifier in Vim’s quickfix list. How does it affect the behavior/display of the quickfix buffer?
I tried to find it out with the following test file:
$ 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
And the following errorformat
first:
set errorformat+=%.%#%*\\s%.%#%*\\s%l\ %f%*\\s%m
With this errorformat
in place I can use :cgetfile test.out
and jump to the line numbers in foo.h
, but with the following errorformat
:
set errorformat+=%.%#%*\\s%t%.%#%*\\s%l\ %f%*\\s%m
All that has changed is that now I see some spaces after the line numbers in the quickfix buffer, e.g. I see (two spaces after the 1)
foo.h|1 | foobar
instead of
foo.h|1| foobar
So I have two questions:
开发者_运维知识库- What is wrong with my
errorformat
? - What should I see if the error type could be extracted?
I'm unsure about the %t format specifier in Vim's quickfix list, how does it affect the behavior/display of the quickfix buffer?
It tells the quickfix buffer what type of error a match is (error, warning, or informational). The quickfix buffer will then show that information after the line number and highlight it in a different color. For example, here is a warning and an error:
hosts.cfg|3473 error| Could not add object property
hosts.cfg|3790 warning| Duplicate definition found for host 'mailgateway'
In the quickfix window the word "warning" is in yellow and the word "error" is white on red. In my errorformat I am using %t where the E or W would be in Error or Warning. For example:
%trror: %m in file '%f' on line %l
This is not really an answer to your question, but an alternate solution I use myself. Personally I find the errorformat system too complicated, and instead use a common very simple errorformat fed by the output of a real function, that I pipe the output of my make command through. I use this: "%f\ %l\ %c\ %m". I write these error parsing functions in python, but any of the supported scripting languages should do, or even vimL. The logic of this being that such a function is much easier to debug, usable outside of vim, and (at least for me) quicker to write than crafting an errorformat string.
I have found the following example in quickfix.txt where %t is used.
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
It seems that some compiler are storing the error type in a single character E or W, presumably for Error and Warning.
Keep in mind that it is a single character, so it won't match "Warning" or "Error".
%t error type (finds a single character)
精彩评论