time spent editing a file

17 views
Skip to first unread message

Marc Fournier

unread,
Jul 28, 2008, 6:48:35 PM7/28/08
to vim...@googlegroups.com
Hello,

I'm wondering if there is a way to know since when or for how long I
have been editing the current file (better: have this fact displayed
in the statusbar, like when typing CTRL-G).

The idea is to be able to know how long it took to write an email, or
fix a small bug in some code, without having to launch an external
time tracking tool.

Thanks !
Marc


Ben Schmidt

unread,
Jul 28, 2008, 9:40:22 PM7/28/08
to vim...@googlegroups.com

Well, an easy way to start would be to save the time when the buffer
is loaded in a buffer-local variable with an autocommand, then make a
command to display the difference.

augroup TimeSpentEditing
au!
au BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')), 'timestartediting',
system('date +%s'))
augroup END

func! TimeSpentEditing()
let timenow=system('date +%s')
let timespent=timenow-b:timestartediting
let hours=timespent/3600
let minutes=(timespent-hours*3600)/60
let seconds=(timespent-hours*3600-minutes*60)
return printf("%d:%02d:%02d",hours,minutes,seconds)
endfunc

com! TimeSpentEditing echo TimeSpentEditing()

Just put that in ~/.vimrc or ~/.vim/plugin/something.vim and issue
:TimeSpentEditing when you want to see.

It should be easy enough to incorporate the value into your statusline
and have it regularly updated, but that is the field of expertise of
others, and certainly not mine, so I'll leave that for someone else to
help with.

Ben.


Ben Schmidt

unread,
Jul 28, 2008, 10:11:31 PM7/28/08
to vim...@googlegroups.com
Ben Schmidt wrote:
> Marc Fournier wrote:
>> Hello,
>>
>> I'm wondering if there is a way to know since when or for how long I
>> have been editing the current file (better: have this fact displayed
>> in the statusbar, like when typing CTRL-G).
>>
>> The idea is to be able to know how long it took to write an email, or
>> fix a small bug in some code, without having to launch an external
>> time tracking tool.
>
> Well, an easy way to start would be to save the time when the buffer
> is loaded in a buffer-local variable with an autocommand, then make a
> command to display the difference.
[...]

> Just put that in ~/.vimrc or ~/.vim/plugin/something.vim and issue
> :TimeSpentEditing when you want to see.
>
> It should be easy enough to incorporate the value into your statusline
> and have it regularly updated, but that is the field of expertise of
> others, and certainly not mine, so I'll leave that for someone else to
> help with.

But the email line-break monster strikes again. Hopefully this one won't
wrap:

augroup TimeSpentEditing
au!
au BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),
\ 'timestartediting', system('date +%s'))
augroup END

func! TimeSpentEditing()
let timenow=system('date +%s')
let timespent=timenow-b:timestartediting
let hours=timespent/3600
let minutes=(timespent-hours*3600)/60
let seconds=(timespent-hours*3600-minutes*60)
return printf("%d:%02d:%02d",hours,minutes,seconds)
endfunc

com! TimeSpentEditing echo TimeSpentEditing()

Smiles,

Ben.


Ben Schmidt

unread,
Jul 28, 2008, 10:15:06 PM7/28/08
to vim...@googlegroups.com
Ben Schmidt wrote:
> Ben Schmidt wrote:
>> Marc Fournier wrote:
>>> Hello,
>>>
>>> I'm wondering if there is a way to know since when or for how long I
>>> have been editing the current file (better: have this fact displayed
>>> in the statusbar, like when typing CTRL-G).
>>>
>>> The idea is to be able to know how long it took to write an email, or
>>> fix a small bug in some code, without having to launch an external
>>> time tracking tool.
>> Well, an easy way to start would be to save the time when the buffer
>> is loaded in a buffer-local variable with an autocommand, then make a
>> command to display the difference.
> [...]
>> Just put that in ~/.vimrc or ~/.vim/plugin/something.vim and issue
>> :TimeSpentEditing when you want to see.
>>
>> It should be easy enough to incorporate the value into your statusline
>> and have it regularly updated, but that is the field of expertise of
>> others, and certainly not mine, so I'll leave that for someone else to
>> help with.
>
> But the email line-break monster strikes again. Hopefully this one won't
> wrap:

And I found a bug in that version, too...

