I had to notice that this doesn't work:

let test=128

highlight Normal ctermbg=test

Is it possible to use variables in colorschemes?

  • 6
    execute "highlight Normal ctermbg=" . test
    – romainl
    Sep 25, 2016 at 19:05
  • 4
    Note that this is more or less the same question than the one you asked last week vi.stackexchange.com/q/9644/1841 :)
    – statox
    Sep 26, 2016 at 8:14

1 Answer 1


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'