2

I have a few questions and a few issues using vim as a C# editing environment. Firstly I am new to vim, so it all is a bit of a learning process for me, I would appreciate any advice and guidance you may have to offer. Secondly I am having some issues getting any cs file to compile.

I am using this as my cs.vim compiler:

 if exists("current_compiler")
  finish
endif
let current_compiler = "cs"

if exists(":CompilerSet") != 2      " older Vim always used :setlocal
  command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet errorformat&
CompilerSet errorformat+=%f(%l\\,%v):\ %t%*[^:]:\ %m,
            \%trror%*[^:]:\ %m,
            \%tarning%*[^:]:\ %m

execute 'CompilerSet makeprg=' . cs#get_net_compiler("csc.exe") . "\\ %

Not sure exactly where I found this. But if I am in a directory with spaces in the dir name I get an error that the file cannot be found to compile. I think I need to tell it to escape the spaces, but how do I do this?

even if I switch back to the original cs.vim compiler file, i get weird issues and it does not appear to compile:

enter image description here

above and beyond that is it possible to work with C# projects in vim and when you compile have it recognize references etc?

EDIT: for clarification, I have and use Visual Studios as my main IDE. I would like to learn to use vim better, so thus I ask these questions.

Thanks!

sec_goat
  • 1,272
  • 1
  • 12
  • 20
  • 1
    As a VIM user for many years, you'll come running back to VS. – David East Oct 05 '12 at 14:58
  • Have a look at this post: http://stackoverflow.com/questions/983640/how-can-i-use-vim-to-do-net-development – Allov Oct 05 '12 at 15:03
  • @Allov thanks for that link. There was briefly some advice on this page about trying to use a different language with vim, one that is better supported, I may take that route and just use VS as my C# / .net editor. – sec_goat Oct 05 '12 at 15:07
  • I know it doesn't really help your question, but... in case you don't know about it, VsVim (http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329) is a really fantastic vim editor you can use within Visual Studio. It has a lot of Vim functionality (not all, of course) and as a long time Vim user I'm very happy working with it in VS. – ngm Oct 05 '12 at 15:44
  • @ngm That is actually what sparked my interest in Vim. My only problem is that I am so set in my ways, I get annoyed with VsVim and turn it off. I figure if I fully immerse myself in Vim, them I will be forced to learn it and VsVim will be all the much handier when I go back. – sec_goat Oct 05 '12 at 15:46

1 Answers1

3

Personally, I use a combination of Vim and Visual Studio (with VsVim installed) for my day to day C# coding. I do the longer spurts of editing with pure Vim because VsVim, as nice as it is, just isn't the same as the full Vim environment with its ecosystem. Nothing beats Visual Studio for interactive debugging.

To get the compiler, I use the following settings in my vimrc, stolen and transmogrified from some section of the internet:

set errorformat=\ %#%f(%l\\\,%c):\ %m
set makeprg=C:\\windows\\microsoft.net\\framework\\v4.0.30319\\msbuild.exe\ /nologo\ /v:q\ /property:GenerateFullPaths=true 

Please note that this integrates MSBuild and so works with the full .sln file--the whole build just works, no need to muck around with individual files. All you have to do to perform a full build is run :make.

While not strictly required, I also like this flag:

set shellcmdflag=\/C

because it ensures that the cmd window closes on its own.

Michael
  • 1,306
  • 1
  • 12
  • 30
  • does this include the project references? For instance I think i tried to compile a project just using Compiler CS, and got reference errors. I also found this: http://www.kianryan.co.uk/2012/09/vim-csharp/ which seems to have helped out a lot. I am still having a hard time making the full transition to Vim. – sec_goat Oct 16 '12 at 19:14
  • As long as your references are configured in the `.sln` file (as Visual Studio would do), they will work perfectly. What I typically do is perform admin-like things (e.g. adding references, adding files, creating projects) in Visual Studio and write as much code as possible from Vim. – Michael Oct 16 '12 at 19:33