Search This Blog

Powered By Blogger

Monday, January 3, 2011

Make a time adaptive vim in Linux

Vi/vim is really the most popular editor under Linux esp. for those advanced users or Linux fans, even though there are dozen of other featured ones including visual editors and the most worthy of mentioning, Emacs for programming gurus.

Here I just got a whimsy yet actually a fortuitous idea, to make this editor of daily use to be adaptive with current local time periods such as morning, noon, evening and other phases of a day.

The snippet  meant to be placed in or tailed at the vim configuration file, as is mostly the /etc/vimrc or $HOME/vimrc, will make the vim editor apply different color scheme that is meaningfully in accordance with the time of period when vim is launched. Additionally, color schemes for other time of period than morning and evening will be changed with the weekday.


" # intelligent colorscheme switching
let weekday=system('date +%u')
let hour=system('date +%H')

" if the shell command gets any exception during execution, nothing will be 
" done on color scheme setting
if !v:shell_error


   " in other time slots than mornings and evenings, scheme to be applied depends 
   " on which the weekday it is today, beginning from 1 as Monday, through 6 as 
   " Saturday and Sunday numbered as 0
    if     1== weekday
        let coloration="elflord"
    elseif 2 == weekday
        let coloration="koehler"
    elseif 3 == weekday
        let coloration="slate"
    elseif 4 == weekday
        let coloration="zellner"
    elseif 5 == weekday
        let coloration="torte"
    elseif 6 == weekday
        let coloration="ron"
    else "Sundays
        let coloration="blue"
    endif 
 
    " exert the color scheme application
    execute "colorscheme ".coloration 
 
    " in mornings, alwasy using the "morning" scheme
    if hour >= 7 && hour <= 10
        let coloration="morning"
    " in evenings, alwasy using the "evening" scheme
    elseif hour >= 18 && hour <= 23
        let coloration="evening"
    endif
 
endif


Just give it a try, you may be intrigued with use of it afterwards like me!

-----------------------------------
other interesting links
-------------------------------------

Full range of vim color scheme implemented in a Google code project
http://vimcolorschemetest.googlecode.com/svn/html/index-c.html

A find-tweaked color scheme for Mac:
http://blog.toddwerth.com/entries/show/8

No comments:

Post a Comment