Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Unity3D with vim

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

  1. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    129
    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.

    [​IMG]

    [​IMG]

    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
    kmare, Nananaaa, Tak and 8 others like this.
  2. amarok-blue

    amarok-blue

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

    DoctorJellyface

    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:
    159
    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:
    110
    What would be the benefit of using roslyn?
     
  6. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    159
    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:
    129
    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:
    110
    @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:
    [​IMG]

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

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    159
    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. FocusedBit

    FocusedBit

    Joined:
    Jun 24, 2015
    Posts:
    10
    @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:
    129
    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:
    129
    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.
     
    FocusedBit likes this.
  14. FocusedBit

    FocusedBit

    Joined:
    Jun 24, 2015
    Posts:
    10
    @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!

    [​IMG]
     
    Last edited: Nov 17, 2017 at 4:35 AM
    Odd-Redesign likes this.