Fandom

Vim Tips Wiki

Display date-and-time on status line

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 468 Printable Monobook Previous Next

created May 1, 2003 · complexity basic · author Dorai Sitaram · version 5.7


The following lines in vimrc will display the time of day and calender date 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.

CommentsEdit

My vimrc has the following (but it can cause a slowdown).

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

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.

set pheader=%<%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}%=Page\ %N

(filename, time, page N)


I have another proposal: Print the last modification time (not the printing time).

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

Also on Fandom

Random Wiki