I'm trying to figure out how to use an environment variable name in a function, passed in as a function argument, i.e.:

function! myautoloadfunc#set_default_env_var(name, value)
  if empty($a:name)
     let $a:name = a:value

call myautoload#set_default_env_var('SOME_VAR', 'SOME_VALUE')

Obviously that doesn't work, I'm pretty sure I can do this with exec, but not sure if there's a more efficient way. Any suggestions?

Edit: It seems that the following works:

call myautoload#set_default_env_var('$SOME_VAR', 'SOME_VALUE')

closed as off-topic by Martin Tournoij Mar 2 '16 at 12:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Martin Tournoij
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Why do you think :execute is not efficient? – romainl Jun 21 '15 at 15:22
  • Ignorance, I suppose. I just don't know. – nfarrar Jun 21 '15 at 15:53
  • 1
    exec 'let $' . name . '=' . string(value) – lcd047 Jun 21 '15 at 15:54
  • Maybe the vim built-in function fnameescape() could help you? – Alex Stragies Aug 11 '15 at 14:02
  • @nfarrar If you found a working solution to your problem it would be better if you could post it as an answer rather than putting it in your question ;-) – statox Aug 12 '15 at 15:33

Browse other questions tagged or ask your own question.