13

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.

1

10 Answers 10

12

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.

5
  • I would have thought that as well, but I have added a few things '/etc/paths.d/' which show up in Terminal but not with MacVim.
    – donut
    Sep 27, 2009 at 5:37
  • And actually, there's more in my '/etc/paths' file than what's in MacVim's path.
    – donut
    Sep 27, 2009 at 5:47
  • @Donut: well, that is odd. On my machine, if I add something to /etc/paths.d, it shows up the next time I boot MacVim. What format are you putting in there? It should be one item per line, I believe, with a $PATH directory on each line (e.g., /usr/texbin).
    – Telemachus
    Sep 27, 2009 at 11:17
  • I totally missed your first paragraph originally: Choosing to "Launch Vim processes in a login shell" did the trick for me. See my answer.
    – donut
    Feb 3, 2010 at 9:55
  • Does anyone know if current MacVim (Vim 9.0.1276, MacVim r176 on my system) is supposed to Hhave with respect to paths/$PATH (as it's established in user's custom, shell dotfiles)? Mar 11, 2023 at 4:32
9

BTW, the "Launch Vim processes in a login shell" preference is no longer available in MacVim (at least not v7.3). I see that launching MacVim from the Finder gets the wrong path, but launching it from a shell (as "mvim") gets the correct path.

1
  • 1
    You can add $PATH to ~/.zprofile and everything will work
    – keios
    Aug 22, 2021 at 12:52
3

It's not sourced from .bash_profile, but you can use this in your .vimrc:

let $PATH=$PATH . ':/blah/foo'

You have to have the : or it won't be a correct PATH variable.

2
  • I just tried it, and this doesn't seem to change the $PATH for MacVim. I also tested it with Vim in the Terminal (both /usr/bin/vim (from Apple) and /opt/local/bin/vim (from MacPorts), and it seems unnecessary. Vim in the terminal already picks up the proper $PATH as sourced by my dot files.
    – Telemachus
    Sep 26, 2009 at 12:18
  • 1
    I tried this as well to no avail.
    – donut
    Sep 27, 2009 at 10:10
2

I can't believe I didn't see this before. Okay, I can believe it. Anyways, MacVim comes with an option that solves this. Under Preferences just check "Launch Vim processes in a login shell". That's it, it works. Snazzy. Stupid me.

Oops

I accidentally wrote this answer not realizing that Telemachus had already given me the correct answer. Marked his as the answer.

1
  • Glad it's sorted
    – Telemachus
    Feb 14, 2010 at 15:30
2

MacVim will source ~/.zprofile and /etc/profile, so you can put your PATH settings in there.

See https://github.com/b4winckler/macvim/wiki/Troubleshooting#for-zsh-users and this question on Stack Overflow.

(Tested with MacVim version 7.3 (65)).

1

This Mac Dev Center article may be of some use.

1
  • Can't get it to work. Could be doing something wrong. The article suggests adding the 'LSEnvironment' property in an app's 'information property list file' which I assumed to be ~/Library/Preferences/org.vim.MacVim.plist. I made it a dictionary with 'PATH' (also tried 'path' and '$PATH') as the a key and what I want for the path as a string value. Still seems to be pulling PATH from some mysterious source. Screenshot of the plist file
    – donut
    Sep 5, 2009 at 9:42
1

I had no problem adding a file to the paths.d directory. I added a file called mysql, whose contents were:

/usr/local/mysql/bin[Return]

Then I placed this file under the paths.d directory, and changed its ownership to root:wheel. Now the mysql directory is automatically added to my $PATH variable.

I didn't investigate fully, but possibly (a) including the [RETURN] at the end of the line, and/or (b) setting the file ownership to root, might be necessary.

1

I ran into this today. MacVim no longer has the "login shell" option, and editing system-wide files for a user-specific setting is sketchy.

Here's a solution using only vim options (see :help :! and :help shell).

In your ~/.vimrc add the lines

set shell=/bin/bash
set shellcmdflag=-l\ -c

This makes bash your default shell from (Mac)Vim, and adds the -l flag (login shell) to commands invoked with :!{cmd}. When executing :shell, bash is started as an "interactive shell that is not a login shell".

To make the $PATH work, you need to have it set in ~/.bash_profile for :!, and ~/.bashrc for :shell. (See INVOCATION in man bash)

UPDATE: This wasn't necessary on my other computer, so there is likely something else that is the root cause.

1
  • 1
    You can do a similar thing for zsh. Define $PATH in .zprofile, and include the -l flag in either set shell or set shellcmdflag.
    – jladan
    May 16, 2018 at 23:23
0

I know more about unix than about macs, so the following advice may or may not work. Try putting this your .vimrc file:

! source ~/.bash_profile

That might do the trick, but there's a slight caveat: the .bash_profile is only meant to be sourced once. It may contain some non-idempotent commands (things which should only execute once). Case in point:

$PATH += /blah/foo:/bar/etc

The more that gets called, the bigger and more redundant $PATH gets. However, if that's not such a big deal, the recommendation on unix would be to put the one-time command in ~/.bashrc and run source ~/.bashrc from your .vimrc file.

3
  • Neither sourcing .bash_profile or .bashrc worked. I tried manually running :source .bash_profile but it just comes up with a "Not an editor command" error for every command in the file and the same with .bashrc.
    – donut
    Aug 29, 2009 at 1:58
  • sorry...what was I thinking...you might try ! source .bash_profile Aug 29, 2009 at 15:05
  • Tried both .bash_profile and .bashrc but still no go. Here's what I'm using in my .bash_profile to change PATH: 'PATH=/usr/local/bin:/Applications/Espresso.app/Contents/SharedSupport/Tools/:/Applications/MacVim/:$PATH' And in my .bashrc: 'export PATH=/Applications/MAMP/bin/php5/bin:$PATH'. And it's .bash_profile that actually affects my Terminal sessions.
    – donut
    Aug 30, 2009 at 13:57
0

I asked a very similar question On the Vim StackExchange Site and posted an answer there that works for me!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .