Reputation: 7734
I intend to create a set of options in vimscript as flags that I can then set at runtime to change the behaviour of my script.
How can I create custom option variables, other plugins like NERDTree for example seem to be able to do it...
Upvotes: 4
Views: 699
Reputation: 172510
The set of Vim options (i.e. the stuff that you manipulate with :set
) is fixed. But plugins use variables, usually named g:PluginName_OptionName
or so, to get something very close to options. With the different variable scopes (g:
, b:
, w:
), you can even achieve something like the buffer- or window-local options in Vim: This means that the plugin checks for the existence of the local variable first, and falls back to using the global variable if no local one exists.
Plugins should provide default values for their configuration variables, that can be overridden in the user's .vimrc
. This is achieved by a test like this:
if ! exists('g:PluginName_ConfigItem')
let g:PluginName_ConfigItem = 'default value'
endif
If you plan to publish your plugin, be sure to document the variables and what values they can hold.
Upvotes: 4