-
Notifications
You must be signed in to change notification settings - Fork 2
/
vim.vch
executable file
·278 lines (244 loc) · 14.6 KB
/
vim.vch
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
# Voice mappings for vim (enabled applications )
# 051213: tan modified
# 260414: tan - changes for compatibility with intellij IDEA vim plug-in
# : inserting "Wait(200)" between ":" and Ex cmds
# : using "Repeat(..)" for multiple undo/redo actions instead of the action prefixed
# with a number of repeats
# : keep core vim 7 commands and move plug-in commands to separate header file
# vim.vch
include keys.vch;
# common ranges
<0to9> := 0..9;
<2to9> := 2..9;
<1to30> := 1..30;
# vim versions of text editing Mappings established in vocola general commands
# ---------------------------------------------------------------------------
# Text Editing
#
<direction> := Left | Right | Up | Down;
<left_right> := (Left={b} | Right={w});
<top_bottom> := (Top={Shift+h} | Bottom={Shift+l} | Middle={Shift+m});
### Characters ( assumes we are in insert mode when calling)
<1to30> <direction> = {$2_$1};
(Change={c} | Copy={y}) (Char | 1 | One) = {Esc}{Right}"$1l";
(Change={c} | Copy={y}) Back [1] = {Esc}{Right}"$1h";
(Change={c} | Copy={y}) <1to30> [Chars] = {Esc}{Right}"$2$1l";
(Change={c} | Copy={y}) Back <1to30> [Chars] = {Esc}{Right}"$2$1h";
Kill (Char | 1 | One) = {Del}; # {Right}"$1l";
Kill Back [1] = {Left}{Del};
Kill <1to30> [Chars] = {Del_$1};
Kill Back <1to30> [Chars] = {Left_$1}{Del_$1}; #{Esc}{Right}"$2$1h";
Change case [(back=1)] [<1to30>] = {Esc} When($1, When($2, {Left_$2}, {Left})) When($2, $2~, ~);
### Words
[One] Word = {Esc}"w";
Back [One] Word = {Esc}"b";
<1to30> Words = {Esc}"$1w";
Back <1to30> Words = {Esc}"$1b";
<edit_mode> Word = {Esc}"$1w";
<edit_mode> <1to30> Words = {Esc}"$1$2w";
<edit_mode> Back Word = {Esc}"$1b";
<edit_mode> Back <1to30> Words = {Esc}"$1$2b";
<edit_mode> Next Word = {Esc}"w$1w";
### Lines (modify parts of/whole lines)
<line_actions> := (
Move to=":" Wait(200) ".m" | Copy to=":" Wait(200) ".co" | Change="cc" | Kill="dd" | Copy="yy" |
Sub=":" Wait(200) ".s///{Left_2}" | Duplicate="yyp" | Start="\^i" | Append="i{end}" |
beginning="20li" | middle="40li" | near the end="60li" |
New Here="i{enter}" | New insert="o" | New Back="O" | Append semicolon="\$i;"
);
<edit_mode> := (Change={c} | Kill={d} | Copy={y}); # Indent= | Comment=
# current line action (no line number specified)
<line_actions> Line = {Esc}$1;
Swap [(Back=Up | Next=Space)] [Line] = {esc} When($1, {$1}, "") "ddp";
<edit_mode> (Beginning="0" | Start="^" | End="\$") [Line] [Here] = {Esc}{Right}$1 When($2, $2, "\$");
Blank (back=O{down} | insert=o{up}) [Line] = {esc}$1{esc};
Join [(Back=Up | Next=Space)] [Line] = {esc} When($1, {$1}) "J";
# todo: think about how to manage the fact that this doesn't work in intellij IDEs
# this, tab switching, preserve casei, changeinside, sort out this
# multiple line action (relative range specified in grammar)
# split into actions and commands(commands require a ":"prefix)
# action use gg,dd etc for pycharm vim plug-in compatibility
<relative_range_actions> := (
Change="cc" | Kill="dd" | Copy="yy" |
Move to="m" | Copy to="co" | # same as copy to in this context | copy here="co-1{enter}" |
duplicate="yyp" | indent=">>g;" | reverse indent="<<g;"
);
<relative_range_actions> (Next="+" | Back="-") Line = {Esc} Wait(200) "$2" Wait(200) "$1";
<relative_range_actions> 2..30 Lines = {Esc} Wait(200) "$2$1"; #".,+" Eval($2-1) "$1";
<relative_range_actions> Back 2..30 Lines = {Esc} Wait(200) {Up_$2} Wait(200) "$2$1"; #"-$2,-1$1";
<relative_range_commands> := (
Sub="s///gc{Left_4}" | # Comment="TComment" |
Start="{enter}i" | Append="{enter}i{end}" |
copy here="co." | comment="s/^/#/{enter}" | remove comment="s/#//{enter}"
);
<relative_range_commands> (Next="+" | Back="-") Line = {Esc} Wait(200) "$2" Wait(200) ":$1";
<relative_range_commands> 2..30 Lines = {Esc} Wait(200) ":.,+" Eval($2-1) "$1";
<relative_range_commands> Back 2..30 Lines = {Esc} Wait(200) ":-$2,-1$1";
# multiple line action with range specified
<range_actions> := (
Move to="m" | Copy to="co" | Change="c" | Kill="d" | Copy="y" |
Sub="s///" | copy here="co." | comment="s/^/#/"| remove comment="s/#//"
);
<range_actions> Range = {esc}":" Wait(200) "$1" Wait(200) {Home};
### Entire "Flow"
<insert> := (insert=I | append=A);
Flow (Start="gg" | Append="G") [<insert>] = {Esc}"$1" Wait(20) "$2";
<edit_mode> (Flow Here=".,\$" | Flow All="0,\$" | Back Flow Here="0,.") = {Esc}":" Wait(200) "$2$1"{Enter};
# other grammar macro specifications for text editing commands
(Indent=">" | reverse indent="<") (Line={enter} | Range={Left}) [1..9] = When($3, Repeat($3, {Esc}":" Wait(200) "$1"$2), {esc}":" Wait(200) "$1"$2);
<sub_action> := (all="%s" | here=".,\$s" | back here="0,.s");
(sub | substitute) <sub_action> = {Esc}":" Wait(200) "$2///gc"Repeat(4, {Left});
# command specific for vim undo buffer
(edit|editor) (cancel=u | redo={ctrl+r}) [<2to9>] = {esc} When($3, Repeat($3, Wait(200) "$2"),
Wait(200) $2);
# change content between two encapsulating tokens
(change=v) (inner=i|outer=a) (
brackets="("|braces="{"|square brackets="["
) = {esc}"t$3{Right 2}" Wait(200) "vi$3";
# using macro storage register "z"
Start macro = {esc}qz;
# hack to produce "@" symbol
Repeat macro [1..9 times] = $1{shift+"'"}z;
<text_actions> := (
Paste=p | Paste Back=P | Insert=i | Append here=a | Append=A | Substitute=s | Replace=R |
diff push=dp | diff pull=do | diff next="\]c" | diff back="\[c" |
Format=Q | Normal mode= | visual mode={ctrl+v}
);
<text_actions> = {esc}$1;
#*-------------------------------------------- */
# navigation specific commands
###
### Jump to start of absolute line number L (directly up to 99,999):
# stop 1 being recognised as "one" in Vocola
$set numbers 0;
## go to absolute line number $line:
## vim mark line "v" incase we want to return to the original line
###test
GotoLineMod(line, mod) := {Esc}"mv" ":" Wait(200) "$line"{enter} Wait(200) "$mod";
GotoLine4Mod(thousands, hundreds, tens, ones, mod) :=
GotoLineMod(Eval($thousands*1000 + $hundreds*100 + $tens*10 + $ones), $mod);
<line_mod> := (
Start="zzI" | Append="zzA" | Sub=":" Wait(200) "s///{Left_2}" |
Scroll [to] bottom="zb" | Scroll [to] top="zt" | Scroll [to] middle="zz" |
beginning="20li" | middlie="40li" | end="60li" |
New back="zzO" | insert="zzo" |
# For the following commands we want to perform actions in place,
# IE. returns to original line (mark "v").
Change=":" Wait(200) ".c{enter}" "'v" | Kill=":" Wait(200) ".d{enter}" "'v" |
Copy=":" Wait(200) ".y{enter}" "'v" | Paste="p" "'v" | Paste Back="P" "'v" |
Move to=":" Wait(200) ".m" | #Copy to=":" Wait(200) ".co" |
copy here=":" Wait(200) ".y{enter}" "'v" "p" |
indent=":" Wait(200) ">{enter}" "'v"| reverse indent=":" Wait(200) "<{enter}" "'v"|
Comment=":" Wait(200) "s/^/#/{enter}" "'v" |
Remove Comment=":" Wait(200) "s/#//{enter}" "'v" |
Blank back="O{esc}" "'v" | Blank insert="o{esc}" "'v" |
touch="i" Wait(200) " " Wait(200) {Left} Wait(200) {Del} Wait(200) {esc} "'v"
);
line [<line_mod>] <0to9> = GotoLineMod($2,$1);
line [<line_mod>] <0to9> <0to9> = GotoLine4Mod(0, 0, $2, $3, $1);
line [<line_mod>] <0to9> <0to9> <0to9> = GotoLine4Mod(0, $2, $3, $4, $1);
line [<line_mod>] <0to9> <0to9> <0to9> <0to9> = GotoLine4Mod($2, $3, $4, $5, $1);
# special navigation actions
<navigation_actions> := (
List changes=":" Wait(200) "changes" | back change="g;" | Undo jump="``" |
return from="''" | Set mark="mz" | Goto mark="'zi" |
Append back="-"\$"i{Del}" | Append next="+"\$"i{Del}" |
Start back="-i" | Start next="+i" | Match bracket="%" |
Scroll [to] bottom="zb" | Scroll [to] top="zt" | Scroll [to] middle="zz"
);
<navigation_actions> = {esc}$1;
Halfpage [(Up="u" | Down="d")] = {Esc} When($1, {Ctrl+$1}, {Ctrl+d});
Page <top_bottom> = {Esc}$1;
##next change="g,"
Back till <key> = {Esc}"T$1";
Till <key> = {Esc}"t$1";
Till next = {Esc}";";
Search <_anything> = {Esc}"/" Wait(200) "\c$1";
Search go <_anything> = {Esc}"/\c$1"{enter};
clear Search = {Esc}"/zzz"{enter};
# commandline actions
Make = {Esc}":" Wait(200) "make";
Vim Update Tag File = {Esc}":" Wait(200) "!ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q ."{Enter};
List errors = {Esc}":" Wait(200) "clist";
Next error = {Esc}":" Wait(200) "cn";
back error = {Esc}":" Wait(200) "cp";
Save file = {Esc}":" Wait(200) "w"{Enter};
Close file = {Esc}":" Wait(200) "q"{Enter};
Save and close file = {Esc}":" Wait(200) "x"{Enter};
#confirm force close definite = {Esc}":" Wait(200) "q!";
back command [1..9] = When($1, Repeat($1, {Esc}":" Wait(200) ""{up}{enter}), {Esc}":" Wait(200) ""{up});
Edit another = {Esc}":" Wait(200) "e ";
File browser = {Esc}":" Wait(200) "e."{Enter};
vim diff split = {esc}":" Wait(200) "vert diffsplit ";
# text shortcuts
#Def include = {Esc}"i#include ";
#Def Define = {Esc}"i#define ";
#Def ifdef = {Esc}"\pid"{enter};
#file Printf = {Esc}"i"{Right}"fprintf(,);" {Left_3};
#Equals = {Esc}i{right}= ";
#Hash = {Esc}"i#"{esc};
Insert space = {Esc}"i"{space}{esc};
#insert comment [(escape={Esc} | insert="i" | todo="iTODO: ")] = {Esc}":" Wait(200) "TComment "{enter}$1;
Insert space after = {Esc}"i"{Right}{space}{esc};
#Begin comment = {Esc}"i/* ";
Append comment = {Esc}"i */"{enter};
#Begin long comment = {Esc}"i#"{esc}"ib"{space};
#End long comment = {Esc}"i#"{esc}"ie"{enter};
Insert line break = {Esc}"i"{enter};
insert comment = {Esc}"i#"{esc}"il"{enter};
Double slash backslash = {Esc}"\/\/";
reference = "-" Wait(500) ">";
Function definition = {Esc}{Right}"idef ():" {Left_3};
Function definition <_anything> = {Esc}{Right}"idef $1():" {Left_2};
Show Help = {Esc}":" Wait(200) "help ";
Set setting [(paste="paste{enter}")] = {Esc}":" Wait(200) "set $1";
Set dark background = {Esc}":" Wait(200) "set bg=dark"{enter};
Set light background = {Esc}":" Wait(200) "set bg=light"{enter};
reload vim config = {esc}":" Wait(200) "source ~/.vimrc"{enter};
run this [(now={enter})] = {esc}":" Wait(200) "!./% $1";
# window navigation
## move created split one page up, return to top of original page in the right split
Split vertical = {Esc}":" Wait(200) "vsp"{Enter}{Shift+h}{PgUp}
{Ctrl+w}"l";
<window_action> := (left=h | right=l | up=k | down=j | next=w | close=c );
Vim Window <window_action> = {esc}{ctrl+w}"$1";
Vim Window crop = {Esc}":" Wait(200) "only"{Enter};
Vim Window make fat = {esc}":" Wait(200) "vertical resize +15"{enter};
Vim Window make thin = {esc}":" Wait(200) "vertical resize -15"{enter};
# buffer navigation
back buffer = {Esc}":" Wait(200) "bp"{Enter};
Close buffer = {Esc}":" Wait(200) "bd"{Enter};
Next buffer = {Esc}":" Wait(200) "bn"{Enter};
Switch buffer = {Esc}":" Wait(200) "b#"{Enter};
List buffers = {Esc}":" Wait(200) "buffers"{enter};
numbered buffer <1to30> = {Esc}":" Wait(200) "b$1"{enter};
# tab navigation
<tab_actions> := (back=p | Close=c | Next=n | List=s | Last=l | First=fir);
vim <tab_actions> tab = {Esc}":" Wait(200) "tab$1"{Enter};
vim switch tab <1to30> = {Esc}":" Wait(200) "tabn $1"{enter};
# tab navigation
#<tag_actions> := (back=":" Wait(200) "tN{enter}" | Jump="{Ctrl+]}" | Next=":" Wait(200) "tn{enter}" |
# Match=":" Wait(200) "ts{enter}" | Return="{Ctrl+t}" | Stack=":" Wait(200) "tags{enter}");
vim Tag back={esc}":" Wait(200) "tN{enter}";
vim Tag Jump={esc}"{Ctrl+]}";
vim Tag Next={esc}":" Wait(200) "tn{enter}";
Vim Tag Match={esc}":" Wait(200) "ts{enter}";
Vim Tag Return={esc}"{Ctrl+t}";
Vim Tag Stack={esc}":" Wait(200) "tags{enter}";
#Vim Tag <tab_actions> = {Esc}$1;
Vim Folds (open=ctrl|close=shift) = {Esc}{$1+f};
### end of core vim commands ###
# editor settings
Nowrap = "{Esc}:set nowrap{enter}";
setting based = "{Esc}:set paste{enter}";
Edit vim RC = {Esc} ":" Wait(200) "e ~\.vimrc" {Enter};
Reload = {Esc} ":" Wait(200) "source \$MYVIMRC" {Enter};
all buffers = {esc}":bufdo ";
# histories
command history = {Esc}"q:";
pattern match history = {Esc}"q/";
#
## temporary project specific macros
histogram debug = {esc}'i#ifdef DEBUG{enter}fsp_log_debug(shared_data_p->config_p->prog_name_p, {enter}"%s: \n", __FUNCTION__);{enter}#endif' {Up}{End} Repeat(19,{Left});
ifdef (debug="DEBUG" | trace="TRACE") = {Esc}"ddi#ifdef $1"{enter};
ifdef end = {esc}"o#endif"{enter};