简体   繁体   English

有没有办法在Vim的“嵌入式” Ruby中使用Gems?

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

I'm trying to use the tinder gem from inside Vim. 我正在尝试使用Vim内部的tinder宝石。 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 . 我希望能够写入Vim缓冲区,所以我需要使用:ruby而不是从外部调用!ruby来使用Vim的嵌入式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. 我已经在命令行上运行了gem install tinder ,但没有问题,但是嵌入式ruby似乎在其加载路径上没有相关目录就可以要求它。

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. 我尝试解压缩Tinder并需要一个绝对路径,这似乎确实有效,但是解压缩并不能解压缩gem的依赖项,因此,例如,它找不到'faraday'。 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. 我在Google上搜索了很多东西,看了看Vmail之类的项目的来源,但据我所知,没有人在Vim的Ruby中使用Gems。 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. 我敢肯定,无论尝试什么,gem本机扩展都将无法正常工作,但我很高兴能够只需要纯Ruby gem。

Many thanks. 非常感谢。

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. 最简单的方法是针对1.9或更高版本的Ruby编译Vim。 Vim will use whichever Ruby is first in your load path when you compile. 编译时,Vim将使用装载路径中首先使用的Ruby。

Then you just need to install gems through the conventional means for the version you compiled with. 然后,您只需要通过常规方法为所编译的版本安装gem即可。

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. 默认情况下,1.9及更高版本中的宝石将在您的加载路径中可用,因为它们对rubygems的自动加载方式进行了一些更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM