自制vim计时小插件: vtimer

来源:互联网 发布:大学物理网络课程 编辑:程序博客网 时间:2024/05/01 19:42
作者:leaforestd | 出处:博客园 | 阅读49次 2012/5/10 22:16:34

转自:http://www.haogongju.net/art/1439549

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

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

 

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

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

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

 

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

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

         Resettime: 总时间清零

 

第一个版本吧, 以后还会改进, 上代码~(木有vimscript格式, 就用bash的highlight了)

 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: leaforestd11 "       Email: leaforestd@gmail.com12 "13 "     Created: May 10 21:28:47 CST 2012 14 "     Version: 1.015 "     History: 1.0 | leaforestd | May 10 21:28:47 CST 2012 | first released16 "17 "=========================================================================1819 function! Vtimer_enter()20     let s:v_start = localtime()21 endfunction2223 function! Vtimer_leave()24     let s:v_end = localtime()25     let s:v_add = s:v_end - s:v_start26     let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])27     let s:v_total = s:v_total + s:v_add28     call writefile([s:v_total], $HOME.'/.vim/vtimer/time')29 endfunction3031 function! Vtimer_show()32     let s:v_total = str2nr(readfile($HOME.'/.vim/vtimer/time')[0])33     let s:v_h = s:v_total / 360034     let s:v_m = (s:v_total % 3600) / 6035     let s:v_s = s:v_total % 6036     echo s:v_h . 'h ' . s:v_m . 'm ' . s:v_s .'s'37 endfunction3839 function! Vtimer_reset()40     call writefile([0], $HOME.'/.vim/vtimer/time')41 endfunction4243 autocmd VimEnter * call Vtimer_enter()44 autocmd VimLeavePre * call Vtimer_leave()4546 command! Showtime call Vtimer_show()47 command! Resettime call Vtimer_reset()http://vimdoc.sourceforge.net/htmldoc/usr_41.html
0 0
原创粉丝点击