/
kata.vim
211 lines (176 loc) · 5.4 KB
/
kata.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
" Vim filetype plugin
" Language: VimKata
" Maintainer: Duane Johnson
" Only do this when not done yet for this buffer
" if exists("b:did_ftplugin")
" finish
" endif
" let b:did_ftplugin = 1
" preserve user's options
let s:save_cpo = &cpo
set cpo&vim
setlocal commentstring=#%s foldmethod=marker
setlocal nospell nohlsearch
setlocal statusline=Time:\ \ Test
function! s:Renumber() range
let b:k_count = 1
exe a:firstline . ',' . a:lastline . "g/^(\\d\\+/s//\\='('.b:k_count/ | let b:k_count += 1"
endfunction
function! s:GroupRenumber()
let group_boundary = '^\[.\{-}\]$'
" Locate the boundary of the group we're in
let firstline = search(group_boundary,'bnW') + 1
let lastline = search(group_boundary, 'nW') - 1
if lastline < 0
let lastline = line('$')
endif
exe firstline . ',' . lastline 'call s:Renumber()'
endfunction
function! s:NextQuestion()
call search("^(\\d\\+)")
normal j
endfunction
function! s:NextQuestionWithPrep()
" call s:StopRecording()
call s:NextQuestion()
call s:ExecutePreparation()
" call s:ClockInit("l")
" call s:StartRecording()
endfunction
function! s:PrevQuestion()
call s:ThisQuestion()
normal k
call s:ThisInput()
endfunction
function! s:ThisQuestion()
call search("^(\\d\\+)", "bc")
endfunction
function! s:ThisInput()
call s:ThisQuestion()
normal j
endfunction
function! s:ThisAnswer()
call s:ThisQuestion()
call search("^>")
normal ll
endfunction
function! s:ThisPreparationLine()
call s:ThisQuestion()
let prepline = search("^<", "nW", search("^(\\d\\+)", "nW"))
return prepline
endfunction
function! s:ExecuteAnswer()
call s:ThisAnswer()
exe "normal \"ay$"
call s:ThisInput()
exe "normal @a"
endfunction
function! s:ExecutePreparation()
let prepline = s:ThisPreparationLine()
if prepline > 0
exe prepline + "G"
normal ll
exe "normal \"ay$"
call s:ThisInput()
exe "normal @a"
else
call s:ThisInput()
end
endfunction
" function! s:ClockInit(scope)
" let l:clock = (strftime("%I") * 3600) + (strftime("%M") * 60) + (strftime("%S"))
" if a:scope == "g"
" let s:kata_clock = l:clock
" elseif a:scope == "l"
" let s:question_clock = l:clock
" endif
" endfunction
" function! s:ClockDiff(scope)
" let l:now = (strftime("%I") * 3600) + (strftime("%M") * 60) + (strftime("%S"))
" if a:scope == "g"
" return (l:now - s:kata_clock)
" elseif a:scope == "l"
" return (l:now - s:question_clock)
" end
" endfunction
" function! s:StartRecording()
" exe "normal qY"
" endfunction
" function! s:StopRecording()
" exe "normal q"
" endfunction
" function! s:ClearRecording()
" let @y = ""
" endfunction
" function! CalcCPM()
" let l:diff = ClockDiff()
" if l:diff <= 0
" return 0
" else
" let l:cpm = strlen(@y) * 60 / l:diff
" return l:cpm
" endif
" endfunction
setlocal updatetime=1000
autocmd! CursorHold * call Timer()
" autocmd! CursorHoldI * call Timer()
function! Timer()
call feedkeys("f\e")
endfunction
" maps
if !hasmapto('<Plug>Renumber')
nmap <unique> <LocalLeader>kr <Plug>Renumber
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>Renumber <SID>Renumber
nnoremap <SID>Renumber ms:1,$ call <SID>Renumber()<CR>`s
if !hasmapto('<Plug>GroupRenumber')
nmap <unique> <LocalLeader>kgr <Plug>GroupRenumber
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>GroupRenumber <SID>GroupRenumber
nnoremap <SID>GroupRenumber ms:call <SID>GroupRenumber()<CR>`s
if !hasmapto('<Plug>NextQuestionWithPrep')
nmap <unique> Q <Plug>NextQuestionWithPrep
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>NextQuestionWithPrep <SID>NextQuestionWithPrep
nnoremap <SID>NextQuestionWithPrep :call <SID>NextQuestionWithPrep()<CR>
if !hasmapto('<Plug>NextQuestion')
nmap <unique> <LocalLeader>kn <Plug>NextQuestion
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>NextQuestion <SID>NextQuestion
nnoremap <SID>NextQuestion :call <SID>NextQuestion()<CR>
if !hasmapto('<Plug>PrevQuestion')
nmap <unique> <LocalLeader>kp <Plug>PrevQuestion
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>PrevQuestion <SID>PrevQuestion
nnoremap <SID>PrevQuestion :call <SID>PrevQuestion()<CR>
if !hasmapto('<Plug>ThisQuestion')
nmap <unique> <LocalLeader>kq <Plug>ThisQuestion
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>ThisQuestion <SID>ThisQuestion
nnoremap <SID>ThisQuestion :call <SID>ThisQuestion()<CR>
if !hasmapto('<Plug>ThisInput')
nmap <unique> <LocalLeader>ki <Plug>ThisInput
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>ThisInput <SID>ThisInput
nnoremap <SID>ThisInput :call <SID>ThisInput()<CR>
if !hasmapto('<Plug>ThisAnswer')
nmap <unique> <LocalLeader>ka <Plug>ThisAnswer
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>ThisAnswer <SID>ThisAnswer
nnoremap <SID>ThisAnswer :call <SID>ThisAnswer()<CR>
if !hasmapto('<Plug>ExecutePreparation')
nmap <unique> <LocalLeader>kx <Plug>ExecutePreparation
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>ExecutePreparation <SID>ExecutePreparation
nnoremap <SID>ExecutePreparation :call <SID>ExecutePreparation()<CR>
if !hasmapto('<Plug>ExecuteAnswer')
nmap <unique> <LocalLeader>ke <Plug>ExecuteAnswer
endif
nnoremap <unique> <buffer> <silent> <script> <Plug>ExecuteAnswer <SID>ExecuteAnswer
nnoremap <SID>ExecuteAnswer :call <SID>ExecuteAnswer()<CR>
" call s:ClockInit("g")
" call s:ClearRecording()
" call s:StartRecording()
" restore user's options
let &cpo = s:save_cpo
" vim:set sw=2: