The result

C# code completion and other rich editing features in Vim.

The high level steps

Details of these steps are in the OmniSharp-Vim repository. The steps are non-trivial. For each step I've provided a way to answer, "Is this step done?"

Install pathogen.vim. Done? Add execute pathogen#infect() to the top of your vimrc and run Vim without errors.

Install omnisharp-vim. Done? Run msbuild from ~/vimfiles/bundles/omnisharp-vim/server without errors.

Install Python. Done? Run :echo has('python') from within Vim and receive a return value of 1.

Install vim-dispatch. Done? Run :dispatch from Vim without errors.

Install syntastic. Done? Run :Helptags from Vim without errors.

Install CtrlP. Done? Run :CtrlP from Vim without errors.

Sanity check

The installation is complete if all of the above steps are done and dir ~/vimfiles/bundle outputs this:


Configure Vim to use Roslyn

Add the following to the top of your vimrc.

let g:OmniSharp_server_type = 'roslyn' 
let g:OmniSharp_prefer_global_sln = 1  
let g:OmniSharp_timeout = 10           

It tells Vim's OmniSharp to use Roslyn, to look for a global.json instead of a sln file, and to wait 10 seconds for the sometimes slow OmniSharp service to respond.

Vim should now provide a rich editing experience when we open a *.cs file inside a .NET Core solution. The problem is that it requires one more difficult step: troubleshooting.

Pattern not found

When we open a *.cs file with Vim, running Ctrl + X + Ctrl + O is supposed to provide completions; instead, we received the following error:

-- Omni completion (^O^N^P) Pattern not found

We were able to work around that by updating the OmniSharp-Roslyn submodule...

cd ~\vimfiles\bundle\omnisharp-vim\omnisharp-roslyn
git checkout dev

Updating the submodule was necessary, because omnisharp-roslyn\artifacts did not initially exist. That was because the build.ps1 script failed, which was due to a missing xunit.runner.utility.desktop.dll assembly. Happily, the great and wise Dustin Campbell had made a fixing PR seven days ago, which we were able to checkout from dev.

If the above is not working, try starting OmniSharp-Roslyn manually as follows:

cd ~\vimfiles\bundle\omnisharp-vim\omnisharp-roslyn
Omnisharp -p 2000 -s C:\temp

This is the content of our C:\temp directory, which contains a dotnet new project, which we created with a dotnet --version of 1.0.0-rc3-004530, and to which we added a valid global.json file.



Where is my vimrc? Run :scriptnames or :echo $MYVIMRC or :help vimrc to view its path. Often the location is ~/_vimrc.

Where are my vimfiles? Run :scriptnames or help vimfiles and look for the PC-related help section. Often the location is ~/vimfiles/.

Why is this so hard? That's the Vim way.

Further reading