Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #358 - Set a random color scheme at startup

Created: November 4, 2002 3:31 Complexity: intermediate Author: Madoka Machitani Version: 6.0 Karma: 11/6 Imported from: Tip#358

This script picks a colorscheme randomly among all available schemes files when vim starts up. This is similar to VimTip341, but differs in that it is independent of other script liblaries, besides the randomness.

Copy & paste the lines below to somewhere appropriate in your .vimrc.

" Create the comma-separated list of colorscheme files 
let s:colors = substitute(globpath(&runtimepath, 'colors/*.vim'), '\n', ',', 'g') 

if strlen(s:colors) 
 " Count the number of color schemes 
 let s:num = strlen(substitute(s:colors, '[^,]\+', '', 'g')) + 1 
 if s:num > 1 
   let s:loop = localtime() % s:num 
   " Rotate the list s:loop times 
   while s:loop 
     let s:colors = substitute(s:colors, '^\([^,]\+\),\(.*\)$', '\2,\1', '') 
     let s:loop = s:loop - 1 
   endwhile 
 endif 
 let s:color = matchstr(s:colors, '^[^,]\+') 
 unlet! g:colors_name 
 execute 'source' s:color 
 " Prevent the message from disappearing 
 redraw 
 echomsg 'Color applied: '.(exists('g:colors_name') ? g:colors_name : '').' ('.s:color.')' 
endif 
unlet! s:colors s:color s:num s:loop 

Please be noted that adding this script might slightly slow down the startup

time of vim. Enjoy!

Comments

It's better to add

redraw 
echo g:colors_name 

at the last.

Anonymous , December 30, 2004 7:43


Advertisement