0

I'd like to set a mapping to loop through a list of colorschemes in MacVim.

Ideally, I'd have an array of color schemes like this:

let s:schemes = ['zellner','ron','morning','murphy','peachpuff','torte']

And in a function set the colorscheme to an index of this array:

colorscheme s:schemes[s:schemeindex]

However this above line does not work. Why?

Instead, I use a workaround which works fine:

function SwitchScheme()
    if s:schemeindex == 0
        colorscheme zellner
        s:schemeindex = 1
    elseif s:schemeindex == 1
        colorscheme ron
        s:schemeindex = 2
    ...
    endif
endfunction

My question is, is there a cleaner way to do this? I'd like to pass a variable to the colorscheme setter function but this doesn't seem to be working.

Are these scheme names constants and if so how do you assign them to a variable?

Many thanks.

casaram
  • 474
  • 3
  • 10

1 Answers1

1

:colorscheme is just limited, like some others such as :source, in that it takes the rest of the line literally, i.e. it can't use a VimL expression as argument. This limitation is generally worked around by using :execute, e.g.

execute 'colorscheme '.s:mycolors[current]

This comes from a a color scheme switcher posted at the Vim Tips wiki.

echristopherson
  • 6,974
  • 2
  • 21
  • 31