Skip to content
kklobe edited this page Jan 8, 2012 · 7 revisions

Using RVM

RVM set the GEM_HOME and GEM_PATH environment variables which causes Vim to try loading gems from the GEM_HOME, which results in errors even if the gems are actually installed in system ruby. For example the Hammer plugin requires github-markup which is installed automatically by Janus, but GEM_HOME causes rubygems to try loading the gem from that folder instead of the rubygems default folder.

Unless someone come up with a better solution, the only reasonable solution I was able to find is to wrap vim and all the aliases with a function that unset these environment variables, here's a function that does this which you can add to your .bashrc or .zshrc (do not forget to call it after defining it!)

# Define Vim wrappers which unsets GEM_HOME and GEM_PATH before
# invoking vim and all known aliases
#
# @author Wael Nasreddine <[email protected]>
function define_vim_wrappers()
{
  vim_commands=(
    eview evim gview gvim gvimdiff gvimtutor rgview
    rgvim rview rvim vim vimdiff vimtutor xxd mvim
  )

  for cmd in ${vim_commands[@]}; do
    cmd_path=`/usr/bin/env which -a "${cmd}" 2>/dev/null | grep '^/'`
    if [ -x "${cmd_path}" ]; then
      eval "function ${cmd} () { (unset GEM_HOME; unset GEM_PATH; $cmd_path \$@) }"
    fi
  done
}

Call it with

define_vim_wrappers

Using 'rvm system do'

You can also use 'rvm system do ...' to accomplish this. For example, with a homebrew-installed MacVim and rvm defaulted to Ruby 1.9.3, I use the following:

alias mvim='rvm system do /usr/local/bin/mvim $@'
Clone this wiki locally