简体   繁体   English

Vim 将哪个 Ruby 用于:ruby 命令?

[英]Which Ruby does Vim use for :ruby commands?

Vim has support for Ruby commands. Vim 支持 Ruby 命令。 (For more information, please see the :help if-ruby documentation .) These commands can be run using :ruby if +ruby support is enabled (see vim --version ). (有关更多信息,请参阅:help if-ruby文档。)如果启用了+ruby支持,则可以使用:ruby运行这些命令(请参阅vim --version )。 As an example, I can see that I'm currently using v3.0.0 by using:例如,我可以看到我目前正在使用 v3.0.0,方法是:

:ruby print RUBY_VERSION

However, which Ruby installation is this?但是,Ruby安装的是哪个? For example, is it system Ruby, something managed by RVM, or a separate Ruby installation that is built into Vim?例如,是系统 Ruby,由 RVM 管理的东西,还是内置在 Vim 中的单独 Ruby 安装?

Also, is it possible to install Ruby gems to use with :ruby commands?此外,是否可以安装 Ruby gem 以与:ruby命令一起使用?


Details about my installation:关于我的安装的详细信息:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H524
$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 21 2021 06:59:54)
macOS version - x86_64
Included patches: 1-2625
Compiled by Homebrew
[...]
$ vim --version | grep ruby
+cursorshape       +lua               +ruby              +wildmenu
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.4 -mmacosx-version-min=10.15 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.32.1_1/lib/perl5/5.32.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -L/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -lpython3.9 -framework CoreFoundation -lruby.3.0 -L/usr/local/Cellar/ruby/3.0.0_1/lib
$ which -a ruby
/Users/username/.rbenv/shims/ruby
/usr/bin/ruby
$ rbenv versions
  system
* 2.6.5 (set by /Users/username/.rbenv/version)

All this depends on Vim build configuration.这一切都取决于 Vim 构建配置。 :ver output may indicate the following: :ver output 可能表示以下内容:

  • -lang interface for "lang" wasn't compiled at all; -lang的“lang”接口根本没有编译;
  • +lang everything was statically linked into Vim executable; +lang所有内容都静态链接到 Vim 可执行文件中;
  • +lang/dyn interface was linked against dynamic library (dll/so) +lang/dyn接口链接到动态库 (dll/so)

If it's linked dynamically then the library will be searched and loaded on demand by option value (eg :h 'rubydll' ).如果它是动态链接的,那么将根据选项值(例如:h 'rubydll' )搜索和加载库。 In this case it may point to any installation you want.在这种情况下,它可能指向您想要的任何安装。 (Although -DRUBY_VERSION=XX specified at compile-time may still be relevant and Vim may fail to load mismatched library). (尽管在编译时指定的-DRUBY_VERSION=XX可能仍然相关,并且 Vim 可能无法加载不匹配的库)。

You don't mention your platform, or how you installed Vim.您没有提及您的平台,或者您如何安装 Vim。 If we're talking about default behavior, these things matter.如果我们谈论默认行为,这些事情很重要。

Unless you statically compiled Ruby into Vim, it will be whichever Ruby is first in your PATH, or first in fish_user_paths if you use the fish shell. Unless you statically compiled Ruby into Vim, it will be whichever Ruby is first in your PATH, or first in fish_user_paths if you use the fish shell. On macOS and typical desktop Linux distributions like Ubuntu, that's what you should expect out of the box.在 macOS 和典型桌面 Linux 发行版(如 Ubuntu)上,这就是您应该期望的开箱即用。

Other ways to check include:其他检查方法包括:

  1. Using which -a ruby will show you all the rubies in your PATH .使用which -a ruby将向您显示PATH中的所有红宝石。

    If Ruby 3.0.0 is not the first item listed, or not the version installed to /usr/bin/ruby, then you can be pretty sure that something else is managing it.如果 Ruby 3.0.0 不是列出的第一个项目,或者不是安装到 /usr/bin/ruby 的版本,那么您可以很确定其他东西正在管理它。

  2. Check env | fgrep -i ruby检查env | fgrep -i ruby env | fgrep -i ruby for settings from various Ruby managers. env | fgrep -i ruby用于来自各种 Ruby 管理器的设置。

    Version managers usually work by modifying your environment.版本管理器通常通过修改您的环境来工作。 For example, chruby adds CHRUBY_VERSION to the environment, and RUBY_ROOT to set the path for the selected Ruby.例如,chruby 将CHRUBY_VERSION添加到环境中,并将RUBY_ROOT设置为选定的 Ruby 的路径。 Other common version managers will also update the environment in various ways, so this is a good place to look.其他常见的版本管理器也会以各种方式更新环境,所以这里是个不错的看点。

  3. Check your shell initialization files (eg ~/.bashrc ).检查您的 shell 初始化文件(例如~/.bashrc )。

    If you aren't setting up RVM, rbenv, or chruby in your shell's initialization script, then you probably aren't using one of them.如果您没有在 shell 的初始化脚本中设置 RVM、rbenv 或 chruby,那么您可能没有使用其中之一。 Of course, that doesn't preclude the use of symlinks, GNU stow, or other redirections, but if you didn't set them up and aren't working on a multiuser system where someone else may have, then you can be pretty confident that invoking ruby is calling the Ruby that's first in your PATH .当然,这并不排除使用符号链接、GNU stow 或其他重定向,但如果您没有设置它们并且不在其他人可能拥有的多用户系统上工作,那么您可以非常自信调用ruby正在调用 Ruby ,这是您PATH中的第一个。

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

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