vis: let ~ have an immediate effect in normal mode
[vis.git] / config.def.h
bloba51c87587779a2d184f43146bb2ef1825a5f771d
1 /* Configure your desired default key bindings. */
3 #define ALIAS(name) .alias = name,
4 #define ACTION(id) .action = &vis_action[VIS_ACTION_##id],
6 static const KeyBinding bindings_basic[] = {
7 { "<C-z>", ACTION(EDITOR_SUSPEND) },
8 { "<Left>", ACTION(CURSOR_CHAR_PREV) },
9 { "<S-Left>", ACTION(CURSOR_LONGWORD_START_PREV) },
10 { "<Right>", ACTION(CURSOR_CHAR_NEXT) },
11 { "<S-Right>", ACTION(CURSOR_LONGWORD_START_NEXT) },
12 { "<Up>", ACTION(CURSOR_LINE_UP) },
13 { "<Down>", ACTION(CURSOR_LINE_DOWN) },
14 { "<PageUp>", ACTION(WINDOW_PAGE_UP) },
15 { "<PageDown>", ACTION(WINDOW_PAGE_DOWN) },
16 { "<S-PageUp>", ACTION(WINDOW_HALFPAGE_UP) },
17 { "<S-PageDown>", ACTION(WINDOW_HALFPAGE_DOWN) },
18 { "<Home>", ACTION(CURSOR_LINE_BEGIN) },
19 { "<End>", ACTION(CURSOR_LINE_END) },
20 { 0 /* empty last element, array terminator */ },
23 static const KeyBinding bindings_motions[] = {
24 { "h", ACTION(CURSOR_CHAR_PREV) },
25 { "<Backspace>", ALIAS("h") },
26 { "<C-h>", ALIAS("<Backspace>") },
27 { "l", ACTION(CURSOR_CHAR_NEXT) },
28 { " ", ALIAS("l") },
29 { "k", ACTION(CURSOR_LINE_UP) },
30 { "C-p", ALIAS("k") },
31 { "j", ACTION(CURSOR_LINE_DOWN) },
32 { "<C-j>", ALIAS("j") },
33 { "<C-n>", ALIAS("j") },
34 { "<Enter>", ALIAS("j") },
35 { "gk", ACTION(CURSOR_SCREEN_LINE_UP) },
36 { "g<Up>", ALIAS("gk") },
37 { "gj", ACTION(CURSOR_SCREEN_LINE_DOWN) },
38 { "g<Down>", ALIAS("gj") },
39 { "^", ACTION(CURSOR_LINE_START) },
40 { "g_", ACTION(CURSOR_LINE_FINISH) },
41 { "$", ACTION(CURSOR_LINE_END) },
42 { "%", ACTION(CURSOR_BRACKET_MATCH) },
43 { "b", ACTION(CURSOR_WORD_START_PREV) },
44 { "B", ACTION(CURSOR_LONGWORD_START_PREV) },
45 { "w", ACTION(CURSOR_WORD_START_NEXT) },
46 { "W", ACTION(CURSOR_LONGWORD_START_NEXT) },
47 { "ge", ACTION(CURSOR_WORD_END_PREV) },
48 { "gE", ACTION(CURSOR_LONGWORD_END_PREV) },
49 { "e", ACTION(CURSOR_WORD_END_NEXT) },
50 { "E", ACTION(CURSOR_LONGWORD_END_NEXT) },
51 { "{", ACTION(CURSOR_PARAGRAPH_PREV) },
52 { "}", ACTION(CURSOR_PARAGRAPH_NEXT) },
53 { "(", ACTION(CURSOR_SENTENCE_PREV) },
54 { ")", ACTION(CURSOR_SENTENCE_NEXT) },
55 { "[[", ACTION(CURSOR_FUNCTION_START_PREV) },
56 { "[]", ACTION(CURSOR_FUNCTION_END_PREV) },
57 { "][", ACTION(CURSOR_FUNCTION_START_NEXT) },
58 { "]]", ACTION(CURSOR_FUNCTION_END_NEXT) },
59 { "gg", ACTION(CURSOR_LINE_FIRST) },
60 { "g0", ACTION(CURSOR_SCREEN_LINE_BEGIN) },
61 { "gm", ACTION(CURSOR_SCREEN_LINE_MIDDLE) },
62 { "g$", ACTION(CURSOR_SCREEN_LINE_END) },
63 { "G", ACTION(CURSOR_LINE_LAST) },
64 { "|", ACTION(CURSOR_COLUMN) },
65 { "n", ACTION(CURSOR_SEARCH_NEXT) },
66 { "N", ACTION(CURSOR_SEARCH_PREV) },
67 { "H", ACTION(CURSOR_WINDOW_LINE_TOP) },
68 { "M", ACTION(CURSOR_WINDOW_LINE_MIDDLE) },
69 { "L", ACTION(CURSOR_WINDOW_LINE_BOTTOM) },
70 { "*", ACTION(CURSOR_SEARCH_WORD_FORWARD) },
71 { "#", ACTION(CURSOR_SEARCH_WORD_BACKWARD) },
72 { "f", ACTION(TO_RIGHT) },
73 { "F", ACTION(TO_LEFT) },
74 { "t", ACTION(TILL_RIGHT) },
75 { "T", ACTION(TILL_LEFT) },
76 { ";", ACTION(TOTILL_REPEAT) },
77 { ",", ACTION(TOTILL_REVERSE) },
78 { "/", ACTION(PROMPT_SEARCH_FORWARD) },
79 { "?", ACTION(PROMPT_SEARCH_BACKWARD) },
80 { "`", ACTION(MARK_GOTO) },
81 { "'", ACTION(MARK_GOTO_LINE) },
82 { 0 /* empty last element, array terminator */ },
85 static const KeyBinding bindings_textobjects[] = {
86 { "aw", ACTION(TEXT_OBJECT_WORD_OUTER) },
87 { "aW", ACTION(TEXT_OBJECT_LONGWORD_OUTER) },
88 { "as", ACTION(TEXT_OBJECT_SENTENCE) },
89 { "ap", ACTION(TEXT_OBJECT_PARAGRAPH) },
90 { "a[", ACTION(TEXT_OBJECT_SQUARE_BRACKET_OUTER) },
91 { "a]", ALIAS("a[") },
92 { "a(", ACTION(TEXT_OBJECT_PARANTHESE_OUTER) },
93 { "a)", ALIAS("a(") },
94 { "ab", ALIAS("a(") },
95 { "a<", ACTION(TEXT_OBJECT_ANGLE_BRACKET_OUTER) },
96 { "a>", ALIAS("a<") },
97 { "a{", ACTION(TEXT_OBJECT_CURLY_BRACKET_OUTER) },
98 { "a}", ALIAS("a{") },
99 { "aB", ALIAS("a{") },
100 { "a\"", ACTION(TEXT_OBJECT_QUOTE_OUTER) },
101 { "a\'", ACTION(TEXT_OBJECT_SINGLE_QUOTE_OUTER) },
102 { "a`", ACTION(TEXT_OBJECT_BACKTICK_OUTER) },
103 { "ae", ACTION(TEXT_OBJECT_ENTIRE_OUTER) },
104 { "af", ACTION(TEXT_OBJECT_FUNCTION_OUTER) },
105 { "al", ACTION(TEXT_OBJECT_LINE_OUTER) },
106 { "iw", ACTION(TEXT_OBJECT_WORD_INNER) },
107 { "iW", ACTION(TEXT_OBJECT_LONGWORD_INNER) },
108 { "is", ACTION(TEXT_OBJECT_SENTENCE) },
109 { "ip", ACTION(TEXT_OBJECT_PARAGRAPH) },
110 { "i[", ACTION(TEXT_OBJECT_SQUARE_BRACKET_INNER) },
111 { "i]", ALIAS("i[") },
112 { "i(", ACTION(TEXT_OBJECT_PARANTHESE_INNER) },
113 { "i)", ALIAS("i(") },
114 { "ib", ALIAS("ib") },
115 { "i<", ACTION(TEXT_OBJECT_ANGLE_BRACKET_INNER) },
116 { "i>", ALIAS("i<") },
117 { "i{", ACTION(TEXT_OBJECT_CURLY_BRACKET_INNER) },
118 { "i}", ALIAS("i{") },
119 { "iB", ALIAS("i{") },
120 { "i\"", ACTION(TEXT_OBJECT_QUOTE_INNER) },
121 { "i\'", ACTION(TEXT_OBJECT_SINGLE_QUOTE_INNER) },
122 { "i`", ACTION(TEXT_OBJECT_BACKTICK_INNER) },
123 { "ie", ACTION(TEXT_OBJECT_ENTIRE_INNER) },
124 { "if", ACTION(TEXT_OBJECT_FUNCTION_INNER) },
125 { "il", ACTION(TEXT_OBJECT_LINE_INNER) },
126 { 0 /* empty last element, array terminator */ },
129 static const KeyBinding bindings_operators[] = {
130 { "0", ACTION(COUNT) },
131 { "1", ACTION(COUNT) },
132 { "2", ACTION(COUNT) },
133 { "3", ACTION(COUNT) },
134 { "4", ACTION(COUNT) },
135 { "5", ACTION(COUNT) },
136 { "6", ACTION(COUNT) },
137 { "7", ACTION(COUNT) },
138 { "8", ACTION(COUNT) },
139 { "9", ACTION(COUNT) },
140 { "d", ACTION(OPERATOR_DELETE) },
141 { "c", ACTION(OPERATOR_CHANGE) },
142 { "y", ACTION(OPERATOR_YANK) },
143 { ">", ACTION(OPERATOR_SHIFT_RIGHT) },
144 { "<", ACTION(OPERATOR_SHIFT_LEFT) },
145 { "gU", ACTION(OPERATOR_CASE_UPPER) },
146 { "~", ACTION(OPERATOR_CASE_SWAP) },
147 { "g~", ACTION(OPERATOR_CASE_SWAP) },
148 { "gu", ACTION(OPERATOR_CASE_LOWER) },
149 { "!", ACTION(OPERATOR_FILTER) },
150 { "=", ACTION(OPERATOR_FILTER_FMT) },
151 { "\"", ACTION(REGISTER) },
152 { 0 /* empty last element, array terminator */ },
155 static const KeyBinding bindings_operator_options[] = {
156 { "v", ACTION(MOTION_CHARWISE) },
157 { "V", ACTION(MOTION_LINEWISE) },
158 { 0 /* empty last element, array terminator */ },
161 static const KeyBinding bindings_normal[] = {
162 { "<Escape>", ACTION(CURSORS_REMOVE_ALL) },
163 { "<Delete>", ALIAS("x") },
164 { "<C-k>", ACTION(CURSORS_NEW_LINE_ABOVE) },
165 { "<C-j>", ACTION(CURSORS_NEW_LINE_BELOW) },
166 { "<C-a>", ACTION(CURSORS_ALIGN) },
167 { "<C-n>", ACTION(CURSOR_SELECT_WORD) },
168 { "<C-p>", ACTION(CURSORS_REMOVE_LAST) },
169 { "<C-w>n", ALIAS(":open<Enter>") },
170 { "<C-w>c", ALIAS(":q<Enter>") },
171 { "<C-w>s", ALIAS(":split<Enter>") },
172 { "<C-w>v", ALIAS(":vsplit<Enter>") },
173 { "<C-w>j", ACTION(WINDOW_NEXT) },
174 { "<C-w>l", ALIAS("<C-w>j") },
175 { "<C-w>w", ALIAS("<C-w>j") },
176 { "<C-w><C-w>", ALIAS("<C-w>j") },
177 { "<C-w><C-j>", ALIAS("<C-w>j") },
178 { "<C-w><C-l>", ALIAS("<C-w>j") },
179 { "<C-w>k", ACTION(WINDOW_PREV) },
180 { "<C-w>h", ALIAS("<C-w>k") },
181 { "<C-w><C-h>", ALIAS("<C-w>k") },
182 { "<C-w><C-k>", ALIAS("<C-w>k") },
183 { "<C-w><Backspace>", ALIAS("<C-w>k") },
184 { "<C-b>", ALIAS("<PageUp>") },
185 { "<C-f>", ALIAS("<PageDown>") },
186 { "<C-u>", ALIAS("<S-PageUp>") },
187 { "<C-d>", ALIAS("<S-PageDown>") },
188 { "<C-e>", ACTION(WINDOW_SLIDE_UP) },
189 { "<C-y>", ACTION(WINDOW_SLIDE_DOWN) },
190 { "<C-o>", ACTION(JUMPLIST_PREV) },
191 { "<C-i>", ACTION(JUMPLIST_NEXT) },
192 { "g;", ACTION(CHANGELIST_PREV) },
193 { "g,", ACTION(CHANGELIST_NEXT) },
194 { "a", ACTION(APPEND_CHAR_NEXT) },
195 { "A", ACTION(APPEND_LINE_END) },
196 { "C", ALIAS("c$") },
197 { "D", ALIAS("d$") },
198 { "I", ACTION(INSERT_LINE_START) },
199 { ".", ACTION(REPEAT) },
200 { "o", ACTION(OPEN_LINE_BELOW) },
201 { "O", ACTION(OPEN_LINE_ABOVE) },
202 { "J", ACTION(JOIN_LINE_BELOW) },
203 { "x", ACTION(DELETE_CHAR_NEXT) },
204 { "r", ACTION(REPLACE_CHAR) },
205 { "i", ACTION(MODE_INSERT) },
206 { "v", ACTION(MODE_VISUAL) },
207 { "V", ACTION(MODE_VISUAL_LINE) },
208 { "R", ACTION(MODE_REPLACE) },
209 { "S", ALIAS("^c$") },
210 { "s", ALIAS("cl") },
211 { "Y", ALIAS("yy") },
212 { "X", ALIAS("dh") },
213 { "u", ACTION(UNDO) },
214 { "<C-r>", ACTION(REDO) },
215 { "g+", ACTION(LATER) },
216 { "g-", ACTION(EARLIER) },
217 { "<C-l>", ACTION(REDRAW) },
218 { ":", ACTION(PROMPT_SHOW) },
219 { "ZZ", ALIAS(":wq<Enter>") },
220 { "ZQ", ALIAS(":q!<Enter>") },
221 { "zt", ACTION(WINDOW_REDRAW_TOP) },
222 { "zz", ACTION(WINDOW_REDRAW_CENTER) },
223 { "zb", ACTION(WINDOW_REDRAW_BOTTOM) },
224 { "q", ACTION(MACRO_RECORD) },
225 { "@", ACTION(MACRO_REPLAY) },
226 { "gv", ACTION(SELECTION_RESTORE) },
227 { "m", ACTION(MARK_SET) },
228 { "<F1>", ALIAS(":help<Enter>") },
229 { "ga", ACTION(UNICODE_INFO) },
230 { "p", ACTION(PUT_AFTER) },
231 { "P", ACTION(PUT_BEFORE) },
232 { "gp", ACTION(PUT_AFTER_END) },
233 { "gP", ACTION(PUT_BEFORE_END) },
234 { "~", ALIAS("<vis-operator-case-swap>l") },
235 { 0 /* empty last element, array terminator */ },
238 static const KeyBinding bindings_visual[] = {
239 { "<C-n>", ACTION(CURSORS_NEW_MATCH_NEXT) },
240 { "<C-x>", ACTION(CURSORS_NEW_MATCH_SKIP) },
241 { "<C-p>", ACTION(CURSORS_REMOVE_LAST) },
242 { "I", ACTION(CURSORS_NEW_LINES_BEGIN) },
243 { "A", ACTION(CURSORS_NEW_LINES_END) },
244 { "<Backspace>", ALIAS("d") },
245 { "<C-h>", ALIAS("<Backspace>") },
246 { "<Delete>", ALIAS("<Backspace>") },
247 { "<Escape>", ACTION(MODE_NORMAL) },
248 { "<C-c>", ALIAS("<Escape>") },
249 { "v", ALIAS("<Escape>") },
250 { "V", ACTION(MODE_VISUAL_LINE) },
251 { ":", ACTION(PROMPT_SHOW_VISUAL) },
252 { "x", ALIAS("d") },
253 { "r", ALIAS("c") },
254 { "s", ALIAS("c") },
255 { "J", ACTION(JOIN_LINES) },
256 { "o", ACTION(SELECTION_FLIP) },
257 { 0 /* empty last element, array terminator */ },
260 static const KeyBinding bindings_visual_line[] = {
261 { "v", ACTION(MODE_VISUAL) },
262 { "V", ACTION(MODE_NORMAL) },
263 { 0 /* empty last element, array terminator */ },
266 static const KeyBinding bindings_readline[] = {
267 { "<Backspace>", ACTION(DELETE_CHAR_PREV) },
268 { "<C-h>", ALIAS("<Backspace>") },
269 { "<Delete>", ACTION(DELETE_CHAR_NEXT) },
270 { "<Escape>", ACTION(MODE_NORMAL) },
271 { "<C-c>", ALIAS("<Enter>") },
272 { "<C-d>", ACTION(DELETE_CHAR_NEXT) },
273 { "<C-w>", ACTION(DELETE_WORD_PREV) },
274 { "<C-u>", ACTION(DELETE_LINE_BEGIN) },
275 { "<C-v>", ACTION(INSERT_VERBATIM) },
276 { 0 /* empty last element, array terminator */ },
279 static const KeyBinding bindings_insert[] = {
280 { "<Escape>", ACTION(MODE_NORMAL) },
281 { "<C-c>", ALIAS("<Escape>") },
282 { "<C-i>", ALIAS("<Tab>") },
283 { "<Enter>", ACTION(INSERT_NEWLINE) },
284 { "<C-j>", ALIAS("<Enter>") },
285 { "<C-m>", ALIAS("<Enter>") },
286 { "<C-o>", ACTION(MODE_OPERATOR_PENDING) },
287 { "<C-d>", ALIAS("<Escape><<i") },
288 { "<C-t>", ALIAS("<Escape>>>i") },
289 { "<C-x><C-e>", ACTION(WINDOW_SLIDE_UP) },
290 { "<C-x><C-y>", ACTION(WINDOW_SLIDE_DOWN) },
291 { "<Tab>", ACTION(INSERT_TAB) },
292 { "<C-r>", ACTION(INSERT_REGISTER) },
293 { 0 /* empty last element, array terminator */ },
296 static const KeyBinding bindings_replace[] = {
297 { 0 /* empty last element, array terminator */ },
300 /* For each mode we list a all key bindings, if a key is bound in more than
301 * one array the first definition is used and further ones are ignored. */
302 static const KeyBinding **default_bindings[] = {
303 [VIS_MODE_OPERATOR_PENDING] = (const KeyBinding*[]){
304 bindings_operator_options,
305 bindings_operators,
306 bindings_textobjects,
307 bindings_motions,
308 bindings_basic,
309 NULL,
311 [VIS_MODE_NORMAL] = (const KeyBinding*[]){
312 bindings_normal,
313 bindings_operators,
314 bindings_motions,
315 bindings_basic,
316 NULL,
318 [VIS_MODE_VISUAL] = (const KeyBinding*[]){
319 bindings_visual,
320 bindings_textobjects,
321 bindings_operators,
322 bindings_motions,
323 bindings_basic,
324 NULL,
326 [VIS_MODE_VISUAL_LINE] = (const KeyBinding*[]){
327 bindings_visual_line,
328 bindings_visual,
329 bindings_textobjects,
330 bindings_operators,
331 bindings_motions,
332 bindings_basic,
333 NULL,
335 [VIS_MODE_INSERT] = (const KeyBinding*[]){
336 bindings_insert,
337 bindings_readline,
338 bindings_basic,
339 NULL,
341 [VIS_MODE_REPLACE] = (const KeyBinding*[]){
342 bindings_replace,
343 bindings_insert,
344 bindings_readline,
345 bindings_basic,
346 NULL,