On Sat, Jan 2, 2016 at 3:25 PM, Tim Chase <vim@tim.thechases.com> wrote:
> Tripped over the following on Linux & BSD:
>
> bash$ echo $USER
> tim
> bash$ echo $UID
> 1000
> bash$ vim
> :echo $USER
> tim
> :echo $UID
> :echo expand('$UID')
> 1000
>
> Note that the ":echo $UID" didn't actually return anything. Yet
> running it through expand() produced the expected result. I
> confirmed the behavior to make sure that it wasn't some redraw issue,
> using the expression register in insert-mode, inserting =$UID and
> =expand('$UID') and got the same mismatched behavior.
>
> Based on the description of "expr9" at ":help expression-syntax",
> "$VAR" should contain that environment variable's content.
>
> Is there something I'm missing here or reasoning for the difference?
> Or documentation that I missed?
>
> Thanks!
>
> -tim
From the manual pages for login and bash, I see that $USER is set by
login, while $UID is set by bash during startup. However I still see
the behaviour you describe in Console Vim started from a bash shell.
Under ":help expr-env-expand" I see:
Note that there is a difference between using $VAR directly and using
expand("$VAR"). Using it directly will only expand environment variables that
are known inside the current Vim session. Using expand() will first try using
the environment variables known inside the current Vim session. If that
fails, a shell will be used to expand the variable. This can be slow, but it
does expand all variables that the shell knows about. Example: >
:echo $shell
:echo expand("$shell")
The first one probably doesn't echo anything, the second echoes the $shell
variable (if your shell supports it).
I suppose that this might account for the behaviour you see.
FWIW, "echo $shell" returns nothing, even at the bash prompt. $SHELL
is set by login so that is known everywhere.
Best regards,
Tony.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment