You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brandon R. Stoner edited this page Jun 15, 2013
·
2 revisions
Accessing variables
Vimpy provides a variables interface which makes Vim variables act much like
dictionaries. This provides access to the following different types of
variable scopes in your Python scripts:
globals
script
window
tab
buffer
vim
options
registers
environment
As an example, you could see what the mapleader variable is currently set to
like this:
from vimpy import variables
print(variables.globals['mapleader'])
If you aren't sure that a variable exists, you can use Python's in keyword to
make sure that it exists before using it:
from vimpy import variables
if 'mapleader' in variables.globals:
print(variables.globals['mapleader'])
And if you felt like making your own global variable, you could always just
assign it like this:
from vimpy import variables
variables.globals['example'] = 'example data'
In the case that you'd prefer to change the value on the current buffer, you
could also have done it like so:
from vimpy import variables
variables.buffer['example'] = 'example data'
This wraps the variable assignment commands that Vim provides, so you can use
it to easily interact with other plugins by changing their settings just like
you normally do it in VimScript.