$ cyanpencil's blog - posts - about - contact

Rotate vim colorscheme between day and night automatically

It happens quite often that I work on my laptop outside during the day. My all-time favourite colorcheme, alduin, gets absolutely killed by sunlight. For this reason, I have to sometimes switch to a light colorscheme.

ouch, my eyes.
Left for the night, right for the day.

Switching manually colorscheme gets tedious after the third time. But it turns out that making it automatic is really simple, just add those lines to your .vimrc:

if strftime('%H') % 19 > 7
	set background=light
	colo lightning
else
	set background=dark
	colo alduin
endif

For now, I’m using lightning as the light themed colorscheme, but I’m not really a fan of it. If you know about one as cool as alduin, let me know via email or Telegram. I really need it.

Note: if you use vim plug to manage your colorschemes, make sure to put the colorscheme command after the call to plug#end(), otherwise you will just end up with the default colorscheme.