sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #341: switch color schemes

 tip karma   Rating 10/4, Viewed by 2854 

created:   October 11, 2002 12:46      complexity:   intermediate
author:   andreas berg      as of Vim:   6.0

This function is similar to the vimtip #211. I did not recognize that s.o.
already wrote a function for that, but this one has one advantage:
It just takes all possible colorschemes in the given directorys and rotates
them. Just put the following code in your .vimrc file:

let SwitchSchemesFiles = globpath("$VIMRUNTIME,$HOME/.vim","colors/*.vim")
let SwitchSchemesIndex = 0

function! SwitchSchemes()
        let sep="\n"
        if g:SwitchSchemesIndex == -1
                let g:SwitchSchemesIndex=0
        endif

        exe "source " . NextElement(g:SwitchSchemesFiles, sep, g:SwitchSchemesIndex)
        let g:SwitchSchemesIndex = NextIndex(g:SwitchSchemesFiles, sep, g:SwitchSchemesIndex + 1)
endfunction

In addition you need the https://www.vim8.org/script.php?script_id=109
Put it in the plugin directory.

If you use e.g. a map to F12, you can easily switch between all
installed themes:
map <f12>  :call SwitchSchemes()<CR>

 rate this tip  Life Changing Helpful Unfulfilling 

<<Visual Select And Search | Remap <ESC> >>

Additional Notes

Anonymous, April 25, 2003 4:52
It might also be useful to output the name of the color scheme after changing it, something like this:

nmap <C-F12> :call SwitchSchemes()<CR>:echo g:colors_name<CR>
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo