public
Last active

Solarized: Night & Day

  • Download Gist
vimrc
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
" Set colorscheme to solarized
colorscheme solarized
 
" Change the Solarized background to dark or light depending upon the time of
" day (5 refers to 5AM and 17 to 5PM). Change the background only if it is not
" already set to the value we want.
function! SetSolarizedBackground()
if strftime("%H") >= 5 && strftime("%H") < 17
if &background != 'light'
set background=light
endif
else
if &background != 'dark'
set background=dark
endif
endif
endfunction
 
" Set background on launch
call SetSolarizedBackground()
 
" Every time you save a file, call the function to check the time and change
" the background (if necessary).
if has("autocmd")
autocmd bufwritepost * call SetSolarizedBackground()
endif

I revised it slightly to be more efficient by not reloading your whole .vimrc and only changing the background setting when it hasn't already been set to the desired value.

https://gist.github.com/aaronbieber/5604155

@aaronbieber Thanks! The only issue, though, is that it does not have an existing background value work with and thus, launches with the Dark background by default. If it's daytime, it won't be until you save the file that it will change to Light. I've updated my gist to combine yours in a way that works, although, a bit repetitively.

Instead of repeating the logic that is already in the function, replace your second section (starting "Launch vim with light background...") to just call SetSolarizedBackground().

Always be DRY (Don't Repeat Yourself).

@aaronbieber Ah, didn't think about that. Fixed. Thanks!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.