sponsor Vim development Vim logo Vim Book Ad

basic Tip #468: display date-and-time on status line

 tip karma   Rating 64/45, Viewed by 2387 

created:   May 1, 2003 8:42      complexity:   basic
author:   Dorai Sitaram      as of Vim:   5.7

It didn't seem like an existing tip mentioned this, so:

The following lines in .vimrc or a plugin file will display
the time of day and calender date (some of us need that reminder)
on the editor status line:

set ruler
set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)

It doesn't update time if you issue no keystrokes, but as soon as you
do anything at all in the editor, you will get the current time.

 rate this tip  Life Changing Helpful Unfulfilling 

<<vim windows displaying output inside vim window | The use of  %< instead of % >>

Additional Notes

Anonymous, May 1, 2003 10:47
"My vimrc has the following.  (Some people might find that these
"lines slow down the response of vim too much.)
set laststatus=2 "black status line at bottom of window
"
if has("win32")
   set statusline=%<%f%h%m%r%=%{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff;}\ %l,%c%V\ %P
else
   set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff;}\ %l,%c%V\ %P
endif
Anonymous, May 9, 2003 8:22
Excellent!

I didn't add this to the status line, but I did add it to the pheader (printheader), which uses the same syntax.
That way when I print the file, I can also print the current clock time.  Now: how can I print the file modify time?
Here is my _vimrc (section):
set pheader=%<%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}%=Page\ %N

(filename, time, page N)
[email protected], February 19, 2004 9:15
Wonderful !

I have a other proposal :
Print the last modification time (not the printing time)

set pheader=%<%f%h%m\ %40{strftime(\"%c\",getftime(expand(\"%%\")))}%=Page\ %N

TaD

PS : There is a writing bug in the gvim help at line 4145 of options.txt
the default value is "%<%f%h%m%=Page\ %N" not "%<%f%h%m%=Page %N"
I wasted a lot of time on this macro bug ;)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo