vim Variables
Variables are easy to define in Vimscript: let my_variable=something
.
They can be used to store user input collected with input('Prompt')
(we typically call inputsave() before and inputrestore() after the input).
We can also get confirmations from the user with confirm('Prompt', 'options', 'default')
. This returns 1 for Ok and 0 for a non-Ok.
Here’s an example:
call inputsave()
let name=input('Name: ')
call inputrestore()
echo name
You can fetch the value of a variable while typing commands by using Ctrl-R followed by the equals sign. Example:
echo "<Ctrl-R>=name<CR>"