If I go on like this I'll be picked up by the spam filters...

Anyway, I think this one works fairly well. If someone can share how to
incorporate it into the status line, that would be very cool.

augroup TimeSpentEditing
au!
au VimEnter,BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),


\ 'timestartediting', system('date +%s'))
augroup END

func! TimeSpentEditing()
let timenow=system('date +%s')
let timespent=timenow-b:timestartediting
let hours=timespent/3600
let minutes=(timespent-hours*3600)/60
let seconds=(timespent-hours*3600-minutes*60)
return printf("%d:%02d:%02d",hours,minutes,seconds)
endfunc

com! TimeSpentEditing echo TimeSpentEditing()

Cheers,

Ben.


Ben Schmidt

unread,
Jul 28, 2008, 10:23:08 PM7/28/08
to vim...@googlegroups.com

OK. The number of versions I am posting of this is getting ridiculous,
but I just happened to notice Vim has a built-in strftime function which
would be better to use than the system call...so...

augroup TimeSpentEditing
au!
au VimEnter,BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),

\ 'timestartediting', strftime('%s'))
augroup END

func! TimeSpentEditing()
let timenow=strftime('%s')

Marc Fournier

unread,
Jul 29, 2008, 5:24:33 AM7/29/08
to vim...@googlegroups.com
Hello,


> Well, an easy way to start would be to save the time when the buffer
> is loaded in a buffer-local variable with an autocommand, then make a
> command to display the difference.
>
> augroup TimeSpentEditing

> [...]


>
> Just put that in ~/.vimrc or ~/.vim/plugin/something.vim and issue
> :TimeSpentEditing when you want to see.

Ben, you are my hero of the day ! Thanks a lot, this is exactly what I
was looking for. I must really learn to use these autocommands. It
looks really powerful.

> It should be easy enough to incorporate the value into your statusline
> and have it regularly updated, but that is the field of expertise of
> others, and certainly not mine, so I'll leave that for someone else to
> help with.

This I figured out myself:

:set ruler
:set rulerformat+=%{TimeSpentEditing()}

or:

:set laststatus=2
:set statusline=%{TimeSpentEditing()}

Thanks again !

Marc


Ben Schmidt

unread,
Jul 29, 2008, 8:50:38 AM7/29/08
to vim...@googlegroups.com
> This I figured out myself:
>
> :set ruler
> :set rulerformat+=%{TimeSpentEditing()}
>
> or:
>
> :set laststatus=2
> :set statusline=%{TimeSpentEditing()}

Mmm. It seems to update more often than I was expecting it to with
something that simple. Not constantly up-to-date, but easily workable
since it seems to update on any cursor movement. Nice.

> Thanks again !

You're welcome!

Ben.


Bill McCarthy

unread,
Jul 29, 2008, 12:47:06 PM7/29/08
to Ben Schmidt
On Mon 28-Jul-08 9:23pm -0600, Ben Schmidt wrote:

> OK. The number of versions I am posting of this is getting ridiculous,
> but I just happened to notice Vim has a built-in strftime function which
> would be better to use than the system call...so...

Nice work on the time function. A significant problem is
that the strftime() is not very portable - the %s doesn't
work here on Windows (compiled with MinGW).

Using reltime() and friends appears to be fairly general.
I've taken the liberty of modifying your code and added a
testing map. It reports to milliseconds. This version uses
floating point, so it is limited to 7.2 and later.

augroup TimeSpentEditing
au!
au VimEnter,BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),

\ 'tstart', reltime())
augroup END

fu! TimeSpentEditing()
let secs=round(1000*str2float(reltimestr(reltime(b:tstart))))/1000
let hours=floor(secs/3600)
let minutes=floor((secs-hours*3600)/60)
let seconds=secs-hours*3600-minutes*60
return printf("%0.0f:%02.0f:%06.3f",hours,minutes,seconds)
endf

com! TimeSpentEditing echo TimeSpentEditing()
map <silent> <leader>dt :TimeSpentEditing<CR>

--
Best regards,
Bill

Christian Brabandt

unread,
Jul 29, 2008, 4:34:56 PM7/29/08
to vim...@googlegroups.com
Hi Bill!

On Tue, 29 Jul 2008, Bill McCarthy wrote:

