In a script, I have the following not working code:
set eval(rules[formatoption])=value
where rules
is a dictionary and formatoption
and value
are a variable. I want to make Vim read the variable name from rules[formatoption]
and set it to value
. How can I make Vim set a variable this way? I think there should be a function like setvar(name, value)
or something similar, that sets name
(string) to value
. That line of code would save me from writing about 30 lines of code in a 70 lines script.
Use :execute
:
execute 'set' rules[formatoption] . '=value'
You can also change Vim options via :let &optionname = ...
, but that doesn't help here. There's also the obscure :help curly-braces-names
, but that won't work here, neither.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With