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. >>>> 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. -- Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com