Color scheme switcher for Vim
Unzip the most recent ZIP archive file inside your Vim profile directory (usually this is
~/.vim on UNIX and
%USERPROFILE%\vimfiles on Windows), restart Vim and execute the command
:helptags ~/.vim/doc (use
:helptags ~\vimfiles\doc instead on Windows). Now try it out: Execute
:NextColorScheme to switch to the next color scheme.
If you didn't change the plug-in's configuration you can now use the
Shift-F8 keys to switch to the next/previous color scheme.
Switch to the next color scheme. After the last color scheme the cycle repeats from the first color scheme.
Switch to the previous color scheme. After the first color scheme the cycle repeats from the last color scheme.
The colorscheme switcher plug-in should work out of the box, but you can change the configuration defaults if you want to change how the plug-in works.
By default the plug-in maps the following keys in insert and normal mode:
F8switches to the next color scheme
Shift-F8switches to the previous color scheme
To disable these mappings (e.g. because you're already using them for a different purpose) you can set the option
g:colorscheme_switcher_define_mappings to 0 (false) in your vimrc script.
If you set this variable to 1 (true) and cycle to the next/previous color scheme, the plug-in will skip color schemes with a different 'background'. By default this is set to 0 (false).
This is useful when you want to see only light or dark color schemes, for example because the sun is shining (you'll want a light background) or because it's late at night (then you'll likely prefer a dark background).
A list with names of color schemes to be ignored by the plug-in. By default the list is empty. Here's an example of how you can set this:
:let g:colorscheme_switcher_exclude = ['default', 'test']
The way Vim color schemes are written isn't really compatible with the idea of quickly switching between lots of color schemes. In my opinion this is an ugly implementation detail of how Vim works internally, in other words I think it's a bug that should be fixed... Here are some references that explain the problem in some detail:
- Vim colorscheme leaves a wake of destruction when switching away
- gVim: remove syntax highlighting groups
Since this behavior hinders cycling through color schemes, the colorscheme switcher plug-in includes a workaround that should hide the problem:
- At startup a dictionary is created which will be used to remember links between highlighting groups;
- Before and after loading a color scheme, the colorscheme switcher plug-in runs the :highlight command without any arguments to find links between highlighting groups. Each link that is found is added to the dictionary. Existing entries are updated. This is done by calling
- After loading a color scheme, the colorscheme switcher plug-in runs the :highlight command without any arguments to find highlighting groups in the state 'cleared'. For each of these groups, if they were previously linked, the link is restored. This is done by calling
Probably this solution is still not perfect, but it's a lot better than the behavior out of the box: Before I implemented the steps above, when I would cycle through my color schemes, Vim would eventually end up with black text on a white background and nothing else! With the steps above, I can cycle as many times as I want and all of the color schemes I've checked so far look fine.
If you have questions, bug reports, suggestions, etc. the author can be contacted at firstname.lastname@example.org. The latest version is available at http://peterodding.com/code/vim/colorscheme-switcher/ and http://github.com/xolox/vim-colorscheme-switcher. If you like this plug-in please vote for it on Vim Online.