Vim Tips Wiki
Advertisement

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1575 Printable Monobook Previous Next

created June 26, 2008 · complexity basic · author Bmearns · version 7.0


The errorformat (or efm) option is a comma-separated list of scanf-style format strings that are used with QuickFix to extract information like file name, line number, column number, etc, from errors and warnings generated with :make. If an error/warning message in the quickfix window matches one of your error formats, you can select it (double click in gvim, or press Enter on the line) to jump to the correct place. It also provides some simple reformatting and highlighting to standardize the display of recognized messages. :help 'efm'

Vim comes preloaded with some good defaults. You can use the set errorformat command in (for instance) your vimrc file to add more for tools you use. If you use the += operator for the assignment, it will append the text to the current value, separated with a comma, as required for the errorformat.

Since compilers and other programs generate messages according to their own rules, there are a multitude of error formats that could be useful. Some are listed here.

flex

The free alternative to LEX, a lexical parser generator. Error messages are like: "somefile.l", line 15: rule cannot be matched.

set errorformat+=%*[\"]%f%*[\"]\\,\ line\ %l:\ %m

bison

The GNU bison parser generator (similar to YACC) generates a couple of different types of errors. They start with the file name, then a colon. If available, the linenumber comes next, followed by a dot (period) and the column number. If appropriate, a dash and then another column number (giving a column range) follows, and then a colon, space, and the error message.

set errorformat+=%f:%l.%c-%*[0-9]:\ %m
set errorformat+=%f:%l.%c:\ %m
set errorformat+=%f:\ %m

Texas Instruments cl2000 compiler

This is the C-compiler and linker that's used for some Texas Instruments DSP microprocessors. Error format is like "file.c", line 17: some error message.

set errorformat=\"%f\"\\,\ line\ %l:\ %m

mingw

The mingw Windows port of the gcc c-compiler/linker from the FSF.

set errorformat+=%f:%l:\ %m

gfortran

A suitable 'errorformat' for gfortran is:

set efm=%E%f:%l.%c:,%E%f:%l:,%C,%C%p%*[0123456789^],%ZError:\ %m,%C%.%#

%E%f:%l.%c:   to parse "FILENAME:LINENUMBER.COLNUMBER:".
%E%f:%l:   to parse "FILENAME:LINENUMBER:".
%C:   to pass over the empty line.
%C%p%*[0123456789^]:   to get the column number from the indicator line (" 1").
%ZError:\ %m:   to parse the error message ("Error: ERROR_MESSAGE").
%C%.%#:   to pass over the source code line (and ignore it).

The following allows parsing of the following message (make output):

gfortran hello-world.f90 -o hello-world.exe
hello-world.f90:11:

sprint *, "hello", pi, x, r
1
Error: Unclassifiable statement at (1)
hello-world.f90:9.4:

r = cotan(pi/2)
   1
Error: Function 'cotan' at (1) has no IMPLICIT type
make: *** [hello-world.exe] Error 1

In Vim, :clist then shows:

2 hello-world.f90:11 col 1 error:  Unclassifiable statement at (1)
3 hello-world.f90:9 col 4 error:  Function 'cotan' at (1) has no IMPLICIT type

Where hello-world.f90 is:

program hello
implicit none

real (kind = 10), dimension(10):: r
real (kind=8):: pi

pi = atan(1.0) * 4
r = cotan(pi/2)
sprint *, "hello", pi, x, r

end program

Modelsim vlog/vcom for Verilog/VHDL

A simulation tool for Verilog/VHDL. Error messages look like:
** Error: /pathto/somefile.v(115): near \"source text\": syntax error message.

set errorformat=**\ Error:\ %f(%l):\ %m

See also

Comments

 TO DO 

  • Clean up tips in Category:Compiler.
  • Where appropriate, should merge compiler tips for a particular language into one tip.
  • Need emphasis to be on the :compiler command (don't directly mess with 'efm').
  • Settings for errorformat should be in a compiler plugin rather than in vimrc. :help write-compiler-plugin :help compiler-select
  • If there is no support for a compiler, user should add a new compiler (need example of how).
  • Need links to a tip with info on the quickfix window.

Related tips (all are in Compiler category; first four are in 'see also' above)

Many existing tips have obsolete/bad advice, for example, tip 476 says to edit the $VIM/ftplugin/perl.vim file (probably means $VIMRUNTIME/ftplugin/perl.vim but you should never patch a distribution file).


Advertisement