Tip 884 Printable Monobook Previous Next
created February 24, 2005 · complexity intermediate · author Johannes Petzold · version 7.0
If your Vim's version has been compiled with the +perl - feature (type ":echo has('perl')" to find out), you can use the following lines to let Vim choose a different color scheme on startup, depending on the actual time of day. For example, if you want something like this:
- "elflord" from 19 to 4 o'clock in the morning
- "morning" from 4 to 8
- "desert" from 8 to 15
- "evening" from 15 to 19
place the following lines somewhere in your vimrc:
perl <<EOFPERL
VIM::DoCommand "color " . {
map @{ref and push(@$a,@$_),[] or $c=$_,[map{$a=[];$_,$c}@{[@$a]}]},
[0..3] => "elflord",
[4..7] => "morning",
[8..14] => "desert",
[15..18] => "evening",
[19..23] => "elflord"
}->{(localtime)[2]}
EOFPERL
Customize the [interval] => "name-of-colorscheme" - lines to your individual needs.
Notes:
- [0..3] means 00:00 to 03:59.
- Intervals should cover all hours from 0 to 23.
Comments
One doesn't usually need Perl to do this, either. As an example:
let hr= strftime("%H")
if 0 <= hr && hr <= 3
colors elflord
elseif 4 <= hr && hr <= 7
colors morning
elseif 8 <= hr && hr <= 14
colors desert
elseif 15 <= hr && hr <= 18
colors evening
else
colors astronaut
endif
If you are really bored, you can make it change every minute:
let my_color{0}="elflord"
let my_color{1}="morning"
let my_color{2}="desert"
let my_color{3}="ron"
let my_color{4}="ChocolateLiquor"
let my_color{5}="cool"
let my_color{6}="aqua"
let my_color{7}="evening"
let my_color{8}="adrian"
let my_color{9}="oceanDeep"
let my_color{10}="sea"
let my_color{11}="automn"
let my_color{12}="astronaut"
let my_color{13}="adam"
let my_color{14}="asu1dark"
let my_color{15}="automation"
let my_color{16}="astronaut"
let my_color{17}="aiseered"
let my_color{18}="autumn2"
let my_color{19}="autumnleaf"
let my_color{20}="billw"
let my_color{21}="biogoo"
let my_color{22}="blackbeauty"
let my_color{23}="borland"
let my_color{24}="breeze"
let my_color{25}="buttercream"
let my_color{26}="caramel"
let my_color{27}="chela_light"
let my_color{28}="coffee"
let my_color{29}="dante"
let my_color{30}="darkblue"
let my_color{31}="dawn"
let my_color{32}="emacs"
let my_color{33}="fruit"
let my_color{34}="golden"
let my_color{35}="gothic"
let my_color{36}="darkblue2"
let my_color{37}="hhazure"
let my_color{38}="dusk"
let my_color{39}="lanzarotta"
let my_color{40}="lilac"
let my_color{41}="darkdot"
let my_color{42}="manxome"
let my_color{43}="matrix"
let my_color{44}="delek"
let my_color{45}="nedit"
let my_color{46}="midnight2"
let my_color{47}="pablo"
let my_color{48}="rainbow_neon"
let my_color{49}="darkocean"
let my_color{50}="mars"
let my_color{51}="nedit2"
let my_color{52}="robinhood"
let my_color{53}="xemacs"
let my_color{54}="simpleandfriendly"
let my_color{55}="metacosm"
let my_color{56}="tomatosoup"
let my_color{57}="northsky"
let my_color{58}="papayawhip"
let my_color{59}="midnight"
let my_color{60}="peachpuff"
autocmd CursorHold * let mn= strftime("%M")|
\ execute "colors ".my_color{mn}
echo g:colors_name