Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity3D with vim

Discussion in 'Linux' started by Odd-Redesign, Sep 18, 2015.

  1. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    Hey! Since I'm already working with unity on linux as a productive environment, I thought I'd share what makes the possibility to work under linux so good - Being able to use vim and a terminal emulator to work on your sources.

    Why Vim?

    Vim is fast an lightweight. Vim inside your favorite shell let's you keep your hands on the keyboard and automate things with aliases and scripts. Vim can look great and no UI elements blocking you from viewing your code.

    Should I use it too?

    Only if you're comfortable with vim keybindings and already heard of vim plugins. Visit

    http://www.openvim.com/
    http://vim-adventures.com/
    http://vimawesome.com/

    For your pleasure.
    You can always still use MonoDevelop with Unity, it'll run in the background independent of Unity or MD.

    How does it look and feel on linux?

    Good question! That's the most important part. It looks glorious on linux. I'm currently using xfce4 and a customized terminator and I love it.





    How can I have it?

    1. Installing vim is easy, just get it with your favorite package manager.

    2. Using plugins in vim is also easy, but there are several ways. I personally prefer pathogen. Please take a look at https://github.com/tpope/vim-pathogen

    3. These are the plugins I use:

    auto-pairs/
    omnisharp-vim/
    rainbow_parentheses.vim/
    syntastic/
    tagbar/
    vim-airline/
    vim-colorschemes/
    vim-colors-solarized/
    vim-dispatch/
    vim-easymotion/
    vim-multiple-cursors/
    YouCompleteMe/

    4. For Unity AutoCompletion you'll especially depend on omnisharp-vim, Syntastic and YouCompleteMe. Again, there are alternatives, but this is what I use.

    http://vimawesome.com/plugin/youcompleteme
    http://vimawesome.com/plugin/syntastic
    https://github.com/OmniSharp/omnisharp-vim

    There is a detailed documentation for omnisharp-vim which you'll have to follow to install it. It's something like that:

    cd ~/.vim/bundle
    git clone https://github.com/OmniSharp/omnisharp-vim.git
    cd omnisharp-vim
    git submodule update --init --recursive
    cd server
    xbuild

    Which can possibly fail on xbuild. It depends on the mono project, which you can easily install via apt-get or dnf, but(!) can still fail if installed. The crucial part is that you'll have like the new-new version of mono to compile it. Something like 3.2.4 or so should do the trick.

    Also don't forget to compile YouCompleteMe:

    cd ~/.vim/bundle/YouCompleteMe
    ./install.py --clang-completer

    If installed and compiled correctly, you can update your .vimrc to include omnisharp, syntastic and YouCompleteMe.

    Here is my complete vimrc file: https://www.fumiko-game.com/cloud/index.php/s/REB6weWElTZUrU0/download
    And (I guess) only the autocompletion stuff: https://www.fumiko-game.com/cloud/index.php/s/yD6wHIGbBrv3GEr/download

    I'm not sure about everything in my .vimrc, so don't expect a perfect example - It's just what works for me and doesn't let me down.

    How do I know that it works?

    Open a source .cs file in your project and see if vim asks you to open one of the solution files:
    Just choose one (I experienced no difference, don't know if there should be two or just one .sln) and if you've got AutoCompletion on objects and variables you're good to go, that's all we wanted - Proper auto completion for vim that includes Unity's predefined classes.

    ps aux | grep omnisharp

    should show something like:

    That shows us that the OmniSharp Server is running in the background.

    Now just edit your files, mess with your code, save with :w and switch to Unity to auto-compile your efforts. Syntastic will tell you about any typos and bad practice and Unity will tell you if something has gone wrong.

    I hope this helps some people setting up Unity with vim since I've always wanted to do it but I didn't even want to try it under windows since the implementation of vim is so clunky.

    I don't know if I forgot anything important for the installation since I set it all up two weeks ago. Feel free to ask if there are any issues, maybe I can help.
     
    Last edited: Apr 20, 2016
  2. ma1onso

    ma1onso

    Joined:
    Jun 17, 2014
    Posts:
    79
    Eres barbaro, que inteligente (Y)
     
  3. fjalla

    fjalla

    Joined:
    Nov 6, 2012
    Posts:
    73
    Thanks for the great tutorial! I also use vim for nearly everything, thinking about the switch to it from MD, just after I set up the completion stuff.

    Also, I see you use powerline too! Please mention it in the tutorial, since it really makes the whole experience much nicer. You may also want to look at powerline-daemon, which greatly increases powerline's performance. I recently sent a PR to them with a systemd service for it. It got accepted, but will only come in the next release, so you'll have to manually download it if you want ;)

    Also, for those looking for a good colourscheme, I definitely recommend Solarized. Check it out!
     
  4. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    Hi @Odd Redesign -- thanks for your post! I use vim with omnisharp also (on OS X). I've been thinking of changing the omnisharp backend to the new roslyn service as that seems to be where things are headed. Have you done this? If so, would love to hear your experiences! The documentation is pretty sparse so far.
     
  5. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    What would be the benefit of using roslyn?
     
  6. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    Not 100% sure but it's what the OmniSharp folks are most actively working on, it seems, as that is the latest and best tech that Microsoft open-sourced recently. It also apparently is less buggy, e.g. just filed a bug with rename refactoring and was told to switch to roslyn.
     
  7. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    Hey Ghopper21!

    Sounds like an interesting idea. I still cannot get omnisharp-vim working on my laptop, so maybe I'll try out roslyn there. For now, I haven't run into any major issue with omnisharp-server on my main machine (linux mint), so don't see any reason to switch.

    Seems like roslyn is already supported by the omnisharp-vim project: https://github.com/OmniSharp/omnisharp-vim#osx--linux

    I fixed the screenshots in my initial post. Good luck getting roslyn to work, would be glad to hear about whether you have been successful or not.
     
  8. spacepluk

    spacepluk

    Joined:
    Aug 26, 2015
    Posts:
    243
    @Ghopper21 hmm, good to know they are abandoning the old server.
     
  9. mzavoloka

    mzavoloka

    Joined:
    Feb 28, 2015
    Posts:
    4
    I had troubles trying to use roslyn on Ubuntu. The server is like pre-beta-rc-candidate version. I think it's too early to use it. In its readme https://github.com/OmniSharp/omnisharp-roslyn you can see that it fails to build at the moment. Not good:


    But I managed to get omnisharp-vim working. Even with Gtk#.
     
  10. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    170
    Hi vimmers --

    Anyone having problems using vim with the latest 5.3.2 version of Unity?

    I had omnisharp-vim more or less working and now it's even flakier than before, sometimes working for autocompletion/rename/goto def/etc, sometimes not. Also I noticed this behavior that if vim saves a file, Unity will recompile in the background and cause vim to freeze up while it does so.

    I wonder if this has something to do with Unity changing how they handle solution files -- the "Sync to MonoDevelop project" menu command is now "Open C# Project" -- dunno if that's just cosmetic or some deeper change. I also recall seeing some changelog thing about a new way Unity communicates with MonoDevelop -- maybe that is related to these new problems with vim?

    Any thoughts/experiences very welcome!
     
  11. RowdyCoder

    RowdyCoder

    Joined:
    Jun 24, 2015
    Posts:
    28
    @Odd-Redesign ... dude... this was a nice write-up and definitely "buy me a beer worthy." Thanks :)

    I know it's been awhile but are you still using VIM with the latest version of Unity? Any issues? Thanks again.
     
    Odd-Redesign likes this.
  12. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    I am still using it with 5.6.3xf1Linux, but there shouldn't be any issues with newer versions of Unity. The thing about this tutorial is just that it is becoming a bit old now and there might be even better and more complete methods of doing this. I would love to start fresh and come up with a new tutorial, but at the moment I am working on an xbox port, binding me to windows 10 and visual studio. As soon as that is done though.. it might be a good time to get this done. I even have found solutions to double-clicking a .cs file in Unity and adding it to the VIM buffers correctly.

    If you're trying this out and there are any issues blocking your way, please let me know.
     
  13. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    Code (CSharp):
    1. #!/bin/bash
    2. if [ -n $(wmctrl -l | grep Terminator-Vim) ]; then
    3.   mytitle='Terminator-Vim'
    4.   terminator --working-directory="`dirname "$@"`" -x "echo -e '\033]2;'$mytitle'\007' && vim '$@'"
    5. else
    6.   wmctrl -a Terminator-Vim
    7.   setxkbmap de # this might be optional if not on DE keyboard
    8.   xdotool key colon
    9.   filename=$(printf %q "$@")
    10.   xdotool type --delay 1 "e $filename"
    11.   xdotool key Return
    12. fi
    13.  
    14. exit 0
    It's a bit hacky but I am using this as an executable bash script named terminator-vim, which I set as the external editor in Unity. This makes double clicking files open correctly in my current vim-session. Just wanted to add this in case someone wants to reproduce this or wants to write his/her own script.

    It tries to find a window called Terminator-Vim and if it finds it, simulates key input with xdotool to open the file with ":e $filename". If it doesn't find a window, it opens one and initializes Terminator to use the correct directory and uses the file name to start a vim session. Sometimes I have to start Terminator first to initialize a shell session, but after that it works great.
     
    RowdyCoder likes this.
  14. RowdyCoder

    RowdyCoder

    Joined:
    Jun 24, 2015
    Posts:
    28
    @Odd-Redesign I should have mentioned that I was on a MAC. That said, I pretty much had all of the same plugins you suggested and then some due to developing against Node.js / React Stack. The only thing that I needed to do was actually update my version of mono and reinstall YouCompleteMe with the proper interpreter flags to support Csharp.

    So with that said I'm also using MacVim. But the setup you broke down worked with ITerm2, Hyper, and my native terminal. I love VIM. It makes coding a joyful experience for me.

    Below is a screenshot of a tutorial file running in VIM on the latest version of Unity. Autocomplete works, IntelliSense works, ... everything works. I'm good. Thanks!

     
    Last edited: Nov 17, 2017
    Odd-Redesign likes this.
  15. AbhimanyuAryan

    AbhimanyuAryan

    Joined:
    Apr 22, 2015
    Posts:
    32
    I'm using nvim on macos. Also it's not compiled using Python. Can these plugins be used with nvim(not compiled using python)?

    ❯ nvim
    Error detected while processing /Users/abhimanyuaryan/.dotfiles/config/nvim/plugged/omnisharp-vim/plugin/OmniSharp.vim:
    line 8:
    Error: OmniSharp requires Vim compiled with +python
    YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support.
    Error detected while processing /Users/abhimanyuaryan/.dotfiles/config/nvim/plugged/ale/after/plugin/ale.vim:
    line 28:
    E605: Exception not caught: ALE conflicts with Syntastic. Uninstall it, or disable this warning with `let g:ale_emit_conflict_warnings = 0` in your vimrc file, *before* plugins are loaded.
    Press ENTER or type command to continue
     
  16. Joseph-Ferano

    Joseph-Ferano

    Joined:
    Jul 18, 2008
    Posts:
    165
    I used Unity3D with vim for like 3 years. I've been using Rider with IdeaVim recently but I'm not liking it as much. Unfortunately SDB still doesn't have an "attach process" facility, so I might continue to use Rider in the background for when I need debugging, unless you guys are having success with something else.

    However, I'm switching to emacs (with evil of course), so I'll keep you guys posted on my results. Hopefully by next week I have my whole env setup. I tend to use a highly customized config so it'll take a while. Please note I don't mean to troll, instead I think emacs and vim users should unite so we can help each other since both are unix style editors and there's a lot of overlap.
     
    Last edited: Nov 30, 2017
  17. MACHIN3

    MACHIN3

    Joined:
    May 25, 2016
    Posts:
    61
    Thanks for posting this(and starting the thread!). I got this to work wthout xdotool, wmctrl, etc.

    Basically, just put something like this in your shell script.:
    Code (CSharp):
    1. #!/bin/bash
    2. termite  -e "vim --servername unity $@"
    I'm using termite obviously, but notice the --servername parameter. See https://vi.stackexchange.com/questi...xisting-vim-instance-from-an-external-command for more details.

    Then in unity, just pass in the same args that are set by default for gvim:
    Code (CSharp):
    1. --remote-tab-silent +$(Line) "$(File)"
    Voila. All scripts opened from unity, will open as buffers in the "unity vim" instance.

    edit: oh, actually they open as tabs, not buffers. For buffers use the following instead.
    Code (CSharp):
    1. --remote-silent +$(Line) "$(File)"
    eidt2: The above args will also allow for double clicking an error message in the console and jumping to the appropriate line the the script.
     
    Last edited: Dec 19, 2017
    Odd-Redesign likes this.
  18. nscheurich

    nscheurich

    Joined:
    Jul 21, 2015
    Posts:
    1
    I can't seem to choose my Neovim executable as the external script editor in Unity 2017.3.1f1 Personal. It looks like Unity is only allowing me to choose `.app` bundles. Has anyone run into and overcome this?

     
  19. ArtBIT

    ArtBIT

    Joined:
    Apr 16, 2013
    Posts:
    1
    @nick-scheurich You can easily fake an OSX app bundle by simply creating a folder of the same name as your executable bash script, and append an .app extension to it.

    Say you have an executable bash script called `MyScript`, just create a folder named `MyScript.app` and put your script inside, it's simple as that.
     
    FROS7 likes this.
  20. Enrico-Monese

    Enrico-Monese

    Joined:
    Dec 18, 2015
    Posts:
    77
    This could be a good starting point to open terminal vim from Unity (macOS only)
     
  21. nswayze

    nswayze

    Joined:
    Nov 17, 2016
    Posts:
    21
    Super under-rated post. Thank you!
     
  22. dooderino

    dooderino

    Joined:
    Mar 2, 2014
    Posts:
    5
    I'm getting a 404 for the link to your .vimrc file :-(
     
  23. magnusol93

    magnusol93

    Joined:
    Jul 27, 2020
    Posts:
    1
    I created a short video to explain how I got this up and running.

     
    UnityXP7 and MACHIN3 like this.
  24. ruslanzelinskyy

    ruslanzelinskyy

    Joined:
    Apr 7, 2019
    Posts:
    1
    How to attach vimspector debugger (or alternative) to editor/android device?
     
  25. jmengxy

    jmengxy

    Joined:
    Aug 15, 2017
    Posts:
    1
  26. fritzlolpro

    fritzlolpro

    Joined:
    Aug 17, 2020
    Posts:
    1
    upload_2021-5-21_23-46-17.png

    Can't get the autocomplete for Unity methods, for C# stuff it works.
    I use Omnisharp + coc with omnisharp plugin
     
  27. kt2ssh

    kt2ssh

    Joined:
    Dec 26, 2015
    Posts:
    4
    Is it possible to inspect the debugging information by setting breakpoint in VIM?
     
  28. raining_day0513

    raining_day0513

    Joined:
    Dec 3, 2019
    Posts:
    9
    Hi, I did create a folder call nvim-unity.app and put my executable script nvim-unity inside it. But I cannot select it when I click "Browse...". I'm using macOS, could you help?
     
  29. Dream_Code_TM

    Dream_Code_TM

    Joined:
    Jul 19, 2013
    Posts:
    38
    Can someone help with settings for Windows .exe settings for neovim
    How properly set External Script Editor and External Script Editor Args
     
  30. Dark-1-Games

    Dark-1-Games

    Joined:
    Mar 26, 2014
    Posts:
    101
    If anyone is interested, I wrote a unity plugin that allows for easy integration with nvim (it can probably be made to work with vim as well). It is tested and working in Windows and linux, and can probably easily work in OSX as well. I don't currently have access to an OSX machine to test.
    It adds a Neovim option in the editor tools.

    https://github.com/FREEZX/com.unity.nvim
     
    pberck and dan_ginovker like this.