> Using reltime() and friends appears to be fairly general.
> I've taken the liberty of modifying your code and added a
> testing map. It reports to milliseconds. This version uses
> floating point, so it is limited to 7.2 and later.
>
> augroup TimeSpentEditing
> au!
> au VimEnter,BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),
> \ 'tstart', reltime())
> augroup END
>
> fu! TimeSpentEditing()
> let secs=round(1000*str2float(reltimestr(reltime(b:tstart))))/1000
> let hours=floor(secs/3600)
> let minutes=floor((secs-hours*3600)/60)
> let seconds=secs-hours*3600-minutes*60
> return printf("%0.0f:%02.0f:%06.3f",hours,minutes,seconds)
> endf
>
> com! TimeSpentEditing echo TimeSpentEditing()
> map <silent> <leader>dt :TimeSpentEditing<CR>

This is strange. I put this snippet into some file below ~/.vim/plugin
(BTW, this happened also with Bens version).

Now whenever I start vim on the commandline without a filename, it
will load the last file I have edited. E.g. if I now start vim in a
second terminal :ls show this:
,----
| :ls
| 1 "[No Name]" line 1
| 2 %a "/var/tmp/mutt-256bit-1004-15151-4257" line 1
| Press ENTER or type command to continue
`----

I have traced it to the setbufvar call, but do not know a way around
it.
Oh, and the second thing is, the buffer variable will not be set for
buffer 1.

Ah, now I see, if I change the event to BufWinEnter this does not
happen anymore and it seems to work alright.


:version reports

VIM - Vi IMproved 7.2b BETA (2008 Jul 13, compiled Jul 29 2008 00:04:10)
Inklusive der Korrekturen: 1-23
Übersetzt von Christian Brabandt <c...@256bit.org>
Riesige Version ohne GUI. Ein- (+) oder ausschließlich (-) der Eigenschaften:
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic
+emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path
+float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand
+jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap
+menu +mksession +modify_fname +mouse -mouseshape +mouse_dec -mouse_gpm
-mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +multi_byte
+multi_lang -mzscheme -netbeans_intg -osfiletype +path_extra -perl +postscript
+printer +profile -python +quickfix +reltime +rightleft -ruby +scrollbind
+signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save
System-vimrc-Datei: "$VIM/vimrc"
Benutzer-vimrc-Datei: "$HOME/.vimrc"
Benutzer-exrc-Datei: "$HOME/.exrc"
Voreinstellung für $VIM: "/home/chrisbra/local/share/vim"
Übersetzt: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2
Linken: gcc -L/usr/local/lib -o vim -lm -lncurses

regards,
Christian
--
:wq!

Richard Hartmann

unread,
Jul 30, 2008, 9:13:30 AM7/30/08
to vim...@googlegroups.com
On Tue, Jul 29, 2008 at 00:48, Marc Fournier <fou...@gmx.net> wrote:

> I'm wondering if there is a way to know since when or for how long I
> have been editing the current file (better: have this fact displayed
> in the statusbar, like when typing CTRL-G).

No idea if that ties into the way you work, but with ZSH, I am doing
something similar, only for all programs I run from the shell. And yes,
I am not converting seconds to anything, but that is personal
preference.

As always, beware evil GMail linebreaks.


Richard

preexec () {
ZSHRC_LAST_TIME=$SECONDS
ZSHRC_LAST_EXECUTE="1"
}

precmd () {
buildRPS1
}

buildRPS1 () {
autoload colors
colors
RPS1="%(?..%{$fg_bold[grey]%}[%{$fg_no_bold[red]%}%U%?%u%{$fg_bold[grey]%}]%{$fg_no_bold[default]%})
"
if [[ $ZSHRC_LAST_EXECUTE -eq 1 ]]
then
ZSHRC_NEW_TIME=$((SECONDS - ZSHRC_LAST_TIME))
ZSHRC_LAST_EXECUTE="0"
RPS1+="$ZSHRC_NEW_TIME "
fi
RPS1+="%h %D{%T %a %e.%m.%Y}"
}

Bill McCarthy

unread,
Jul 30, 2008, 3:07:01 PM7/30/08
to Christian Brabandt

That is indeed strange. I don't see anything explicitly in the
autocmd to trigger a "normal `0" (open last). Do you have something
like that in your _vimrc?

> Ah, now I see, if I change the event to BufWinEnter this does not
> happen anymore and it seems to work alright.

