Last Updated: February 25, 2016
·
4.848K
· errm

Using Rbenv Ruby From Within Vim (zsh)

So since I switched to using zsh I noticed that my $PATH was getting messed up from within vim.

From the shell my path would look like this:

➜  ~  echo $PATH
/Users/edr/.rbenv/shims:/Users/edr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Then when I started vim my path would look like this:

:!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/edr/.rbenv/shims:/Users/edr/bin

so it seems that for some reason /etc/zshenv gets executed when vim starts, i fixed this by commenting it out, ala thus:

# system-wide environment settings for zsh(1)
#if [ -x /usr/libexec/path_helper ]; then
  #eval `/usr/libexec/path_helper -s`
#fi

Nothing seems to have broken, yet!

So the point of this, so I can do something like this and use my rbenv ruby:

:nmap :w \| !ruby path/to/the/test.rb<Enter>

6 Responses
Add your response

Same thing fixes rvm and a number of other zsh woes. Thanks.

over 1 year ago ·

@csexton good to see it helped

over 1 year ago ·

Worked perfectly for me, thanks!

over 1 year ago ·

Is there a way to override this in the ~/.zshrc so that it can be in version control?

over 1 year ago ·

Ah. Seems to break eval "$(rbenv init -)" in my ~/.zshrc.

over 1 year ago ·

I think there's a better way to do this. Ultimately, /etc/zshenv is sourced with every ZSH shell, including non-interactive. path_helper is needed to fix the path in interactive shells only. If we move /etc/zshenv to /etc/zprofile, it'll only get sourced in login shells, and won't interfere with vim.

sudo mv /etc/{zshenv,zprofile}

More info: https://github.com/sorin-ionescu/prezto/issues/381

This fixed the issue for me, and I was still able to leave the path helper functionality intact.

over 1 year ago ·