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>
Written by Ed
Related protips
6 Responses
Same thing fixes rvm and a number of other zsh woes. Thanks.
@csexton good to see it helped
Worked perfectly for me, thanks!
Is there a way to override this in the ~/.zshrc so that it can be in version control?
Ah. Seems to break eval "$(rbenv init -)"
in my ~/.zshrc.
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.