I don't think so, Christian, that would appear to reset the timer far
too often. If open vim without a file and then press `0 I have a
b:tstart for each buffer. However, if I open vim on the last file
edited with something like (will vary by shell):

gvim "+sil! norm `0"

then my last file has a b:tstart in buffer 2 and buffer 1 is empty
with no b:tstart - so \dt fails in buffer 1.

A possible work around to to also define, in addition to the
autocmd VimEnter,BufRead,BufNew ..., the following:

au BufWinEnter * if !exists('b:tstart')
\| call setbufvar(str2nr(expand('<abuf>')),
\ 'tstart', reltime()) | en

--
Best regards,
Bill

Christian Brabandt

unread,
Jul 30, 2008, 6:11:41 PM7/30/08
to vim...@googlegroups.com
Hi Bill!

The culprit was my viminfo setting:
set viminfo+=%

Steps to reproduce:
1)
Take an empty .vimrc and put the following into it:
,----
| set viminfo+=%


|
| augroup TimeSpentEditing
| au!
| au VimEnter,BufRead,BufNew * call setbufvar(str2nr(expand('<abuf>')),
| \ 'tstart', reltime())
| augroup END

`----

2)save as tempvimrc
3)start vim like the following:
vim -N -u temp_vimrc ~/.vimrc
4) quit vim
5) start vim vim -N -u temp_vimrc

You'll see vim will haved loaded ~/.vimrc

> > Ah, now I see, if I change the event to BufWinEnter this does not
> > happen anymore and it seems to work alright.
>
> I don't think so, Christian, that would appear to reset the timer far
> too often. If open vim without a file and then press `0 I have a

Yeah, I noticed, after I send my last mail. But it would be a good
idea to stop the timer, whenever you leave the buffer, wouldn't it?


regards,
Christian

Bill McCarthy

unread,
Jul 30, 2008, 6:48:31 PM7/30/08
to Christian Brabandt
On Wed 30-Jul-08 5:11pm -0600, Christian Brabandt wrote:

> The culprit was my viminfo setting:
> set viminfo+=%

Yes, that will load buffers when no file is specified - but
why wasn't that working before you used Ben's timer routine?

>> > Ah, now I see, if I change the event to BufWinEnter this does not
>> > happen anymore and it seems to work alright.
>>
>> I don't think so, Christian, that would appear to reset the timer far
>> too often. If open vim without a file and then press `0 I have a
>
> Yeah, I noticed, after I send my last mail. But it would be a good
> idea to stop the timer, whenever you leave the buffer, wouldn't it?

The timer only shows the elapsed time since a buffer is
created or filled by a new file. I don't think Vim has a
autocmd event for leaving a buffer - just for switching
buffers. More specifically, it appears to be missing an
event for switching focus from Vim/Gvim.

After I replaced Ben's use of a non-portable function with a
portable one, I looked at keeping track of time that a
buffer was actually in use. I couldn't find a way to deal
with the most common event of switching to another app.

--
Best regards,
Bill

Christian Brabandt

unread,
Jul 31, 2008, 2:26:18 PM7/31/08
to vim...@googlegroups.com
Hi Bill!

On Wed, 30 Jul 2008, Bill McCarthy wrote:

>
> On Wed 30-Jul-08 5:11pm -0600, Christian Brabandt wrote:
>
> > The culprit was my viminfo setting:
> > set viminfo+=%
>
> Yes, that will load buffers when no file is specified - but
> why wasn't that working before you used Ben's timer routine?

No I do not think it should load the last buffer, should it? As I
understand the help, it should only restore the buffer list.

>
> >> > Ah, now I see, if I change the event to BufWinEnter this does not
> >> > happen anymore and it seems to work alright.
> >>
> >> I don't think so, Christian, that would appear to reset the timer far
> >> too often. If open vim without a file and then press `0 I have a
> >
> > Yeah, I noticed, after I send my last mail. But it would be a good
> > idea to stop the timer, whenever you leave the buffer, wouldn't it?
>
> The timer only shows the elapsed time since a buffer is
> created or filled by a new file. I don't think Vim has a
> autocmd event for leaving a buffer - just for switching
> buffers. More specifically, it appears to be missing an
> event for switching focus from Vim/Gvim.
>
> After I replaced Ben's use of a non-portable function with a
> portable one, I looked at keeping track of time that a
> buffer was actually in use. I couldn't find a way to deal
> with the most common event of switching to another app.

