自制vim计时小插件: vtimer

之前看了 这篇文章 里面提到了 "勇敢地编程10000小时",

也对 10000小时天才理论 挺感兴趣, 自己准备这么做.

 

so, 如何实现呢? 第一点就是, 如何测量这个时间呢?

这时候, 一个统一的编辑器的优势就体现出来了, 就记录在花在这上面的时间不就行了嘛.

特别是, 这里 还有其脚本语言的介绍~

 

5月1号开始了解vimscript语言, 走走停停弄了一周(好慢..), 这个语言的number, string和list纠结了好一会, 而且不给错误信息非常蛋疼. 今晚终于弄好了..

命令: Showtime: 显示总共用在vim上的时间: 小时 分 秒

         Resettime: 总时间清零

 

第一个版本吧, 以后还会改进, 上代码~

可能的改进:

1.这个插件是放在~/.vim/plugin/下, totaltime存在~/.vim/vtimer/下的time中, 只有一行. 这个浪费了, 改成就存在自身的一行中, 用注释.

2.:Showtime显示的是这次启动vim之前的总时间, 改成显示到现在的总时间.

下次改进后上传到vim.org去.

 1 "=========================================================================
 2 "
 3 "    FileName: vtimer.vim
 4 "  Describle: automatic timer to measure time spent with vim
 5 "   Commands: :Showtime    
 6 "                  show totaltime used
 7 "              :Resettime
 8 "                  reset totaltime
 9 "
10 "      Author: leaforestd
11 "       Email: leaforestd@gmail.com
12 "
13 "     Created: May 10 21:28:47 CST 2012 
14 "     Version: 1.0
15 "     History: 1.0 | leaforestd | May 10 21:28:47 CST 2012 | first released
16 "
17 "=========================================================================
18 
19 function! Vtimer_enter()
20     let s:v_start = localtime() 
21 endfunction
22 
23 function! Vtimer_leave()
24     let s:v_end = localtime()
25     let s:v_add = s:v_end - s:v_start
26     let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])
27     let s:v_total = s:v_total + s:v_add
28     call writefile([s:v_total], $HOME.'/.vim/vtimer/time')
29 endfunction
30 
31 function! Vtimer_show()
32     let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])
33     let s:v_h = s:v_total / 3600
34     let s:v_m = (s:v_total % 3600) / 60
35     let s:v_s = s:v_total % 60
36     echo s:v_h . 'h ' . s:v_m . 'm ' . s:v_s .'s'
37 endfunction
38 
39 function! Vtimer_reset()
40     call writefile([0], $HOME.'/.vim/vtimer/time')
41 endfunction
42 
43 autocmd VimEnter * call Vtimer_enter()
44 autocmd VimLeavePre * call Vtimer_leave()
45 
46 command! Showtime call Vtimer_show()
47 command! Resettime call Vtimer_reset()

 

posted @ 2012-05-10 22:11  leaforestd  阅读(324)  评论(0编辑  收藏  举报