rubyrubygemsvimload-path

Is there a way to use Gems in Vim's 'embedded' Ruby?


I'm trying to use the tinder gem from inside Vim. I'd like to be able to write to the Vim buffers, so I need to use Vim's embedded Ruby using :ruby as opposed to externally calling !ruby.

I have run gem install tinder with no problems on the command line, but embedded ruby doesn't seem to have the relevant directories on its load path to be able to require it.

I've tried manipulating the load path by trying things like:

:ruby `gem env gempath`.strip.split(':').each { |p| $:.unshift(p) }

... but with little success.

I've also tried a similar thing with:

Gem.path.unshift ...

... but, again, with little success.

I've tried unpacking Tinder and requiring an absolute path, which does seem to work, but unpack doesn't unpack the gem's dependencies, so it cannot find 'faraday', for example. Perhaps I could recursively unpack?

Does anyone have any thoughts on this issue?

I've googled around a lot and looked at the source of projects like Vmail, but as far as I can tell, no one is using Gems within Vim's Ruby. This seems an awful shame.

I'm pretty sure gem native extensions will never work, whatever I try- but I'd be very happy just being able to require pure Ruby gems.

Many thanks.


Solution

  • After hunting around for a long time, it's actually pretty simple.

    The easiest way is to compile Vim against a version of Ruby that's 1.9 or greater. Vim will use whichever Ruby is first in your load path when you compile.

    Then you just need to install gems through the conventional means for the version you compiled with.

    The gems will be available in your load path by default in 1.9 and onwards because they made some changes to the way rubygems gets autoloaded.