When I'm using vim in a terminal, it uses the PATH I have set, and I can run programs and scripts located in my ~/bin folder using !

For example

:! some_bash_script.sh

When I try this in MacVim, it doesnt find my personal shell scripts. How can I fix this?

I've set my shell in my ~/.vimrc like so:

set shell=/bin/zsh

but that doesn't seem to help. I did notice that if I launch MacVim from the command line, it works as expected, i assume because the shell's environment is the environment in which MacVim ends up running in.


$ open -a MacVim.app

Is there a better way to do this? I like launching MacVim using Spotlight, but it doesnt work if I do it that way, only via Terminal.

NOTE: This is similar to this question, but that was for vim, not gvim or MacVim

  • 2
    superuser.com/q/31353/358509 has MacVim solutions for the PATH.
    – chicks
    Mar 29, 2018 at 18:11
  • 1
    Is this about zsh or bash?
    – muru
    Mar 30, 2018 at 1:31
  • I agree with muru's question, and will also say that either shell will read different dotfiles (and thus potentially create different $PATHs) depending on whether it's launched as a login shell, etc. :echo $PATH in MacVim will tell you exactly what $PATH it's seeing, but I'm sure that won't give you additional info. You'll probably need to set your path in a shell dotfile that's read regardless of how the shell is launched.
    – brhfl
    Mar 30, 2018 at 2:02
  • The answer i posted here allows you to use whatever shell you use (as it uses whatever you have set in Terminal).
    – Brad Parks
    Mar 31, 2018 at 22:41

2 Answers 2


I answered a similar question here. The problem is that zsh (and other shells) only runs ~/.zshrc for interactive shells and ~/.zprofile for "login" shells.

To force running commands as a login shell, add the -l flag to either the shell option, or the shellcmdflag option. That is (in your ~/.gvimrc),

set shell=/bin/zsh\ -l
" or
set shellcmdflag=-l\ -c

You need to escape the spaces because of how the set command works. Putting it in your ~/.gvimrc will prevent $PATH from growing when running it from the terminal.

  • hey! I tried this, but couldnt get it to work. I put it in my ~/.vimrc, ~/.gvimrc and the system files used by MacVim, but no difference in executing programs. I tried it with both lines, to no effect (ie - it couldnt find anything I had in my ~/bin folder, which is in my path)
    – Brad Parks
    May 17, 2018 at 11:14
  • Worth noting that $ZDOTDIR/.zshenv is sourced for non-interactive shells, but I wouldn't really recommend customizing $PATH in there.
    – brhfl
    May 17, 2018 at 13:06
  • 1
    Where do you define your path? :! runs commands non-interactively, so you should define $PATH in .zprofile, not .zshrc. Otherwise, I'm out of ideas. I tested and implemented this fix just before writing the answer.
    – jladan
    May 18, 2018 at 14:32
  • @brhfl why not?
    – Bluu
    Nov 21, 2019 at 23:37
  • Only defining $PATH in ~/.zprofile worked for me. Adding the -l flag to the shell or shellcmdflag Vim option like suggested in this answer was unnecessary. This is weird because it means that ~/.zprofile is still read despite Vim running a non-login shell (set shell returns /bin/zsh and set shellcmdflag returns -c by default).
    – Géry Ogam
    Jan 24 at 11:27

So far, my best solution is to launch MacVim using an alternate application launcher, which you can create using AppleScript like so:

  1. Create an apple script like by Running "Script Editor", clicking "New Document", and supplying the following:

    tell application "Terminal"
         do script "open -a MacVim.app; exit"
         delay 5
    end tell
  2. Export that as an application, by

    • choosing "File | Export"
    • choose "File Format" as "Application"
    • Click "Save", and call it whatever you like. I called mine MacVimLauncher.app, and I saved it under Applications
  3. Run that instead of MacVim.app.

Note: If you have MacVim running, you have to shut it down before trying this out. I've had a similar problem with Eclipse in the past, and this should solve that issue as well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.