A Page screen shot of the Neovim text editor showcasing Intellisense autocomplete working with a Unity .NET c# file.

Configure (Neo)Vim for Unity Game Engine Development

November 15, 2020 RSS Feed Only Files Quick View

Tools - Install the following

  • NeoVim - Open source fork of the Vim editor.
  • Neovim-CoC - Intellisense Engine - Make your Vim/Neovim as smart as VSCode.
  • OmniSharp-vim - A great vim plugin that installs omnisharp and integrates with mono/.NET and Coc.
  • Mono - Open Sourced version of the .NET software framework - Unity compiles c# code to c++. Only needed if you are developing on OSX/Linux
  • Unity - Game Development Engine.
  • Neovim-Remote - This is a python executable script that extends Neovim to allow for remote features that are available with regular vim.

Preface

Neovim-CoC is a very robust vim plugin which allows for numerous extensions and configurations. It is not really an “out of the box” solution, and you will have to get your hands dirty. Having said that, I really appreciate all of the work that is going into this plugin, and can’t imagine developing without it.

If you use a different Intellisense solution, just make sure OmniSharp-vim is compatible with it.

Tutorial

I LOVE editing code in Vim. Recently I decided to dabble with the Unity Game Engine. Unity has terrific built in integration with VScode, but not with Vim.

Luckily Unity allows for integrating any editor that can accept line and file arguments.

Open up your Unity game/project.

From the tool bar select:

edit > preferences > External Tools

As you can see there is a dropdown that allows for choosing a text editor executable file.

You must create the file first in order to choose it.

Utilities/neovim-unity

#!/bin/bash
gnome-terminal -- nvr --servername unity $@

Lets breakdown this simple file.

  • gnome-terminal is the executable command that opens a new terminal window on my machine. If you use a different terminal the command will be different.

  • nvr --servername unity $@ is the argument, which itself is a command.

  • nvr is the executable command for neovim-remote. This is needed because you are unable to pass server and remote options into neovim like you can for vim.

  • --servername unity is how we name the neovim server instance.

  • $@ allows the Unity Game Editor to pass in File arguments into the (executable) file.

Now you must make the file an executable.

Command Line

cd Utilities
chmod +x neovim-unity

Choose the newly created executable file in the Unity preferences. The external script editor arguments field will appear.

Add the following line:

External Script Editor Args

  --remote-silent +$(Line) $(File)

edit > preferences > External Tools

Now you can open/debug files within the Unity UI and it will automatically open the file in your Vim editor.

However you will notice that the intellisense is most likely not working.

First, we must edit the Neovim-CoC configuration file. Within vim enter the following command:

(Neo)Vim Command

:CocConfig

This will open you configuration file for Neovim-CoC. Add the following lines to the object:

CoC config.json

{
  //...
  "coc.source.OmniSharp.enable" : true,
  "coc.source.OmniSharp.triggerCharacters": ".",
}

Now you must generate the project files so that the OmniSharp server can analyze the project.

In order to do this, switch the External Text Editor option back to “Open by file extension”. (For some reason it will not allow for generating these files when the nvim-unity is selected) You will now have the options to regenerate project files. Make sure the following are checked before regenerating:

  • Embedded Packages
  • Registry Packages
  • Local Packages

edit > preferences > External Tools

Switch the External Text Editor option back to “neovim-unity”. Make sure that the argument field still has the following:

External Script Editor Args

--remote-silent +$(Line) $(File)

edit > preferences > External Tools

Now, upon opening any .cs file within the project, should open in vim, and your OmniSharp server should start up, analyze the project files, and provide you with an IDE like experience.

Side Note

If there are any issues with the OmniSharp server, make sure to follow ALL of the installation instructions at OmniSharp-vim. There are a few different caveats in regards to the operating system you are running.