Home

Extended MSVC errorformat in Vim

The default errorformat in Vim is enough to recognize error messages and put it into the quickfix window. The part responsible for it is this: %f(%l): %m.

But Vim provides more scancodes than just file, line and message to extract more information from it. For example error number and type can also extracted. The help states the corresponding scancodes are %t for error type and %n for error number. Error type is a single character, as far as I have seen ā€˜wā€™ for warnings and ā€˜eā€™ for errors are recognized, everything else is treated the same as a warning.

As far as I know, the compiler prints 3 types of messages: notes, warnings and errors. For template errors it also prints the template parameters. To catch all 3 cases, 3 errorformats need to be added. In case of warnings and errors a number is supplied which can be used to search the compiler manual to get additional error descriptions.

The resulting errorformat string are as follows:

The vimrc entries require escaped spaces when using set, so the result is:

set errorformat+=%f(%l):\ %trror\ C%n:\ %m
set errorformat+=%f(%l):\ %tarning\ C%n:\ %m
set errorformat+=%f(%l):\ %tote:\ %m

Sadly Vim does not support jumping from one error to the next one, skipping all warnings. This dampens the usefulness of this extended errorformat.

In addition I write an errorformat entry to suppress template information in the quickfix window. Of course, sometimes that information might be needed to correct the error, but in my experience so far they mostly take up screen space.

The scancode %-G filters messages, %s and %m are used only used as placeholders, not to actually catch meaningful content. The part %\\s%# match whitespace which precedes any line of the template message. The complete errorformat to filter the template messages would be:

set errorformat+=%-G%\\s%#and,%-G%\\s%#with,%-G%\\s%#[,%-G%\\s%#%s=%m,%-G%\\s%#]