Wikia

Vim Tips Wiki

Changes: Display date-and-time on status line

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 26: Line 26:
 
set laststatus=2 "black status line at bottom of window
 
set laststatus=2 "black status line at bottom of window
 
if has("win32")
 
if has("win32")
set statusline=%<%f%h%m%r%=%{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
+
set statusline=%<%f%h%m%r%=%{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
 
else
 
else
set statusline=%&lt;%f%h%m%r%=%{strftime(\"%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&amp;ff}\ %l,%c%V\ %P
+
set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
 
endif
 
endif
 
</pre>
 
</pre>
Line 37: Line 37:
 
That way when I print the file, I can also print the current clock time.
 
That way when I print the file, I can also print the current clock time.
   
set pheader=%&lt;%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}%=Page\ %N
+
set pheader=%<%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}%=Page\ %N
   
 
(filename, time, page N)
 
(filename, time, page N)
Line 44: Line 44:
 
I have another proposal: Print the last modification time (not the printing time).
 
I have another proposal: Print the last modification time (not the printing time).
   
set pheader=%&lt;%f%h%m\ %40{strftime(\"%c\",getftime(expand(\"%%\")))}%=Page\ %N
+
set pheader=%<%f%h%m\ %40{strftime(\"%c\",getftime(expand(\"%%\")))}%=Page\ %N
   
 
----
 
----

Latest revision as of 08:45, September 29, 2008

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

Around Wikia's network

Random Wiki