Macos – $PATH in Vim doesn’t match Terminal

environment-variablesmacosmacvimpathvim

I'm using MacVim and when I don't launch it from the Terminal (mvim) its $PATH does not include what I have set in my .bash_profile. It only seems to have the default values, /usr/bin:/bin:/usr/sbin:/sbin.

I'm running OS X 10.5.8. Even if I could set it manually in my .vimrc that would be okay, though I would prefer it to pull from the same place as Terminal. I've tried following what one site suggested, adding let $PATH += /blah/foo:/bar/etc to no avail.

Edit/Solution: See my answer below. MacVim has an option to fix this.

Best Answer

MacVim appears to be getting the $PATH in a way that ignores a regular user's custom dotfiles.

I can't say why they prefer to do it this way, but it appears to be true. In the preferences (under the Advanced tab), you can choose to "Launch Vim processes in a login shell", but it only improves the $PATH slightly for me.

The best I can tell, MacVim uses /usr/libexec/path_helper - which in turn uses the items found (1) in the /etc/paths file and (2) anything additional found in the /etc/paths.d/ directory. Any changes made in a user's home directory (via .profile or the like) is ignored.

In a nutshell, you get the OSX defaults, plus any applications that add themselves to /etc/paths.d. (For example, MacTex does so on my system.) So if you want to adjust your MacVim path, one way would be to add a file with items to /etc/paths.d. (I wouldn't directly edit /etc/paths since then you run the risk of the changes being undone by system updates.)

Thanks for letting me know this. I'm off to file a wishlist bug at MacVim.