vim: implement a stopwatch in vim

79 views
Skip to first unread message

ping

unread,
May 20, 2012, 5:56:26 AM5/20/12
to vim...@googlegroups.com
hi experts/gurus:
I recently use vim to exercise my reading speed , and I use an external
stopwatch application to count in order to be accurately count my time
(in seconds).
while it works that way it's a pain to switch over between vim and that
stopwatch application over and over.
is it possible to have a small stopwatch displaying in the status line,
triggered/reset simply by a key hit?

I did some google search and didn't find anything good on this. I got
following code (leafo...@gmail.com) somewhere but it doesn't work for
my desire:


function! Vtimer_enter()
let s:v_start = localtime()
endfunction

function! Vtimer_leave()
let s:v_end = localtime()
let s:v_add = s:v_end - s:v_start
let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])
let s:v_total = s:v_total + s:v_add
call writefile([s:v_total], $HOME.'/.vim/vtimer/time')
endfunction

function! Vtimer_show()
let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])
let s:v_h = s:v_total / 3600
let s:v_m = (s:v_total % 3600) / 60
let s:v_s = s:v_total % 60
echo s:v_h . 'h ' . s:v_m . 'm ' . s:v_s .'s'
endfunction

function! Vtimer_reset()
call writefile([0], $HOME.'/.vim/vtimer/time')
endfunction

autocmd VimEnter * call Vtimer_enter()
autocmd VimLeavePre * call Vtimer_leave()

command! Showtime call Vtimer_show()
command! Resettime call Vtimer_reset()


thanks!

Christian Brabandt

unread,
May 20, 2012, 7:40:23 AM5/20/12
to vim...@googlegroups.com
Hi ping!

On So, 20 Mai 2012, ping wrote:

> hi experts/gurus:
> I recently use vim to exercise my reading speed , and I use an
> external stopwatch application to count in order to be accurately
> count my time (in seconds).
> while it works that way it's a pain to switch over between vim and
> that stopwatch application over and over.
> is it possible to have a small stopwatch displaying in the status
> line, triggered/reset simply by a key hit?
>
> I did some google search and didn't find anything good on this. I
> got following code (leafo...@gmail.com) somewhere but it doesn't
> work for my desire:

What is wrong with it?


Perhaps the BufTimer¹ Plugin is better suited for you?


¹)http://groups.google.com/group/vim_use/msg/beb8fd135c9c9e01

regards,
Christian
--
Reply all
Reply to author
Forward
0 new messages