Is it possible to get a list of declared variables with a VimL (aka VimScript) expression? I'd like to get the same set of values that will be presented for a command using -complete=expre开发者_StackOverflow中文版ssion
. The goal is to augment that list for use in a user-defined command completion function.
You can use g:
as a dictionary that holds all global variables, so:
let globals = keys(g:)
will give you all the names. The same applies to the other scopes: b:
, s:
, w:
, etc. See :help internal-variables
for the complete list.
You can get something similar using keys of g:
, b:
, t:
, w:
and v:
dictionaries, but beware of the following facts:
- There is no equivalent to this dictionaries if you want to complete options.
- Some variables like
count
(but notg:count
orl:count
),b:changedtick
and, maybe, others are not present in this dictionaries. - Some vim hacker may add key
@@@
to dictionaryg:
, but it won't make expressiong:@@@
valid variable name (but adding000
there will). Thoughg:["@@@"]
will be a valid expression.
精彩评论