Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal ruby error in vim

Tags:

vim

ruby

I've been having this problem for a while with vim. The first time I do anything that interacts with ruby, such as :ruby puts "test", I get <internal:gem_prelude>:1:in 'require': cannot load such file -- rubygems.rb (LoadError).

Some diagnostic information that may be useful : my OS is OS X 10.11.2, Vim is version 7.4, ruby is 2.1.2 installed with rvm, my shell is zsh (but this also happens with bash), and my vim is completely vanilla.

 $  ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
 $  rvm list

rvm rubies

=* ruby-2.1.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

 $  which -a ruby
/Users/marcusbuffett/.rvm/rubies/ruby-2.1.2/bin/ruby
/usr/local/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
 $  vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 18 2016 09:07:16)
MacOS X (unix) version
Included patches: 1-1401
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+channel         -gettext         -mzscheme        +textobjects
+cindent         -hangul_input    +netbeans_intg   +title
-clientserver    +iconv           +packages        -toolbar
+clipboard       +insert_expand   +path_extra      +user_commands
+cmdline_compl   +job             +perl            +vertsplit
+cmdline_hist    +jumplist        +persistent_undo +virtualedit
+cmdline_info    +keymap          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python          +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      -lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xsmp
+emacs_tags      -mouseshape      -sniff           -xterm_clipboard
+eval            +mouse_dec       +startuptime     -xterm_save
+ex_extra        -mouse_gpm       +statusline      -xpm
+extra_search    -mouse_jsbterm   -sun_workshop
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang   -L. -L/Users/travis/.sm/pkg/active/lib -fPIC -Bstatic -fstack-protector -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -framework Python   -lruby-static -framework CoreFoundation -lobjc -L/Users/marcusbuffett/.rvm/rubies/ruby-2.1.2/lib
like image 763
Marcus Buffett Avatar asked Mar 18 '16 16:03

Marcus Buffett


1 Answers

Assuming that ruby works for you normally when using from the command line, I suspect that the problem comes from the fact that you are trying to use a RVM ruby in VIM and VIM doesn't use a login shell by default. RVM, on the other hand has it's initialization done in the shell init scripts, which are run only in login shells, which you get e.g. when you open a terminal.

Now, as you have also a system ruby installed in /usr/local, VIM sees this system ruby instead of the RVM one. And I guess you don't have rubygems installed in the system ruby.

So, one quick method is to force VIM to use the login shell, so that it behaves the same way as your command line. This is answered in this SO question, and I quote from there:

# ~/.vimrc
set shell=bash\ -l

Another option would be to manually set the VIM PATH so that the first found ruby is the one from RVM, not the system one.

like image 63
Matouš Borák Avatar answered Oct 13 '22 05:10

Matouš Borák