Wes Miller
Wes Miller

Reputation: 2241

VIM Syntax coloring for error listings

We use shell scripts to call various cmake operations to build our product. The information echoed to STDERR is the errors output from the g++ compiler. I can use stream redirection to get the errors into a file

myBuild.sh 2> errors

and I can edit that file along with the various sources. Syntax highlighting is working in the .cpp's and .h's but the errors file is unhighlighted.

Is there a way to get vim to colorize my errors file? Perhaps adding a filetype as in errors.err or some script stored in $VIM_something?

Example output

/wxyzModule/wxyzModule.h: In member function 'void WxyzModule::setIsTesting(bool)':
/wxyzModule/wxyzModule.h:48:48: error: 'm_isTesting' was not declared in this scope

If I :set filetype=cpp, the 48:48 is red, bool is green, and not and this are yellow. Everything else stays the same white as if no highlighting were done.

Upvotes: 0

Views: 332

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172738

Though your error file contains C++ function and variable names, it is not C++ syntax (especially the overall structure with the filename in front is different). Therefore, trying to apply :setfiletype cpp to it is bound to fail.

If you really need highlighting in that, you have to write your own syntax plugin (e.g. called g++errorformat). You can certainly copy certain syntax elements from $VIMRUNTIME/syntax/cpp.vim, but essentially, you're writing a separate syntax.

Note: If you load the error file into Vim's quickfix list (:cfile errors), you'll get basic highlighting of filename and line / column, and amenities like jumping to the location of the error.

Upvotes: 1

Dhruva Sagar
Dhruva Sagar

Reputation: 7307

Consider instead to using :make from within vim, you can set it to use your shell command by setting :h 'makeprg' option, eg.) set makeprg=myBuild.sh\ 2>&1, the default :h 'errorformat' should work with this, otherwise you could tweak it.

Upvotes: 1

pfnuesel
pfnuesel

Reputation: 15350

You can set the filetype in to e.g. cpp with

:set filetype=cpp

If you want to know what filetype you are currently using, you can just type

:set filetype

If you don't want to type that every time, you can use an autocmd

autocmd BufNewFile,BufRead *.err   set filetype=cpp

Upvotes: 0

Related Questions