Vim errorformat for Visual Studio

点点圈 提交于 2019-12-02 16:15:31

I have a blog post which walks through all the details of getting C# projects building in Vim, including the error format. You can find it here: http://kevin-berridge.blogspot.com/2008/09/vim-c-compiling.html

In short you need the following:

:set errorformat=\ %#%f(%l\\\,%c):\ %m
:set makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true

Copy from question to remove from 'unanswered' list

set errorformat=\ %#%f(%l\\\,%c):\ %m

This will capture the output for both devenv /Build and msbuild. However, msbuild has one catch. By default, it's output doesn't include full paths. To fix this you have to add the following line to your csproj file's main PropertyGroup:

<GenerateFullPaths>True</GenerateFullPaths>

I found an even better answer: use :compiler to use built-in efm settings.

" Microsoft C#
compiler cs
" Microsoft Visual C++
compiler msvc
" mono
compiler mcs
" gcc
compiler gcc

Note: It also sets the default makeprg. See $VIMRUNTIME/compiler/

Try running msbuild instead of devenv. This will open up a ton of power in how the build runs.

Open a Visual Studio Command Prompt to get your path set up. Then do msbuild MySln.sln /Configuration:Debug.

See msbuild /? for help.

I found this question when looking for errorformat for compiling c++ in Visual Studio. The above answers don't work for me (I'm not using MSBuild either).

I figured out this from this Vim Tip and :help errorformat:

" filename(line) : error|warning|fatal error C0000: message
set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %[A-Z\ ]%#%n:\ %m

Which will give you a quickfix looking like this:

stats.cpp|604 error 2039| 'getMedian' : is not a member of 'Stats'

(with error highlighted) from

c:\p4\main\stats.cpp(604) : error C2039: 'getMedian' : is not a member of 'Stats'

As Simon Buchan mentioned you can use this in your project to generate the full paths in the output:

<GenerateFullPaths>True</GenerateFullPaths>

But you can make it more portable by adding /property:GenerateFullPaths=true to you makeprg instead of adding the above to your project files.

:set makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true\

None of these errorformats worked in Visual studio 2009 v9.0.21022.8 professional edition. Using cygwin, had to call devenv from bash which made setting makeprg a little tricky (screw batch files). Also had to tweak my errorformat when devenv splits into multiple processes and proceeds error message with "1>" or "2>" etc:

set autowrite
"2>c:\cygwin\home\user\proj/blah.cpp(1657) : error C2065: 'blah' : undeclared identifier

set errorformat=%.%#>\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %[A-Z\ ]%#%n:\ %m
let prg="devenv"
let makepath=$MAKEPATH
let &makeprg='cmd /c "'.prg.' '.makepath.'"'

My .bashrc sets the MAKEPATH environment variable using cygpath to convert to a DOS compatible path:

export MAKEPATH="$(cygpath -d "proj/VC9/some.sln") /build \"Debug\""

If you have vim 6.x you can use :cw which is SO much better than clist (try searching for errors among hundreds of warnings and you know what I mean). Looking at vim tweaks makes me want to vomit but I'm in vim heaven!!! Good bye visual studio! Thanks for the base to tweak pydave +1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!