Setting up Unity with Vim or VS Code on Linux

The following has been tested on Ubuntu and Arch, although it should work for any distro – just change package names accordingly.

screenshot

If you want to use Vim, feel free to skip the VS Code section – although I’d still recommend setting that up to confirm Mono and OmniSharp are working properly.

# Mono

Arch: mono via pacman. Additionally, having mono-msbuild and mono-msbuild-sdkresolver installed has helped in some cases where OmniSharp wouldn’t start properly.

Ubuntu: Install Mono as described here. I’m pretty sure msbuild is shipped along with the above download.

# .NET SDK

Ubuntu: Install via snap:

sudo snap install --classic dotnet-sdk

VS Code might be unable to locate the dotnet-sdk if installed via snap. You can simply fix it by runnig sudo snap alias dotnet-sdk.dotnet dotnet.

Arch: dotnet-sdk via pacman.

(Skip to Vim)

# VS Code

Ubuntu: Install non-Snap VS Code via the .deb package from here.

sudo apt install ./code*.deb

Arch: Install visual-studio-code-bin from AUR (to get access to all extensions). (More info in the Arch Wiki)

In VS Code: Install the following extensions (File -> Preferences -> Extensions):

  • C# (Microsoft)
  • Unity Code Snippets (Kleber Silva)
  • Unity Snippets (Ycleptic Studios)
  • Unity Tools (Tobiah Zarlez)

Either search for each extension, or install them by running:

code --install-extension ms-dotnettools.csharp
code --install-extension kleber-swf.unity-code-snippets
code --install-extension twxs.cmake
code --install-extension Tobiah.unity-tools

In VSCode’s settings (File -> Preferences -> Settings):

  1. Search omnisharp.path, hit Edit in settings.json, and set it to "latest".
  2. Search omnisharp.useGlobalMono and set to always.
  3. Search omnisharp.useModernNet and uncheck the box.

The extensions will automatically download omnisharp. You should be able to see progress in the Output window of VS Code, if not, it might be a good idea to restart VS Code.

# Unity

On Ubuntu, use the Unity Hub AppImage from here. On Arch, install unityhub. You can find more detailed setup instructions here.

From the Unity Editor, in Edit -> Preferences -> External Tools select VSCode (likely /usr/bin/code). Below, tick the following:

  • Embedded packages
  • Local packages
  • Git packages
  • Built-in packages

and hit Regenerate Project Files.

# Issues opening files

You should be able to double click on the .cs files from within Unity and have VS Code open the file. On some systems there’s an issue where VS Code opens some weird paths with quotation marks in them.

To fix this, open up VS Code by yourself, click File -> Open Folder and select your project directory (the one with the Assets directory in it). VS Code should now ask you which project to open. Choose the .sln file and you should be good to go.

# That’s it!

Now, your VS Code should be smart! Hovering over Unity stuff should display documentation, as seen below.

screenshot

# Bonus Round: Vim

Note: I use neovim. The following has not been tested with regular vim.

To set up neovim integration, I use CoC.

If you use plugged, add the following line to your init.nvim:

Plug 'neoclide/coc.nvim'

The coc-omnisharp extension is deprecated so the csharp-ls language server can be used instead.

On Arch, csharp-ls can be installed from AUR.

After installing, adapt the languageserver section of your coc-settings.json as follows:

  "languageserver": {
    "csharp-ls": {
      "command": "csharp-ls",
      "filetypes": ["cs"],
      "rootPatterns": ["*.csproj", ".vim/", ".git/", ".hg/"]
    }
  }

On startup of neovim, the language server will look for the .sln file. Until I figure out a workaround, this means the editor needs to be started from the Unity project’s root directory.

# Comments

This post is a copy of a GitHub Gist. Feel free to post any comments or additions there. Also, thanks to @jreeee for the Snap Alias tip :)