5

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.

1

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.