From the docs, local variables are defined as:
script-variable s: Local to a :source'ed Vim script.
function-argument a: Function argument (only inside a function).
local-variable l: Local to a function.
It seems that a
is the simplest and most narrow -- this can never be user-defined within a function and is only used to reference the variables that were passed to a given function. In other words, I cannot do something like a:name = "Tom"
, and its the only variable type that cannot be defined on the left-hand side.
What would be the difference then between l
and s
? As far as I understand, l:var
can only be done inside a function and is illegal to use outside of a function, and once the function is done the l:var
variable is discarded. And then s:var
I'm not too clear on at all (for example, why can't I call this from the command-line within the function its being used?).
.vimrc
it adds that variable intog:
rather thans:
. Why does a variable defined outside a function in a script belong to theg:
scoope? – David542 Jun 13 '20 at 23:14