Using vim with the Ruby Version Manager

Just like many other people, I joined the recent hype of going back to vim after using Textmate for a long time.
I have to say it’s good to be back and it’s great using vim’s great capabilities with Ruby development.

However, I stumbled upon one thing that has really caused me trouble, and there is not much solution on the internet.
When using the rails-vim with rvm, it never seemed to call the right ruby version, resulting in missing gems etc. However, when starting a shell via “:shell”, everything worked as expected.

Other people have had this issue as well and some of them created RVM vim plugins which kinda solved the problem. Sorry guys, although your plugins may have other nice features, you have totally missed the point.

After some investigation in the vim source code which is very well written, I figured out a bit which I could have easily found in the help file.. Using “:!command” runs the command in a non-interactive shell by default, while “:shell” obviously opens an interactive shell.

The problem with non-interactive shells is that they don’t load their ~/.(bash, zsh, whatever)rc files (as pointed out here), the place where for most users, RVM is being initialized.

Thankfully, the solution to this is very simple. Just add this to your ~/.vimrc file, and “:!ruby -v” should show you your default Ruby version selected in RVM:

set shellcmdflag=-ic

One thought on “Using vim with the Ruby Version Manager

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.