Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

errorformat in Vim

📅 2015-Mar-25 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ errorformat, make, quickfix, vim ⬩ 📚 Archive

Vim can parse compilation errors when it is passed as an error file using the argument -q. It can also parse the errors produced by running :make. In both these cases, the file path, line and column number of errors can be parsed and traversed using :cnext or displayed in the QuickFix window.

The errorformat is the list of error formats that Vim uses to parse and recognize errors from input text. The default error format in Vim can be seen by trying the command :set errorformat?. The items in the list of error formats are separated by a comma. When separated, these are the components of the list:

%*[^"]"%f"%*\D%l: %m
"%f"%*\D%l: %m
%-G%f:%l: (Each undeclared identifier is reported only once
%-G%f:%l: for each function it appears in.)
%-GIn file included from %f:%l:%c:
%-GIn file included from %f:%l:%c\,
%-GIn file included from %f:%l:%c
%-GIn file included from %f:%l
%-G%*[ ]from %f:%l:%c
%-G%*[ ]from %f:%l:
%-G%*[ ]from %f:%l\,
%-G%*[ ]from %f:%l
"%f"\, line %l%*\D%c%*[^ ] %m
%D%*\a[%*\d]: Entering directory `%f'
%X%*\a[%*\d]: Leaving directory `%f'
%D%*\a: Entering directory `%f'
%X%*\a: Leaving directory `%f'
%DMaking %*\a in %f
%f|%l| %m

This default error format is set in Vim as DFLT_EFM based on the platform as seen in the source code here. Other error formats can be set at runtime based on the compiler flag. The different options for compiler and their corresponding error formats can be seen listed in the files in the directory /usr/share/vim/vim74/compiler. In fact, the default error format string set on Linux is the same as that in /usr/share/vim/vim74/compiler/gcc.vim

For more on error format see :help errorformat in Vim.

Tried with: Vim 7.4 and Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