Alex
Alex

Reputation: 121

Problem with Vim's Ruby plugin

I have just installed Vim and when ever I go to open in ruby file I get these errors:

Error detected while processing C:\Program files (x86)\Vim\vimfiles\ftplugin\ruby.vim
line: 76
Encoding::ConverterNotFoundError: code converter not found (UTF-16LE to ASCII-8bit)
line: 93

E121 :Undefined varaible: s:ruby_path
E15: Invalid expression: s:ruby_path
line: 76

NameError: uninitialized constant Gem::Quickloader
line: 93

I have Ruby 192 installed and I get this error even if I update ruby vim files.

These are the two lines those errors are referring to if it helps:

line 76:  ruby VIM::command( 'let s:ruby_path = "%s"' % ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,}) )

line 93: let &l:path = s:ruby_path

Upvotes: 12

Views: 4550

Answers (6)

Allen
Allen

Reputation: 760

If you run RVM and want its default ruby, use:

let g:ruby_path = "/Users/allen/.rvm/rubies/default/bin"

If you set your ruby interpreter in your project .rvmrc file, you can create an environment variable in your .rvmrc:

rvm 1.9.2@projectname --create
export RUBY_BIN=`which ruby | sed 's/ruby$//'`

You can use environment variables in your .vimrc:

let g:ruby_path=$RUBY_BIN

(Note you should also set a default $RUBY_BIN in your .bashrc or .zshrc so this works outside of .rvmrc projects.)

If your ~/.rvm/rubies/default/bin path does not yet exist, you need to set your rvm system default of ruby. At your command prompt or terminal application, enter:

rvm use 1.9.2 --default

using whatever ruby version you need.

Upvotes: 5

David Tchepak
David Tchepak

Reputation: 10484

Updating to the latest release of Ruby 1.9.2 (1.9.2p180 (2011-02-18) at the time of posting) fixed this for me.

I was running 1.9.2p132 or so when I had the problem, which seems to have been patched around Dec 2010. You can check your current version by running ruby -v.

Upvotes: 0

r1pvanwinkle
r1pvanwinkle

Reputation: 63

I opened the file "C:...\vim73\ftplugin\ruby.vim" and right before line 73 or so, where the code reads:

if !exists("s:ruby_path")

I added:

let s:ruby_path = 'C:\ruby192\bin'

So far vim seems happier about editing ruby files. Note I installed my ruby in the "C:" directory instead of "Program Files" to get a better pathname to ruby.exe.

My version of ruby.vim is dated 2010 Mar 15.

Upvotes: 0

mr_stru
mr_stru

Reputation: 151

Note that instead of editing ruby.vim file you can just add

let g:ruby_path = ':C:\ruby192\bin'

in your _vimrc file (or equivalent for your platform). That way you won't need to keep re-editing ruby.vim when you update it.

Upvotes: 15

Marek Sapota
Marek Sapota

Reputation: 20608

Your problem is probably Ruby 1.9 - AFAIK Vim only works with Ruby 1.8, so you might have to downgrade your Ruby version to get Vim working.

Upvotes: 0

the Tin Man
the Tin Man

Reputation: 160611

How did you install Ruby?

Go into irb and enter:

Gem.all_load_paths.uniq

which should return a list of paths to your install gems that Gem knows about also.

That's what is failing in your error message and leads me to suspect you are missing some path or environment info, because it looks like vim isn't able to find your Ruby gems correctly.

Encoding::ConverterNotFoundError is a core library exception, so that part is working, but it looks like the Gem command isn't working.

Upvotes: 0

Related Questions