开发者

Programmatically getting a list of variables

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:

  1. There is no equivalent to this dictionaries if you want to complete options.
  2. Some variables like count (but not g:count or l:count), b:changedtick and, maybe, others are not present in this dictionaries.
  3. Some vim hacker may add key @@@ to dictionary g:, but it won't make expression g:@@@ valid variable name (but adding 000 there will). Though g:["@@@"] will be a valid expression.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