vtimer.vim: 1.1

现在除了统计总时间外, 还能记录用vim写的总行数了~

这里

 

code:

 1 "=========================================================================
 2 "
 3 " FileName: vtimer.vim
 4 " Describle: recording total time spent on vim, and lines you write via vim
 5 " Commands: :Showtime
 6 " show total time on vim
 7 "
 8 " :Resettime
 9 " reset total time
10 "
11 " :Showline
12 " show total line added with vim
13 "
14 " :Resetline
15 " reset total line
16 "
17 " Author: leaforestd
18 " Email: leaforestd@gmail.com
19 "
20 " Created: Sat May 12 07:51:25 CST 2012
21 " Version: 1.0
22 " History: 1.0 | leaforestd | Sat May 12 07:51:25 CST 2012 | first time released
23 " 1.1 | leaforestd | Sat Jul 21 10:13:23 CST 2012 | add a function to count totalline
24 "
25 "=====================totaltime & totalline===============================
26 "
27 "0
28 "0
29 "
30 "=========================================================================
31 
32 function! Vtimer_enter()
33 let s:t_start = localtime()
34 let s:l_start = line("$")    
35 endfunction
36 
37 function! Vtimer_leave()
38 "read file
39 let s:tl_file = readfile($HOME.'/.vim/plugin/vtimer.vim')
40 
41 "time
42 let s:t_inc = localtime() - s:t_start
43 let s:t_total = str2nr(strpart(s:tl_file[26],1))
44 let s:t_total = s:t_total + s:t_inc
45 let s:tl_file[26] = '"'.s:t_total
46 
47 "line
48 let s:l_inc = line("$") - s:l_start
49 if s:l_inc < 0
50 let s:l_inc = 0
51 endif
52 let s:l_total = str2nr(strpart(s:tl_file[27],1))
53 let s:l_total = s:l_total + s:l_inc
54 let s:tl_file[27] = '"'.s:l_total
55 
56 "write file
57 call writefile(s:tl_file, $HOME.'/.vim/plugin/vtimer.vim')
58 endfunction
59 
60 function! Vtimer_Showtime()
61 let s:t_inc = localtime() - s:t_start
62 let s:t_total = str2nr(strpart(readfile($HOME.'/.vim/plugin/vtimer.vim')[26],1))
63 let s:t_total = s:t_total + s:t_inc
64 let s:t_h = s:t_total / 3600
65 let s:t_m = (s:t_total % 3600) / 60
66 let s:t_s = s:t_total % 60
67 echo s:t_h . 'h ' . s:t_m . 'm ' . s:t_s .'s'
68 endfunction
69 
70 function! Vtimer_Showline()
71 let s:l_inc = line("$") - s:l_start
72 let s:l_total = str2nr(strpart(readfile($HOME.'/.vim/plugin/vtimer.vim')[27],1))
73 let s:l_total = s:l_total + s:l_inc
74 echo s:l_total . 'line(s)'
75 endfunction
76 
77 function! Vtimer_Resettime()
78 let s:tl_file = readfile($HOME.'/.vim/plugin/vtimer.vim')
79 let s:tl_file[26] = '"0'
80 call writefile(s:tl_file, $HOME.'/.vim/plugin/vtimer.vim')
81 endfunction
82 
83 function! Vtimer_Resetline()
84 let s:l_file = readfile($HOME.'/.vim/plugin/vtimer.vim')
85 let s:l_file[27] = '"0'
86 call writefile(s:l_file, $HOME.'/.vim/plugin/vtimer.vim')
87 endfunction
88 
89 autocmd VimEnter * call Vtimer_enter()
90 autocmd VimLeavePre * call Vtimer_leave()
91 
92 command! Showtime call Vtimer_Showtime()
93 command! Resettime call Vtimer_Resettime()
94 command! Showline call Vtimer_Showline()
95 command! Resetline call Vtimer_Resetline()
posted @ 2012-07-21 10:48  leaforestd  阅读(199)  评论(0编辑  收藏  举报