getVar.vim


Ⅰ. 插件描述

Convenient retrieval of buffer or global script options.

Ⅱ. 基本信息

创建日期:  2002-07-26
使用用户:  1
Github星:  1
插件作者:  Salman Halim

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/getvar-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/getvar-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/getvar-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/getVar.vim

Ⅳ. 文档说明

These are just a few convenience functions that are useful for retrieval of plugin options that can be set globally as well as having buffer-specific over-rides.

Example:  I have a global variable called "g:sortOrder" which is set to "a".  In the test.java buffer, I create a buffer variable called "b:sortOrder" which is set to "d".  Now, GetVar#GetVar( "sortOrder" ) will return "d" when I'm in test.java and "a" everywhere else.  My plugin code doesn't need to actually check for buffer or global variables; I can just call GetVar#GetVar and be done with it.

Why is this useful?  It mimics the behaviour of options.  For example, :set grepprg? will return the value of 'grepprg'; if a local version has been set (:setlocal grepprg=<something>), it will quietly return that.  Otherwise, it will return the global value.  GetVar#GetVar allows the same behaviour for variables.

GetVar#GetVar will take an optional second parameter which will be the default value to return if neither a buffer nor a global variable by the specified name is found (the default default :) is -1).

Example:  GetVar#GetVar( "userID", "NONE" ) will take either a userID or the string "NONE" if there isn't one.  This can be useful where a script should just use an assumed default if the user hasn't specified an override (global or otherwise).

GetVar#VarExists simply returns true if any of the scopes used by GetVar#GetVar exist (in the same order of checking as GetVar#GetVar).

添加新评论