Well you could return the time the cursor stayed in that particular
buffer. I hacked some simple version, but as I only had a Windows
version < 7.2 this looks pretty ugly right now:

augroup TimeSpentEditing
au!
au BufRead,VimEnter,BufNew,BufEnter * call setbufvar(str2nr(expand('<abuf>')),
\ 'tstart', reltime()[0]) | if !exists("b:tdur") |
\ call setbufvar(str2nr(expand('<abuf>')), 'tdur', 0) | endif |
\ if !exists("gtstart") | let gtstart=reltime()[0] | endif
au BufLeave * call setbufvar(str2nr(expand('<abuf>')),
\ 'tdur', b:tdur + reltime()[0] - b:tstart)
augroup END

func! TimeSpentEditing()
let timenow=reltime()[0]
let timespent=reltime()[0] - b:tstart + b:tdur


let hours=timespent/3600
let minutes=(timespent-hours*3600)/60
let seconds=(timespent-hours*3600-minutes*60)

let gtspent=reltime()[0] - g:gtstart
let ghrs=gtspent/3600
let gmin=(gtspent-ghrs*3600)/60
let gsec=(gtspent-ghrs*3600-gmin*60)
return printf("buffer %s: %d:%02d:%02d\t Vim: %d:%02d:%02d",expand("%:t"),hours,minutes,seconds, ghrs,gmin,gsec)
endfunc

com! TimeSpentEditing echo TimeSpentEditing()
map <silent> <leader>dt :TimeSpentEditing<CR>


Mit freundlichen Grüßen
Christian
--
Die Freiheit der Rede hat den Nachteil, daß immer wieder Dummes,
Häßliches und Bösartiges gesagt wird. Wenn wir aber alles in allem
nehmen, sind wir doch eher bereit, uns damit abzufinden, als sie
abzuschaffen.
-- Winston Spencer Churchill

Tony Mechelynck

unread,
Jul 31, 2008, 3:29:20 PM7/31/08
to vim...@googlegroups.com
On 31/07/08 00:48, Bill McCarthy wrote:
[...]

> The timer only shows the elapsed time since a buffer is
> created or filled by a new file. I don't think Vim has a
> autocmd event for leaving a buffer - just for switching
> buffers. More specifically, it appears to be missing an
> event for switching focus from Vim/Gvim.
>
> After I replaced Ben's use of a non-portable function with a
> portable one, I looked at keeping track of time that a
> buffer was actually in use. I couldn't find a way to deal
> with the most common event of switching to another app.
>

