How to Use Correct Ruby in Vim? How to Modify $Path in Vim

How to use correct ruby in vim ? How to modify $PATH in VIM?

I did'n t set the shell option in .vimrc, so that it was automatically set to /bin/zsh.

Then I found out that I hab a dublicate initialisation of rbenv: in my .zshrc. I removed the initialisation end $PATH extensioin in .zshrc because that was already handled by the oh-my-zsh rbenv plugin.

Even after that cleanup, the $PATH mangeling still happening so :!echo $PATH

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/games

Setting :set shell=/bin/bash was what helped me, as i can live with bash in my vim: :!echo $PATH

/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/Users/fb/Dropbox/local/bash

Alter $PATH in vim/macvim so as to find the right ruby binary

I don't know if it applies to zsh but depending on how it's started, bash reads some files and not others. Having this line in my ~/.vimrc ensures that $PATH is the same in Vim and in my shell.

set shell=bash\ -i

But it depends on how you start/customize your shell.

See :help 'shell' and zsh's manual.

How to correctly set PATH in gvim?

You don't change your PATH from Vim. It is inherited from the process that launches Vim and that's there, outside of Vim that you must fix your issue.

You didn't tell us how and where you set your PATH, what desktop environment (if any) or even what value you get in GVim, by the way.

-- edit --

When you lauch GVim from the command-line, it inherits your shell's environment variables and you should get the same $PATH with $ gvim as you do with $ vim.

When you start GVim from a menu or an icon, it inherits the desktop environment's PATH which is defined regardless of your shell's PATH so the output of :echo $PATH is different from what you should get in my shell.

In my opinion, the most effective way to get GVim to honor your custom PATH is simply to change the Exec line in its gvim.desktop file from:

Exec=gvim -f %F

to:

Exec=env PATH=/your/complete/path gvim -f %F

How to run the proper version of Ruby when executing through MacVim (!ruby)

The most direct way to specify a ruby is to give its full pathname in the :! command (instead of relying on whichever ruby is found first in the PATH directories):

  • To use the Ruby at /path/to/your/preferred/ruby:

    :!/path/to/your/preferred/ruby %
  • To use RVM-installed ruby-1.9.2-head:

    :!~/.rvm/bin/ruby-1.9.2-head %
  • To use RVM-installed ruby-1.9.2-head with your rails3-dev gemset:

    :!~/.rvm/bin/ruby-1.9.2-head@rails3-dev %

So your map command might end up like this:

:map ,t :w\|:!~/.rvm/bin/ruby-1.9.2-head@rails3-dev %<cr>

It is also usually possible to adjust the effective value of the PATH environment variable so that your desired ruby is the first one found, but it may not always be as simple as you might like. Specifically, the :! commands are processed by the shell configured by the shell Vim option (:set shell? to see its value). The configuration files for that shell may modify the PATH value that Vim gives the shell (compare Vim’s PATH (:echo $PATH) to the PATH that :! commands end up using (:!echo $PATH) to see if your shell’s configuration files might be adjusting the PATH).

You might try modifying the PATH that Vim and its children use like this:

:let $PATH = $HOME . '/.rvm/wrappers/ruby-1.9.2-head@rails3-dev:' . $PATH

You should check the effective PATH with :!echo $PATH and :!which ruby to find whether your shell is further modifying the PATH (maybe :set shell=/bin/sh if you have this problem).

Note: I have never seen this particular use of RVM’s wrapper directories, future versions of RVM may break it. The normal usage is to create a wrapper and invoke it directly out of ~/.rvm/bin (similar to the first part of this post) instead of putting ~/.rvm/wrapper/whatever in the PATH.

How to run the proper version of Ruby when executing through MacVim (!ruby)

The most direct way to specify a ruby is to give its full pathname in the :! command (instead of relying on whichever ruby is found first in the PATH directories):

  • To use the Ruby at /path/to/your/preferred/ruby:

    :!/path/to/your/preferred/ruby %
  • To use RVM-installed ruby-1.9.2-head:

    :!~/.rvm/bin/ruby-1.9.2-head %
  • To use RVM-installed ruby-1.9.2-head with your rails3-dev gemset:

    :!~/.rvm/bin/ruby-1.9.2-head@rails3-dev %

So your map command might end up like this:

:map ,t :w\|:!~/.rvm/bin/ruby-1.9.2-head@rails3-dev %<cr>

It is also usually possible to adjust the effective value of the PATH environment variable so that your desired ruby is the first one found, but it may not always be as simple as you might like. Specifically, the :! commands are processed by the shell configured by the shell Vim option (:set shell? to see its value). The configuration files for that shell may modify the PATH value that Vim gives the shell (compare Vim’s PATH (:echo $PATH) to the PATH that :! commands end up using (:!echo $PATH) to see if your shell’s configuration files might be adjusting the PATH).

You might try modifying the PATH that Vim and its children use like this:

:let $PATH = $HOME . '/.rvm/wrappers/ruby-1.9.2-head@rails3-dev:' . $PATH

You should check the effective PATH with :!echo $PATH and :!which ruby to find whether your shell is further modifying the PATH (maybe :set shell=/bin/sh if you have this problem).

Note: I have never seen this particular use of RVM’s wrapper directories, future versions of RVM may break it. The normal usage is to create a wrapper and invoke it directly out of ~/.rvm/bin (similar to the first part of this post) instead of putting ~/.rvm/wrapper/whatever in the PATH.

Ctags path in vim is different from the shell

When you do :!command or :call system('command') Vim starts a new subshell according to the values of 'shell' and a bunch of other options listed under :help 'shell'. The 'shellcmdflag' option is important because it usually tells your shell how to start (interactive or not, login or not) which usually has an impact on what *rc files are sourced and thus if your environment variables are seen or not.

Please, update your question with these informations:

  • your OS
  • :set shell?
  • :set shellcmdflag?
  • in what *rc file did you change your PATH?

Can I set Vim's 'embedded' ruby path?

Yes, but you'll have to recompile Vim. Vim will compile against whatever Ruby is first in your $PATH at compile time, so you should just be able to download the source and run:

./configure --enable-rubyinterp # + other options you want
make
make install

If you're on OS X using Homebrew, you may wish to just brew install vim or brew install macvim --override-system-vim.

why $PATH in vim and in zsh is different?

Maybe, did you write $PATH in .zshrc? If so, you should use .zshenv.

.zshrc is not loaded when called script commands from vim and some applications.

Or you're using zsh on OS X. You should move /etc/zshenv to /etc/zshrc.

$PATH in vim is different from which in shell? (Mac OSX)

Unfortunately, MacVim won't be affected by paths you set in .profile or .bashrc.

You can set paths affecting all programs on Mac OS X by using the /etc/paths and /etc/paths.d/ mechanisms. More detailed explanation here:

https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x



Related Topics



Leave a reply



Submit