Tip #211: Rotate color themes
tip karma |
Rating 55/30, Viewed by 5654
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
February 6, 2002 4:48 |
|
complexity: |
|
intermediate |
author: |
|
Mohit Kalra ([email protected]) |
|
as of Vim: |
|
6.0 |
This tip is for those who like to change their vim color themes pretty often. I like different themes just for a change in my work environment. To achieve this just add the following to your .vimrc or _vimrc file.
let themeindex=0
function! RotateColorTheme()
let y = -1
while y == -1
let colorstring = "#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
let x = match(colorstring,"#",g:themeindex)
let y = match(colorstring,"#",x+1)
let g:themeindex = x+1
":echo x y g:themeindex
if y == -1
let g:themeindex = 0
else
let themestring = strpart(colorstring,x+1,y-x-1)
echo("Setting Theme to-> ".themestring)
return ":so $VIMRUNTIME/colors/".themestring
endif
endwhile
endfunction
Change the value of colorstring above by changing the line
let colorstring = "#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
You can add your favorite color themes in this string so that you can rotate between them. Just make sure that any string that you add is in between the # as shown above. Just follow the format above and things will work.
Then assign a key to roate the theme.
map <F8> :execute RotateColorTheme()
Dunno if there are better ways to do the same. I just did a "help eval" and wrote the above.
<< compiling the actual file with gcc |
Setting file attributes without reloading a buffer >>
Additional Notes
Anonymous,
February 7, 2002 1:15
|
note that its usually much better to put things like this as a script file in your $HOME/vimfiles or $HOME/.vim directory instead of in the ~/.vimrc or ~/_vimrc.
that makes the vimrc nice and simple and also portable to earlier versions of vim which might not have some of the things which this function uses for instance.
|
[email protected],
November 24, 2004 17:23
|
Here's a version which automatically picks up all your colorschemes without having to specify them. Handy for trying out new themes a dozen at a time, for instance.
" .vim/plugin/rotate-colors.vim
let themeindex=0
function! RotateColorTheme()
let y = -1
while y == -1
let colorfiles = globpath(&runtimepath;, "colors/*.vim")
let colorstring = substitute(colorfiles, "\n", "#", "g")
let x = match(colorstring,"#",g:themeindex)
let y = match(colorstring,"#",x+1)
let g:themeindex = x+1
if y == -1
let g:themeindex = 0
else
let themestring = strpart(colorstring,x+1,y-x-1)
echo("Setting Theme to -> ".themestring)
return ":so ".themestring
endif
endwhile
endfunction
|
|