16

Why does the following:

let s:colorschemes = ['synic', 'ir_black']
let s:colorscheme_idx = 0

function! RotateColorscheme()
  let s:colorscheme_idx += 1
  let s:name = s:colorschemes[s:colorscheme_idx]
  echo s:name
  colorscheme s:name
endfunction

not execute the colorscheme? Vim complains with the following error 'cannot find colorschem s:name'. How do I tell it that I want it to derefence that variable and not apply it literally to :colorscheme?

1 Answer 1

16

Have a look at this script from vim.wikia.com which does pretty much what you are asking for.

Key-line seems to be this one:

let nowcolors = 'elflord morning desert evening pablo'
  execute 'colorscheme '.split(nowcolors)[i]
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but do you know why i need to use execute? I didn't need to use execute for the echo line above it? What makes :echo different from :colorscheme?
see :help exe vs. :help echo

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.