6

I knew you could scope a variable by prefixing it with g: b:, etc. but I only just discoverred that the prefix itself references a dictionary containing all the scoped variables. For example,

:echo b:c_minlines
50

and

:echo b:
{'c_minlines': 50, 'did_indent': 1, 'current_syntax': 'c', ...}

Is this documented somewhere?

ivan
  • 1,450
  • 1
  • 11
  • 16

1 Answers1

9

Poking around with :helpgrep \<g:\A, I found this is documented under :help internal-variables:

There are several name spaces for variables.  Which one is to be used is
specified by what is prepended:

        (nothing) In a function: local to a function; otherwise: global
|buffer-variable|    b:   Local to the current buffer.
|window-variable|    w:   Local to the current window.
|tabpage-variable|   t:   Local to the current tab page.
|global-variable|    g:   Global.
|local-variable|     l:   Local to a function.
|script-variable|    s:   Local to a |:source|'ed Vim script.
|function-argument|  a:   Function argument (only inside a function).
|vim-variable|       v:   Global, predefined by Vim.

The scope name by itself can be used as a |Dictionary|.  For example, to
delete all script-local variables: >
    :for k in keys(s:)
    :    unlet s:[k]
    :endfor
jamessan
  • 11,045
  • 2
  • 38
  • 53
  • Oh wow, I was staring at that very page and somehow overlooked The scope name by itself can be used as a Dictionary. Thanks! – ivan Jul 08 '17 at 17:43