Have you tried the FocusGained / FocusLost events? ("Only in the GUI and
a few console versions.")


Best regards,
Tony.
--
'Twas the Night before Crisis

'Twas the night before crisis, and all through the house,
Not a program was working not even a browse.
The programmers were wrung out too mindless to care,
Knowing chances of cutover hadn't a prayer.
The users were nestled all snug in their beds,
While visions of inquiries danced in their heads.
When out in the lobby there arose such a clatter,
I sprang from my tube to see what was the matter.
And what to my wondering eyes should appear,
But a Super Programmer, oblivious to fear.
More rapid than eagles, his programs they came,
And he whistled and shouted and called them by name;
On Update! On Add! On Inquiry! On Delete!
On Batch Jobs! On Closing! On Functions Complete!
His eyes were glazed over, his fingers were lean,
From Weekends and nights in front of a screen.
A wink of his eye, and a twist of his head,
Soon gave me to know I had nothing to dread...

Matt Wozniski

unread,
Jul 31, 2008, 4:01:53 PM7/31/08
to vim...@googlegroups.com
On Thu, Jul 31, 2008 at 2:26 PM, Christian Brabandt wrote:
>
> Hi Bill!
>
> On Wed, 30 Jul 2008, Bill McCarthy wrote:
>
>>
>> On Wed 30-Jul-08 5:11pm -0600, Christian Brabandt wrote:
>>
>> > The culprit was my viminfo setting:
>> > set viminfo+=%
>>
>> Yes, that will load buffers when no file is specified - but
>> why wasn't that working before you used Ben's timer routine?
>
> No I do not think it should load the last buffer, should it? As I
> understand the help, it should only restore the buffer list.

AFAICS, "restore the buffer list" means "create a new hidden buffer
for every file that had been open, then switch to a new buffer". So,
naturally, that restores the last buffer.

~Matt

Christian Brabandt

unread,
Aug 1, 2008, 3:29:14 AM8/1/08
to vim...@googlegroups.com
Hi Matt!

On Thu, 31 Jul 2008, Matt Wozniski wrote:

> AFAICS, "restore the buffer list" means "create a new hidden buffer
> for every file that had been open, then switch to a new buffer". So,
> naturally, that restores the last buffer.

I guess, then something must have prevented it from working correctly
before. But as I did not like that behaviour anyway, I removed '%'
from my viminfo setting and now it is working as expected.


Thanks for all your help.


regards,
Christian
--
:wq!

Bill McCarthy

unread,
Aug 1, 2008, 10:32:08 AM8/1/08
to Tony Mechelynck
On Thu 31-Jul-08 2:29pm -0600, Tony Mechelynck wrote:
>
> On 31/07/08 00:48, Bill McCarthy wrote:
> [...]
>> The timer only shows the elapsed time since a buffer is
>> created or filled by a new file. I don't think Vim has a
>> autocmd event for leaving a buffer - just for switching
>> buffers. More specifically, it appears to be missing an
>> event for switching focus from Vim/Gvim.
>>
>> After I replaced Ben's use of a non-portable function with a
>> portable one, I looked at keeping track of time that a
>> buffer was actually in use. I couldn't find a way to deal
>> with the most common event of switching to another app.

> Have you tried the FocusGained / FocusLost events? ("Only in the GUI and
> a few console versions.")

Yes, found them after writing the above - and the both work
in my Windows console for Vim. I may explore generalizing
the time editing question with those autocmds.

--
Best regards,
Bill

Ben Schmidt

unread,
Aug 1, 2008, 11:22:05 AM8/1/08
to vim...@googlegroups.com
Great teamwork, guys! Full marks for improving portability with
reltime(). I don't really think the milliseconds (or whatever) are
useful to display though. I honestly don't open, edit and save my files
with measurement errors less than that, and it's just wasted space in
the statusline or whatever. The 'pause the timer while using another
app/window' is an interesting idea, too; would be interesting to see
that in action.

At any rate, it seems the approach that would work best with different
viminfo settings etc. would be to use a BufWinEnter autocommand but set
the variable only if not already set. We shouldn't need setbufvar if
using that autocommand, either, so just this should suffice, I think
(and doesn't need float support which a lot of people still won't have):

augroup TimeSpentEditing
au!
au BufWinEnter * if !exists('b:tstart')|let b:tstart=reltime()|en
augroup END

func! TimeSpentEditing()
let secs=str2nr(reltimestr(reltime(b:tstart)))
let hours=secs/3600
let minutes=(secs-hours*3600)/60
let seconds=secs-hours*3600-minutes*60


return printf("%d:%02d:%02d",hours,minutes,seconds)
endfunc

com! TimeSpentEditing echo TimeSpentEditing()


map <silent> <leader>dt :TimeSpentEditing<CR>

Smiles,

Ben.


Bill McCarthy

unread,
Aug 3, 2008, 8:56:20 PM8/3/08
to Ben Schmidt
On Fri 1-Aug-08 10:22am -0600, Ben Schmidt wrote:

> Great teamwork, guys! Full marks for improving portability with
> reltime(). I don't really think the milliseconds (or whatever) are
> useful to display though. I honestly don't open, edit and save my files
> with measurement errors less than that, and it's just wasted space in
> the statusline or whatever. The 'pause the timer while using another
> app/window' is an interesting idea, too; would be interesting to see
> that in action.
>
> At any rate, it seems the approach that would work best with different
> viminfo settings etc. would be to use a BufWinEnter autocommand but set
> the variable only if not already set. We shouldn't need setbufvar if
> using that autocommand, either, so just this should suffice, I think
> (and doesn't need float support which a lot of people still won't have):

It was fun. I've taken what we started and expanded it a
bit. It still used floating point for those that have it
but only prints out to milliseconds. For those using Vim
version 7+, I've added a report capability.

I didn't add status line updates since those are very custom
and they slow down work.

I'll attach it to a new thread called BufTimer - others may
not be reading this thread.

--
Best regards,
Bill

Reply all
Reply to author
Forward
0 new messages