History
Article Edit this page Discussion

Set a random color scheme at startup

From Vim Tips Wiki

Jump to: navigation, search

Tip 358 Previous Next Created: November 4, 2002 Complexity: intermediate Author: Madoka Machitani Version: 6.0


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 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

Adding this script might slightly slow down the startup.

[edit] Comments

It's better to add

redraw
echo g:colors_name

at the last.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Set a random color scheme at startup"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation