$PATH is different in Vim that in parent shell

559 views
Skip to first unread message

John Magolske

unread,
Jun 23, 2012, 4:24:55 PM6/23/12
to vim...@googlegroups.com
I'm finding that $PATH is different in Vim than in the parent shell.
In a shell I see that $PATH reflects what's in my ~/.zshrc :

% echo $SHELL
/bin/zsh
% echo $PATH
/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/sbin:/usr/bin:\
/home/john/bin:/home/john/git/scripts:/home/john/.cabal/bin:\
/home/john/context/tex/texmf-linux/bin

But within a Vim session launched in that same terminal:

:!echo $SHELL
/bin/zsh
:!echo $PATH
/home/john/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:\
/usr/bin:/usr/sbin:/usr/NX/bin

... $PATH is different. So when using a shell script located in
/home/john/git/scripts in a mapping in my vimrc, it's necessary to
write out the full path to the executable. Seems this should be
easy to figure out, but searching around I can't come up with an
explanation as to why $PATH is different in Vim.

Thanks for any help,

John

--
John Magolske
http://B79.net/contact

Marc Weber

unread,
Jun 23, 2012, 4:35:03 PM6/23/12
to vim_use
You can change PATH in vim (as you can change any env var):

let $PATH='/no-such/dir'

and then try :!echo 'hello world'

your shell will no longer be found.

Why is your vim's PATH different? Don't know

vim -V20/tmp/log will show you all viml lines. grep for PATH.

If this doesn't help you the I don't know how to debug it.

env vars can also be changed for child processes, see man exec.
However this should not happen in your shell.

Marc Weber

Paul

unread,
Jun 23, 2012, 6:59:13 PM6/23/12
to vim...@googlegroups.com
On Saturday, 23 June, 2012 at 21:24:55 BST, John Magolske wrote:
>I'm finding that $PATH is different in Vim than in the parent shell.

It looks like you have your PATH set in two different places. Have a look at :help :! and :help shellcmdflag - set it to -ic to see if it helps.

--

.

John Magolske

unread,
Jun 23, 2012, 8:50:55 PM6/23/12
to vim...@googlegroups.com
* Paul <googl...@rainslide.net> [120623 16:25]:
Yes, after doing :set shellcmdflag=-ic to specify that vim use an
interactive shell I see PATH as what I have set in my ~/.zshrc.
But placing "set shellcmdflag=-ic" in my ~/.vimrc creates a behavior
where when Vim is launched it is immediately suspended and I have to
issue `fg` to bring it to the foreground.

Digging around for where else PATH could be set, I found this in
/etc/zsh/zshenv (came from installing Debian via the grml distro) :

if (( EUID != 0 )); then
PATH="$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:\
/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/games:/usr/NX/bin$ADDONS"
else
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:\
/usr/local/sbin:/usr/local/bin:/usr/NX/bin$ADDONS"
fi

Ah...the same path I see when doing :!echo $PATH in Vim.

Commenting out those lines solved the problem not only for Vim, but
for other applications as well (vifm also saw that non-desired PATH).

Thanks for the helpful clues!
Reply all
Reply to author
Forward
0 new messages