Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm working on improving my .vimrc, and I want to have command inside of it that depends upon whether it is night or day. I'd like to have something like the following in the end:

if isNightTime
  " do something
else
  " some other thing
endif

What's the best way to go about this?

share|improve this question
1  
Have you seen :help time-functions ? –  Raimondi Apr 3 '11 at 19:15
    
Guess I hadn't seen that. I'm sorry for bothering folks before I'd sufficiently studied the documentation! –  Jonathan Sterling Apr 3 '11 at 23:04
1  
I didn't mean it that way, Vim's help can be a bit difficult to work with at first, that's why I pointed that page to you ;) –  Raimondi Apr 4 '11 at 3:55
    
Didn't take any offense! :) Thanks, everyone, for being so helpful. –  Jonathan Sterling Apr 4 '11 at 4:39
    
Just out of curiosity, what are you doing that requires this type of switch? Is it related to a colorscheme? –  Matt Alexander May 3 '11 at 16:15

1 Answer 1

up vote 5 down vote accepted

Using the strftime() funtion is probably the best approach. If you are satsified with one-hour resolution, you could do something like this:

let hour = strftime("%H")
if 6 <= hour && hour < 18
    " do daytime stuff
else
    " do nighttime stuff
endif

See

:help strftime()

and the strftime man page.

share|improve this answer
    
Thanks a lot! Worked perfectly. –  Jonathan Sterling Apr 3 '11 at 23:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.