Friday, May 11, 2012

RE: In function difference "let var" and "let l:var"

Richard wrote:
> In a function is there a difference in scope, visibility,
> usage, etc. between using the "l:"
> local qualifier and not using it?
>
> funcition Foo() {
> let a1 = 4
> let l:a2 = 4
> }

No. The l: is required only if you want a local variable with
the same name as a Vim v: variable (however, it seems that
even then the l: is not always needed). See ':help l:var'.

The following shows typical usage where l: is not needed:

let g1 = 'global value'
function! Try()
let l1 = g:g1 " g1 is error E121: Undefined variable: g1
let g1 = 'local value'
let g:g1 = 'locally set value'
$put =l1 .' '. g1 .' '. g:g1
endfunction

Sourcing the above and entering ':call Try()' gives:

global value local value locally set value

John

--
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

No comments: