-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.vim
334 lines (306 loc) · 8.06 KB
/
Common.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
" =============================================================================
"
" VimPinyin —— Vim 拼音输入法
"
" 作者: ChaiShushan<[email protected]>
" 版权: BSD
"
" =============================================================================
" UTF8无BOM编码
scriptencoding utf-8
" =============================================================================
" 变量类型
" =============================================================================
" {{{
function! VimPinyin_Common_IsIntType(var)
return type(a:var) == type(0)
endfunction
function! VimPinyin_Common_IsFloatType(var)
return type(a:var) == type(0.0)
endfunction
function! VimPinyin_Common_IsStringType(var)
return type(a:var) == type("")
endfunction
function! VimPinyin_Common_IsListType(var)
return type(a:var) == type([])
endfunction
function! VimPinyin_Common_IsDictType(var)
return type(a:var) == type({})
endfunction
function! VimPinyin_Common_IsFuncType(var)
return type(a:var) == type(function("tr"))
endfunction
"}}}
" =============================================================================
" 普通字符类型
" =============================================================================
"{{{
function! VimPinyin_Common_IsSpace(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == char2nr(' ')
endfunction
function! VimPinyin_Common_IsDigit(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode >= char2nr('0') && a:keycode <= char2nr('9')
endfunction
function! VimPinyin_Common_IsLower(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode >= char2nr('a') && a:keycode <= char2nr('z')
endfunction
function! VimPinyin_Common_IsUpper(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode >= char2nr('A') && a:keycode <= char2nr('Z')
endfunction
function! VimPinyin_Common_IsAlpha(keycode)
if VimPinyin_Common_IsLower(a:keycode)
return 1
endif
if VimPinyin_Common_IsUpper(a:keycode)
return 1
endif
return 0
endfunction
function! VimPinyin_Common_IsPunct(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
" [! - /] -> [ 32 - 47]
" [: - @] -> [ 58 - 64]
" [\[- `] -> [ 91 - 96]
" [{ - ~] -> [123 - 126]
if a:keycode >= char2nr('!') && a:keycode <= char2nr('/')
return 1
endif
if a:keycode >= char2nr(':') && a:keycode <= char2nr('@')
return 1
endif
if a:keycode >= char2nr('[') && a:keycode <= char2nr('`')
return 1
endif
if a:keycode >= char2nr('{') && a:keycode <= char2nr('~')
return 1
endif
return 0
endfunction
function! VimPinyin_Common_IsGraph(keycode)
if VimPinyin_Common_IsDigit(a:keycode)
return 1
endif
if VimPinyin_Common_IsAlpha(a:keycode)
return 1
endif
if VimPinyin_Common_IsPunct(a:keycode)
return 1
endif
return 0
endfunction
function! VimPinyin_Common_IsPrint(keycode)
if VimPinyin_Common_IsGraph(a:keycode)
return 1
endif
if VimPinyin_Common_IsSpace(a:keycode)
return 1
endif
return 0
endfunction
"}}}
" =============================================================================
" 控制字符类型
" =============================================================================
"{{{
" <C-\>
function! VimPinyin_Common_IsSwitchKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == 28
endfunction
" <C-^>
function! VimPinyin_Common_IsSettingKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == 30
endfunction
function! VimPinyin_Common_IsEscKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == 27
endfunction
" ???
function! VimPinyin_Common_IsEnterKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == 13
endfunction
function! VimPinyin_Common_IsCandidateKey(keycode)
return a:keycode == char2nr(';')
endfunction
function! VimPinyin_Common_IsBackspaceKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<BS>")
endfunction
function! VimPinyin_Common_IsDeleteKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<Del>")
endfunction
function! VimPinyin_Common_IsPageUpKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<PageUp>")
endfunction
function! VimPinyin_Common_IsPageDownKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<PageDown>")
endfunction
function! VimPinyin_Common_IsLeftKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<Left>")
endfunction
function! VimPinyin_Common_IsRightKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<Right>")
endfunction
function! VimPinyin_Common_IsUpKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<Up>")
endfunction
function! VimPinyin_Common_IsDownKey(keycode)
if !VimPinyin_Common_IsStringType(a:keycode)
return 0
endif
return a:keycode == expand("\<Down>")
endfunction
" =============================================================================
" 鼠标键
" [v:mouse_win, v:mouse_lnum, v:mouse_col]
function! VimPinyin_Common_IsLeftMouse(keycode)
if !VimPinyin_Common_IsStringType(a:keycode) | return 0 | endif
return a:keycode == "\<LeftMouse>" && v:mouse_win > 0
endfunction
function! VimPinyin_Common_IsRightMouse(keycode)
if !VimPinyin_Common_IsStringType(a:keycode) | return 0 | endif
return a:keycode == "\<RightMouse>" && v:mouse_win > 0
endfunction
" =============================================================================
function! VimPinyin_Common_IsUnknowKey(keycode)
if VimPinyin_Common_IsPrint(a:keycode)
return 0
endif
if VimPinyin_Common_IsEnterKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsBackspaceKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsDeleteKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsPageUpKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsPageDownKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsLeftKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsRightKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsUpKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsDownKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsEscKey(a:keycode)
return 0
endif
return 1
endfunction
"}}}
" =============================================================================
" 字符对应输入模式
" =============================================================================
"{{{
function! VimPinyin_Common_IsPinyinModeKey(keycode)
if !VimPinyin_Common_IsAlpha(a:keycode)
return 0
endif
if VimPinyin_Common_IsIExModeKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsU4CModeKey(a:keycode)
return 0
endif
if VimPinyin_Common_IsVEnModeKey(a:keycode)
return 0
endif
return 1
endfunction
function! VimPinyin_Common_IsIExModeKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == char2nr('i')
endfunction
function! VimPinyin_Common_IsU4CModeKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == char2nr('u')
endfunction
function! VimPinyin_Common_IsVEnModeKey(keycode)
if !VimPinyin_Common_IsIntType(a:keycode)
return 0
endif
return a:keycode == char2nr('v')
endfunction
"}}}
" =============================================================================
" 显示相关
" =============================================================================
"{{{
" 清空命令行
function! VimPinyin_Common_ClearCommandBar()
echo ''
if mode() !~ '[in]'
let cmdtype = getcmdtype()
if cmdtype != '@'
let prepre = cmdtype . getcmdline() . "\n"
execute 'echo | echon "' . prepre . '"'
endif
endif
endfunction
" 返回空字符串
function! VimPinyin_Common_ReturnNone()
redrawstatus!
return ""
endfunction
"}}}
" =============================================================================
"{{{1 vim: foldmethod=marker: