Tip: #884 - Use different color schemes depending on time of day
Created: February 24, 2005 11:43 Complexity: intermediate Author: Johannes Petzold Version: 6.0 Karma: 51/20 Imported from: Tip#884
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 into your _vimrc:
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]}
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
I apologize, of course you have to mark the perl-lines as they're not exactly able to be interpreted as VIM-Commands. These are all the lines you have to place into your _vimrc:
perl <<EOFPERL VIM::DoCommand "color " . {
map --AT--{ref and push(--AT--$a,--AT--$_),[] or $c=$_,[map{$a=[];$_,$c}--AT--{[--AT--$a]}]},
[0 .. 3] => "elflord",
[4 .. 7] => "morning",
[8 .. 14] => "desert",
[15 .. 18] => "evening",
[19 .. 23] => "elflord"
}->{(localtime)[2]}
EOFPERL
Anonymous
, February 24, 2005 11:48
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
NdrOchip--AT--ScampbellPfamily.AbizM - NOSPAM
, February 24, 2005 12:50
Gkrellsun has na nice program for calculating current sun position and sun rise/set times
I use it to tune my colors (a bit lame, but works)
let s:hour=strftime("%H") let s:sunrise=system("echo $((`suninfo -lat 50 -lon 20 | head -n1 | cut -f1 -d:`+1))") let s:sunset=system("echo $((`suninfo -lat 50 -lon 20 | tail -n1 | cut -f1 -d:`+11))") if (s:hour<s:sunset) && (s:hour>s:sunrise)
colorscheme BlackSea
else
colorscheme dante
fi
khorne--AT--leto.homedns.org
, February 24, 2005 13:44
http://www.vim.org/scripts/script.php?script_id=696
Anonymous , February 24, 2005 16:38
What a wonderful tip! It seems that I'll never use it, but what an idea!...
By the way, you may use
autocmd CursorHold * ...
to make Vim change colors at run-time, almost exactly at the time, not only at startup.
Ivan Tishchenko , February 25, 2005 8:25
If you are realy 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
anonymous
, February 27, 2005 5:36
Emacs has calender-mode complete with sunrise,lunar phases all in emacs-lisp, let's see something non trivial from vim users too. Or are we all just web site makers here?
Prem Chopra , March 2, 2005 21:47
How do Highlight two different colors for two different patterns?. Example /Manual <CR> will highlight word "Manual" in yellow,similarly I want to highlight the pattern "Books" in red color.
sivasankar
sivasankar--AT--perftrends.com
, December 1, 2005 5:09