Reply to message «Re: Way to skip systemwide vimrc?», 
sent 08:53:14 13 May 2011, Friday
by Ben Schmidt:

> That's a nice piece of Vimscript. Probably overkill for this situation,
> at least if only run at startup before there are likely to be any local
> variables, but it's still pretty cool.
>
> Now if we just had a way to do script vars....
Without ability to purge script variables this code should not be used after 
plugins are sourced: for example, you will render all my plugins useless 
because 
they use script variables as guards (and also check for particular global 
variables to provide a way for user to disable them, but only if they are 
defined before plugin is sourced for the first time) and this code purges out 
everything that can be used for invoking a plugin.

For now you can use a workaround: add something like
    execute g:RegisterScriptVariable
at the start of each plugin, where
    let g:RegisterScriptVariable='call RegScriptVar(s:, expand("<sfile>"))'
and
    let s:svars={}
    function RegScriptVar(sdict, sfile)
        let s:svars[a:sfile]=a:sdict
    endfunction
. Then you will be able to purge script variables by emptying dictionaries 
inside s:vars.

Original message:
> >      call map(keys(g:), 'remove(g:, v:val)')
> >      call map(filter(range(1, bufnr('$')), 'bufexists(v:val)'),
> >      
> >              \'map(keys(getbufvar(v:val, "")), '.
> >              \    '"remove(getbufvar(".v:val.", \"\"), v:val)")')
> >      
> >      let curtabnr=tabpagenr()
> >      for tabnr in range(1, tabpagenr('$'))
> >      
> >          for winnr in range(1, tabpagewinnr(tabnr, '$'))
> >          
> >              let windict=gettabwinvar(tabnr, winnr, '')
> >              call map(keys(windict), 'remove(windict, v:val)')
> >          
> >          endfor
> >          execute 'tabn' tabnr
> >          call map(keys(t:), 'remove(t:, v:val)')
> >      
> >      endfor
> >      execute 'tabn' curtabnr
> >      unlet tabnr curtabnr winnr
> > 
> > It will clear all variables: global, buffer, window, tabpage for all
> > buffers, windows and tab pages.
> 
> That's a nice piece of Vimscript. Probably overkill for this situation,
> at least if only run at startup before there are likely to be any local
> variables, but it's still pretty cool.
> 
> Now if we just had a way to do script vars....
> 
> > It does not uses redirections which I do not like.
> 
> I don't like them either. But since they were needed for other parts of
> the solution, I just used them again for consistency.
> 
> >      for s:group in split(s:augroups)
> >      
> >          exec "autocmd! ".s:group
> >          unlet s:group
> >      
> >      endfor
> > 
> > You forgot to delete the augroup itself:
> >      for s:group in split(s:augroups)
> >      
> >          exec "autocmd! ".s:group
> >          execute 'augroup!' s:group
> >          unlet s:group
> >      
> >      endfor
> 
> True!
> 
> Ben.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to