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

后端 未结 4 575
北恋
北恋 2021-02-08 02:37

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         


        
相关标签:
4条回答
  • 2021-02-08 03:15

    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

    0 讨论(0)
  • 2021-02-08 03:23

    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.

    0 讨论(0)
  • 2021-02-08 03:32

    I was not able to resolve this with zsh, and ended up using bash for my vim shell.

    Here's what I did:

    1. modified my .zshrc to work with bash
    2. ln -s .zshrc .bashrc
    3. added set shell=bash to my .vimrc file

    and now my vim command-line PATH is equal to my zsh shell PATH.

    0 讨论(0)
  • 2021-02-08 03:33

    I don't use mac or zsh (I am on linux), however I ran into this problem when I ran gvim from the MATE Menu.

    I solved it by adding this to my .vimrc:

    if $PATH !~ "\.rbenv"
        let $PATH="/home/username/.rbenv/shims:/home/username/.rbenv/bin:" . $PATH
    endif
    

    This avoids setting it if you run vim from a terminal, otherwise the rbenv paths would be included twice.

    I tried setting the application to run via a terminal, but that didn't help.

    0 讨论(0)
提交回复
热议问题