We’ll be heavily using omnisharp-vim in this guide.. This plugin provides a huge amount of features that facilitates C# development. To make full use of the features that omnisharp has to offer, the following plugins are needed;
From the time of writing this, omnisharp is configured to expect nunit-console.exe in your path somewhere. If this isn’t on your path, the nunit tests will silently fail to run. You have a choice with how to fix this;
Navigate to the omnisharp plugin configuration and change the test command from using nunit-console.exe to nunit-console4.
In a directory that is on your path, create a symlink from nunit-console.exe to /Library/Frameworks/Mono.framework/Commands/nunit-console4
Personally, I prefer the second option as it gives me the freedom to reinstall the plugin if necessary without having to dig into the configuration. Furthermore, the location where the config.json is said to be stored is now out of date, and it is unclear which config.json in the plgunis directory structure you should use.
Configuring vim with omnisharp shortcuts
You now have everything needed to open up a C# project in vim and be able to invoke omnisharp functions. However, you’ll need to make some amendments to your vim setup first to add some useful shortcuts. I would advise that you create a file type plugin to dump this configuration into, so you can keep your .vimrc devoid of all of this c# configuration. Here’s what I’ve used, which I’ve yanked and slightly modified from here to improve performance.
Setting up a C# project
To setup a C# project without relying on visual studio/xamarin studio, we can use grunt-init-csharpsolution.
Creating a project is then as straight forward as navigating to an empty directory, and performing the following;
grunt-init csharpsolution
nuget restore to install any dependencies
What functionality has been added
Now that we have this all setup, what does all of this give us? Provided you have followed all of these instructions, we now have
Tab Autocomplete, which also shows which parameters a particular function expects.
Project wide refactor. Press F2 to change a class/function/variable name and it’ll rename all instances in your project.
Asynchronous test runner. In a nunit test, either press ,ra to run all tests, ,rf to run all tests in a particular fixture, or ,rt to run a single test.
Context aware code actions. If you have configured Syntastic to work, you can hover over code shaded red/blue (which is Syntastic that indicating something is wrong), ,ca will provide ways you can fix this.
Navigate to classes/functions using gd.
Conclusion
These features have allowed me to come up with a pretty decent workflow for writing C# using vim. I would strongly recommend that you read through the omnisharp documentation to find out everything this great plugin has to offer.