This question already has an answer here:

I had to notice that this doesn't work:

let test=128

highlight Normal ctermbg=test

Is it possible to use variables in colorschemes?

marked as duplicate by statox, Ingo Karkat, jamessan, John O'M. Sep 28 '16 at 1:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Vimscript is evaluated exactly like the Ex commands typed in the : command-line. There were no variables in ex, so there's no way to specify them. When typing a command interactively, you'd probably use <C-R>= to insert variable contents:

:sleep <C-R>=timetowait<CR>m<CR>

... but in a script, :execute must be used. All the literal parts of the Ex command must be quoted (single or double quotes), and then concatenated with the variables:

execute 'sleep' timetowait . 'm'