Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my vim command-line path differ from my shell PATH?

e.g.,

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/bin:~/bin:/usr/local/Cellar/python3/3.2.3/bin

$ vim 
:! echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:~/bin:/usr/local/Cellar/python3/3.2.3/bin

I expected them to be the same. Why are they different?

If it makes a difference, here is my shell, vim version and OS version:

$ echo $SHELL
SHELL=/usr/local/bin/zsh

$ /usr/local/bin/zsh --version
zsh 5.0.0 (x86_64-apple-darwin12.0.0)

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 20 2012 13:16:02)
Compiled by [email protected]


$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.8.2
BuildVersion:   12C60

(Mountain Lion)
like image 401
Rob Bednark Avatar asked Nov 15 '12 17:11

Rob Bednark


2 Answers

This is a known problem introduced by Apple in OS X 10.5 Leopard.

If you are using Bash or Zsh and are using non-interactive shells, you are affected.

Running sudo chmod ugo-x /usr/libexec/path_helper will fix you up, but you should take a look at the article to see why.

From this SO answer

like image 95
Dty Avatar answered Oct 04 '22 21:10

Dty


There are many similar questions on stackoverflow and stackexchange.

Your shell executes different *rc files depending on the arguments its given at launch time. Therefore, you need to setup Vim so that it launchs your shell with the right arguments.

The following helps in bash, I'm almost certain there's a similar flag in zsh.

set shell=bash\ -i

See $ man zsh for the right flag and the right execution order.

like image 32
romainl Avatar answered Oct 04 '22 22:10

romainl