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.
考虑使用:make
从vim中,你可以通过设置:h 'makeprg'
选项来设置它使用你的shell命令,例如: set makeprg=myBuild.sh 2>&1
,默认值:h 'errorformat'
set makeprg=myBuild.sh 2>&1
与这工作,否则你可以调整它。
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 (eg 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.
You can set the filetype in vim to eg 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
链接地址: http://www.djcxy.com/p/19136.html
上一篇: 基于列的ViM语法高亮显示
下一篇: VIM语法着色错误列表