-
Notifications
You must be signed in to change notification settings - Fork 5
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.