Hari Krishna Dara wrote:
On Wed, 7 Jun 2006 at 8:10am, Jürgen Krämer wrote:

Hi,

Hari Krishna Dara wrote:
I am trying to use the new vim7 "object-based" features and am stuck
with an issue in using autoload style variables. Save the below as t.vim
in your autoload directory and execute it (:runtime autoload/t.vim).

let t#var = 'something'

let s:hash = {}
function! s:hash.func()
  echomsg 'from numbered function scope: '. g:t#var
endfunction

echomsg 'from global scope: '. t#var
call s:hash.func()
<<<<

you get the below output:

from global scope: something
Error detected while processing function 3:
line    1:
E121: Undefined variable: t#var
E15: Invalid expression: 'from numbered function scope: '. t#var

Is there something wrong that I am doing or is this a bug?
inside a function you have to reference global variables with the "g:"
prefix even if it's an autoload variable, i.e.

  function! s:hash.func()
    echomsg 'from numbered function scope: '. g:t#var
  endfunction

Regards,
Jürgen

Strange... according to the documentation at |autoload|, you can access
them without the g: prefix.

According to the documentation at |global-variables|, omitting g: within a function definition gives you a variable local to the function:

                       *global-variable* *g:var*
Inside functions global variables are accessed with "g:". Omitting this will access a variable local to a function. But "g:" can also be used in any other
place if you like.


This also works when reading a variable that has not been set yet: >

        :let l = foo#bar#lvar

However, when the autoload script was already loaded it won't be loaded again
for an unknown variable.
<<<<

I am still thinking that it is a bug in the code or in the documentation
(or at least needs to be clarified for poor souls like me). Anyway, it
works with the g: prefix, so thanks for pointing this out.



Best regards,
Tony.

Reply via email to