11 #include <sys/types.h>
13 #include "ui-terminal.h"
16 #include "text-util.h"
17 #include "text-motions.h"
18 #include "text-objects.h"
25 #define PAGE_HALF (INT_MAX-1)
27 /** functions to be called from keybindings */
28 /* ignore key, do nothing */
29 static const char *nop(Vis
*, const char *keys
, const Arg
*arg
);
30 /* record/replay macro indicated by keys */
31 static const char *macro_record(Vis
*, const char *keys
, const Arg
*arg
);
32 static const char *macro_replay(Vis
*, const char *keys
, const Arg
*arg
);
33 /* temporarily suspend the editor and return to the shell, type 'fg' to get back */
34 static const char *suspend(Vis
*, const char *keys
, const Arg
*arg
);
35 /* reset count if set, otherwise remove all but the primary selection */
36 static const char *normalmode_escape(Vis
*, const char *keys
, const Arg
*arg
);
37 /* reset count if set, otherwise switch to normal mode */
38 static const char *visualmode_escape(Vis
*, const char *keys
, const Arg
*arg
);
39 /* switch to mode indicated by arg->i */
40 static const char *switchmode(Vis
*, const char *keys
, const Arg
*arg
);
41 /* switch to insert mode after performing movement indicated by arg->i */
42 static const char *insertmode(Vis
*, const char *keys
, const Arg
*arg
);
43 /* switch to replace mode after performing movement indicated by arg->i */
44 static const char *replacemode(Vis
*, const char *keys
, const Arg
*arg
);
45 /* add a new line either before or after the one where the cursor currently is */
46 static const char *openline(Vis
*, const char *keys
, const Arg
*arg
);
47 /* join lines from current cursor position to movement indicated by arg */
48 static const char *join(Vis
*, const char *keys
, const Arg
*arg
);
49 /* perform last action i.e. action_prev again */
50 static const char *repeat(Vis
*, const char *keys
, const Arg
*arg
);
51 /* replace character at cursor with one from keys */
52 static const char *replace(Vis
*, const char *keys
, const Arg
*arg
);
53 /* create a new cursor on the previous (arg->i < 0) or next (arg->i > 0) line */
54 static const char *selections_new(Vis
*, const char *keys
, const Arg
*arg
);
55 /* try to align all selections on the same column */
56 static const char *selections_align(Vis
*, const char *keys
, const Arg
*arg
);
57 /* try to align all selections by inserting the correct amount of white spaces */
58 static const char *selections_align_indent(Vis
*, const char *keys
, const Arg
*arg
);
59 /* remove all but the primary cursor and their selections */
60 static const char *selections_clear(Vis
*, const char *keys
, const Arg
*arg
);
61 /* remove the least recently added selection */
62 static const char *selections_remove(Vis
*, const char *keys
, const Arg
*arg
);
63 /* remove count (or arg->i)-th selection column */
64 static const char *selections_remove_column(Vis
*, const char *keys
, const Arg
*arg
);
65 /* remove all but the count (or arg->i)-th selection column */
66 static const char *selections_remove_column_except(Vis
*, const char *keys
, const Arg
*arg
);
67 /* move to the previous (arg->i < 0) or next (arg->i > 0) selection */
68 static const char *selections_navigate(Vis
*, const char *keys
, const Arg
*arg
);
69 /* select the next region matching the current selection */
70 static const char *selections_match_next(Vis
*, const char *keys
, const Arg
*arg
);
71 /* clear current selection but select next match */
72 static const char *selections_match_skip(Vis
*, const char *keys
, const Arg
*arg
);
73 /* rotate selection content count times left (arg->i < 0) or right (arg->i > 0) */
74 static const char *selections_rotate(Vis
*, const char *keys
, const Arg
*arg
);
75 /* remove leading and trailing white spaces from selections */
76 static const char *selections_trim(Vis
*, const char *keys
, const Arg
*arg
);
77 /* save active selections to mark */
78 static const char *selections_save(Vis
*, const char *keys
, const Arg
*arg
);
79 /* restore selections from mark */
80 static const char *selections_restore(Vis
*, const char *keys
, const Arg
*arg
);
81 /* union selections from mark */
82 static const char *selections_union(Vis
*, const char *keys
, const Arg
*arg
);
83 /* intersect selections from mark */
84 static const char *selections_intersect(Vis
*, const char *keys
, const Arg
*arg
);
85 /* perform complement of current active selections */
86 static const char *selections_complement(Vis
*, const char *keys
, const Arg
*arg
);
87 /* subtract selections from mark */
88 static const char *selections_minus(Vis
*, const char *keys
, const Arg
*arg
);
89 /* adjust current used count according to keys */
90 static const char *count(Vis
*, const char *keys
, const Arg
*arg
);
91 /* move to the count-th line or if not given either to the first (arg->i < 0)
92 * or last (arg->i > 0) line of file */
93 static const char *gotoline(Vis
*, const char *keys
, const Arg
*arg
);
94 /* make the current action use the operator indicated by arg->i */
95 static const char *operator(Vis
*, const char *keys
, const Arg
*arg
);
96 /* blocks to read a key and performs movement indicated by arg->i which
97 * should be one of VIS_MOVE_{TO,TILL}_{,LINE}_{RIGHT,LEFT}*/
98 static const char *movement_key(Vis
*, const char *keys
, const Arg
*arg
);
99 /* perform the movement as indicated by arg->i */
100 static const char *movement(Vis
*, const char *keys
, const Arg
*arg
);
101 /* let the current operator affect the range indicated by the text object arg->i */
102 static const char *textobj(Vis
*, const char *keys
, const Arg
*arg
);
103 /* move to the other end of selected text */
104 static const char *selection_end(Vis
*, const char *keys
, const Arg
*arg
);
105 /* use register indicated by keys for the current operator */
106 static const char *reg(Vis
*, const char *keys
, const Arg
*arg
);
107 /* use mark indicated by keys for the current action */
108 static const char *mark(Vis
*, const char *keys
, const Arg
*arg
);
109 /* {un,re}do last action, redraw window */
110 static const char *undo(Vis
*, const char *keys
, const Arg
*arg
);
111 static const char *redo(Vis
*, const char *keys
, const Arg
*arg
);
112 /* earlier, later action chronologically, redraw window */
113 static const char *earlier(Vis
*, const char *keys
, const Arg
*arg
);
114 static const char *later(Vis
*, const char *keys
, const Arg
*arg
);
115 /* delete from the current cursor position to the end of
116 * movement as indicated by arg->i */
117 static const char *delete(Vis
*, const char *keys
, const Arg
*arg
);
118 /* insert register content indicated by keys at current cursor position */
119 static const char *insert_register(Vis
*, const char *keys
, const Arg
*arg
);
120 /* show a user prompt to get input with title arg->s */
121 static const char *prompt_show(Vis
*, const char *keys
, const Arg
*arg
);
122 /* blocks to read 3 consecutive digits and inserts the corresponding byte value */
123 static const char *insert_verbatim(Vis
*, const char *keys
, const Arg
*arg
);
124 /* scroll window content according to arg->i which can be either PAGE, PAGE_HALF,
125 * or an arbitrary number of lines. a multiplier overrides what is given in arg->i.
126 * negative values scroll back, positive forward. */
127 static const char *wscroll(Vis
*, const char *keys
, const Arg
*arg
);
128 /* similar to scroll, but do only move window content not cursor position */
129 static const char *wslide(Vis
*, const char *keys
, const Arg
*arg
);
130 /* call editor function as indicated by arg->f */
131 static const char *call(Vis
*, const char *keys
, const Arg
*arg
);
132 /* call window function as indicated by arg->w */
133 static const char *window(Vis
*, const char *keys
, const Arg
*arg
);
134 /* show info about Unicode character at cursor position */
135 static const char *unicode_info(Vis
*, const char *keys
, const Arg
*arg
);
136 /* either go to count % of file or to matching item */
137 static const char *percent(Vis
*, const char *keys
, const Arg
*arg
);
138 /* navigate jumplist next (arg->i > 0), prev (arg->i < 0), save (arg->i = 0) */
139 static const char *jumplist(Vis
*, const char *keys
, const Arg
*arg
);
142 VIS_ACTION_EDITOR_SUSPEND
,
143 VIS_ACTION_CURSOR_CHAR_PREV
,
144 VIS_ACTION_CURSOR_CHAR_NEXT
,
145 VIS_ACTION_CURSOR_LINE_CHAR_PREV
,
146 VIS_ACTION_CURSOR_LINE_CHAR_NEXT
,
147 VIS_ACTION_CURSOR_CODEPOINT_PREV
,
148 VIS_ACTION_CURSOR_CODEPOINT_NEXT
,
149 VIS_ACTION_CURSOR_WORD_START_PREV
,
150 VIS_ACTION_CURSOR_WORD_START_NEXT
,
151 VIS_ACTION_CURSOR_WORD_END_PREV
,
152 VIS_ACTION_CURSOR_WORD_END_NEXT
,
153 VIS_ACTION_CURSOR_LONGWORD_START_PREV
,
154 VIS_ACTION_CURSOR_LONGWORD_START_NEXT
,
155 VIS_ACTION_CURSOR_LONGWORD_END_PREV
,
156 VIS_ACTION_CURSOR_LONGWORD_END_NEXT
,
157 VIS_ACTION_CURSOR_LINE_UP
,
158 VIS_ACTION_CURSOR_LINE_DOWN
,
159 VIS_ACTION_CURSOR_LINE_START
,
160 VIS_ACTION_CURSOR_LINE_FINISH
,
161 VIS_ACTION_CURSOR_LINE_BEGIN
,
162 VIS_ACTION_CURSOR_LINE_END
,
163 VIS_ACTION_CURSOR_SCREEN_LINE_UP
,
164 VIS_ACTION_CURSOR_SCREEN_LINE_DOWN
,
165 VIS_ACTION_CURSOR_SCREEN_LINE_BEGIN
,
166 VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE
,
167 VIS_ACTION_CURSOR_SCREEN_LINE_END
,
168 VIS_ACTION_CURSOR_PERCENT
,
169 VIS_ACTION_CURSOR_BYTE
,
170 VIS_ACTION_CURSOR_BYTE_LEFT
,
171 VIS_ACTION_CURSOR_BYTE_RIGHT
,
172 VIS_ACTION_CURSOR_PARAGRAPH_PREV
,
173 VIS_ACTION_CURSOR_PARAGRAPH_NEXT
,
174 VIS_ACTION_CURSOR_SENTENCE_PREV
,
175 VIS_ACTION_CURSOR_SENTENCE_NEXT
,
176 VIS_ACTION_CURSOR_BLOCK_START
,
177 VIS_ACTION_CURSOR_BLOCK_END
,
178 VIS_ACTION_CURSOR_PARENTHESIS_START
,
179 VIS_ACTION_CURSOR_PARENTHESIS_END
,
180 VIS_ACTION_CURSOR_COLUMN
,
181 VIS_ACTION_CURSOR_LINE_FIRST
,
182 VIS_ACTION_CURSOR_LINE_LAST
,
183 VIS_ACTION_CURSOR_WINDOW_LINE_TOP
,
184 VIS_ACTION_CURSOR_WINDOW_LINE_MIDDLE
,
185 VIS_ACTION_CURSOR_WINDOW_LINE_BOTTOM
,
186 VIS_ACTION_CURSOR_SEARCH_REPEAT_FORWARD
,
187 VIS_ACTION_CURSOR_SEARCH_REPEAT_BACKWARD
,
188 VIS_ACTION_CURSOR_SEARCH_REPEAT
,
189 VIS_ACTION_CURSOR_SEARCH_REPEAT_REVERSE
,
190 VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD
,
191 VIS_ACTION_CURSOR_SEARCH_WORD_BACKWARD
,
192 VIS_ACTION_WINDOW_PAGE_UP
,
193 VIS_ACTION_WINDOW_PAGE_DOWN
,
194 VIS_ACTION_WINDOW_HALFPAGE_UP
,
195 VIS_ACTION_WINDOW_HALFPAGE_DOWN
,
196 VIS_ACTION_MODE_NORMAL
,
197 VIS_ACTION_MODE_NORMAL_ESCAPE
,
198 VIS_ACTION_MODE_VISUAL
,
199 VIS_ACTION_MODE_VISUAL_ESCAPE
,
200 VIS_ACTION_MODE_VISUAL_LINE
,
201 VIS_ACTION_MODE_INSERT
,
202 VIS_ACTION_MODE_REPLACE
,
203 VIS_ACTION_DELETE_CHAR_PREV
,
204 VIS_ACTION_DELETE_CHAR_NEXT
,
205 VIS_ACTION_DELETE_LINE_BEGIN
,
206 VIS_ACTION_DELETE_WORD_PREV
,
207 VIS_ACTION_JUMPLIST_PREV
,
208 VIS_ACTION_JUMPLIST_NEXT
,
209 VIS_ACTION_JUMPLIST_SAVE
,
214 VIS_ACTION_MACRO_RECORD
,
215 VIS_ACTION_MACRO_REPLAY
,
218 VIS_ACTION_REPLACE_CHAR
,
219 VIS_ACTION_TOTILL_REPEAT
,
220 VIS_ACTION_TOTILL_REVERSE
,
221 VIS_ACTION_PROMPT_SEARCH_FORWARD
,
222 VIS_ACTION_PROMPT_SEARCH_BACKWARD
,
223 VIS_ACTION_TILL_LEFT
,
224 VIS_ACTION_TILL_RIGHT
,
225 VIS_ACTION_TILL_LINE_LEFT
,
226 VIS_ACTION_TILL_LINE_RIGHT
,
229 VIS_ACTION_TO_LINE_LEFT
,
230 VIS_ACTION_TO_LINE_RIGHT
,
232 VIS_ACTION_OPERATOR_CHANGE
,
233 VIS_ACTION_OPERATOR_DELETE
,
234 VIS_ACTION_OPERATOR_YANK
,
235 VIS_ACTION_OPERATOR_SHIFT_LEFT
,
236 VIS_ACTION_OPERATOR_SHIFT_RIGHT
,
238 VIS_ACTION_INSERT_NEWLINE
,
239 VIS_ACTION_INSERT_TAB
,
240 VIS_ACTION_INSERT_VERBATIM
,
241 VIS_ACTION_INSERT_REGISTER
,
242 VIS_ACTION_WINDOW_NEXT
,
243 VIS_ACTION_WINDOW_PREV
,
244 VIS_ACTION_APPEND_CHAR_NEXT
,
245 VIS_ACTION_APPEND_LINE_END
,
246 VIS_ACTION_INSERT_LINE_START
,
247 VIS_ACTION_OPEN_LINE_ABOVE
,
248 VIS_ACTION_OPEN_LINE_BELOW
,
249 VIS_ACTION_JOIN_LINES
,
250 VIS_ACTION_JOIN_LINES_TRIM
,
251 VIS_ACTION_PROMPT_SHOW
,
253 VIS_ACTION_SELECTION_FLIP
,
254 VIS_ACTION_WINDOW_REDRAW_TOP
,
255 VIS_ACTION_WINDOW_REDRAW_CENTER
,
256 VIS_ACTION_WINDOW_REDRAW_BOTTOM
,
257 VIS_ACTION_WINDOW_SLIDE_UP
,
258 VIS_ACTION_WINDOW_SLIDE_DOWN
,
259 VIS_ACTION_PUT_AFTER
,
260 VIS_ACTION_PUT_BEFORE
,
261 VIS_ACTION_SELECTIONS_NEW_LINE_ABOVE
,
262 VIS_ACTION_SELECTIONS_NEW_LINE_ABOVE_FIRST
,
263 VIS_ACTION_SELECTIONS_NEW_LINE_BELOW
,
264 VIS_ACTION_SELECTIONS_NEW_LINE_BELOW_LAST
,
265 VIS_ACTION_SELECTIONS_NEW_LINES_BEGIN
,
266 VIS_ACTION_SELECTIONS_NEW_LINES_END
,
267 VIS_ACTION_SELECTIONS_NEW_MATCH_ALL
,
268 VIS_ACTION_SELECTIONS_NEW_MATCH_NEXT
,
269 VIS_ACTION_SELECTIONS_NEW_MATCH_SKIP
,
270 VIS_ACTION_SELECTIONS_ALIGN
,
271 VIS_ACTION_SELECTIONS_ALIGN_INDENT_LEFT
,
272 VIS_ACTION_SELECTIONS_ALIGN_INDENT_RIGHT
,
273 VIS_ACTION_SELECTIONS_REMOVE_ALL
,
274 VIS_ACTION_SELECTIONS_REMOVE_LAST
,
275 VIS_ACTION_SELECTIONS_REMOVE_COLUMN
,
276 VIS_ACTION_SELECTIONS_REMOVE_COLUMN_EXCEPT
,
277 VIS_ACTION_SELECTIONS_PREV
,
278 VIS_ACTION_SELECTIONS_NEXT
,
279 VIS_ACTION_SELECTIONS_ROTATE_LEFT
,
280 VIS_ACTION_SELECTIONS_ROTATE_RIGHT
,
281 VIS_ACTION_SELECTIONS_TRIM
,
282 VIS_ACTION_SELECTIONS_SAVE
,
283 VIS_ACTION_SELECTIONS_RESTORE
,
284 VIS_ACTION_SELECTIONS_UNION
,
285 VIS_ACTION_SELECTIONS_INTERSECT
,
286 VIS_ACTION_SELECTIONS_COMPLEMENT
,
287 VIS_ACTION_SELECTIONS_MINUS
,
288 VIS_ACTION_TEXT_OBJECT_WORD_OUTER
,
289 VIS_ACTION_TEXT_OBJECT_WORD_INNER
,
290 VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER
,
291 VIS_ACTION_TEXT_OBJECT_LONGWORD_INNER
,
292 VIS_ACTION_TEXT_OBJECT_SENTENCE
,
293 VIS_ACTION_TEXT_OBJECT_PARAGRAPH
,
294 VIS_ACTION_TEXT_OBJECT_PARAGRAPH_OUTER
,
295 VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_OUTER
,
296 VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_INNER
,
297 VIS_ACTION_TEXT_OBJECT_PARENTHESIS_OUTER
,
298 VIS_ACTION_TEXT_OBJECT_PARENTHESIS_INNER
,
299 VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_OUTER
,
300 VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_INNER
,
301 VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_OUTER
,
302 VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_INNER
,
303 VIS_ACTION_TEXT_OBJECT_QUOTE_OUTER
,
304 VIS_ACTION_TEXT_OBJECT_QUOTE_INNER
,
305 VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_OUTER
,
306 VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_INNER
,
307 VIS_ACTION_TEXT_OBJECT_BACKTICK_OUTER
,
308 VIS_ACTION_TEXT_OBJECT_BACKTICK_INNER
,
309 VIS_ACTION_TEXT_OBJECT_LINE_OUTER
,
310 VIS_ACTION_TEXT_OBJECT_LINE_INNER
,
311 VIS_ACTION_TEXT_OBJECT_INDENTATION
,
312 VIS_ACTION_TEXT_OBJECT_SEARCH_FORWARD
,
313 VIS_ACTION_TEXT_OBJECT_SEARCH_BACKWARD
,
314 VIS_ACTION_UNICODE_INFO
,
315 VIS_ACTION_UTF8_INFO
,
319 static const KeyAction vis_action
[] = {
320 [VIS_ACTION_EDITOR_SUSPEND
] = {
322 VIS_HELP("Suspend the editor")
325 [VIS_ACTION_CURSOR_CHAR_PREV
] = {
326 "vis-motion-char-prev",
327 VIS_HELP("Move cursor left, to the previous character")
328 movement
, { .i
= VIS_MOVE_CHAR_PREV
}
330 [VIS_ACTION_CURSOR_CHAR_NEXT
] = {
331 "vis-motion-char-next",
332 VIS_HELP("Move cursor right, to the next character")
333 movement
, { .i
= VIS_MOVE_CHAR_NEXT
}
335 [VIS_ACTION_CURSOR_LINE_CHAR_PREV
] = {
336 "vis-motion-line-char-prev",
337 VIS_HELP("Move cursor left, to the previous character on the same line")
338 movement
, { .i
= VIS_MOVE_LINE_CHAR_PREV
}
340 [VIS_ACTION_CURSOR_LINE_CHAR_NEXT
] = {
341 "vis-motion-line-char-next",
342 VIS_HELP("Move cursor right, to the next character on the same line")
343 movement
, { .i
= VIS_MOVE_LINE_CHAR_NEXT
}
345 [VIS_ACTION_CURSOR_CODEPOINT_PREV
] = {
346 "vis-motion-codepoint-prev",
347 VIS_HELP("Move to the previous Unicode codepoint")
348 movement
, { .i
= VIS_MOVE_CODEPOINT_PREV
}
350 [VIS_ACTION_CURSOR_CODEPOINT_NEXT
] = {
351 "vis-motion-codepoint-next",
352 VIS_HELP("Move to the next Unicode codepoint")
353 movement
, { .i
= VIS_MOVE_CODEPOINT_NEXT
}
355 [VIS_ACTION_CURSOR_WORD_START_PREV
] = {
356 "vis-motion-word-start-prev",
357 VIS_HELP("Move cursor words backwards")
358 movement
, { .i
= VIS_MOVE_WORD_START_PREV
}
360 [VIS_ACTION_CURSOR_WORD_START_NEXT
] = {
361 "vis-motion-word-start-next",
362 VIS_HELP("Move cursor words forwards")
363 movement
, { .i
= VIS_MOVE_WORD_START_NEXT
}
365 [VIS_ACTION_CURSOR_WORD_END_PREV
] = {
366 "vis-motion-word-end-prev",
367 VIS_HELP("Move cursor backwards to the end of word")
368 movement
, { .i
= VIS_MOVE_WORD_END_PREV
}
370 [VIS_ACTION_CURSOR_WORD_END_NEXT
] = {
371 "vis-motion-word-end-next",
372 VIS_HELP("Move cursor forward to the end of word")
373 movement
, { .i
= VIS_MOVE_WORD_END_NEXT
}
375 [VIS_ACTION_CURSOR_LONGWORD_START_PREV
] = {
376 "vis-motion-bigword-start-prev",
377 VIS_HELP("Move cursor WORDS backwards")
378 movement
, { .i
= VIS_MOVE_LONGWORD_START_PREV
}
380 [VIS_ACTION_CURSOR_LONGWORD_START_NEXT
] = {
381 "vis-motion-bigword-start-next",
382 VIS_HELP("Move cursor WORDS forwards")
383 movement
, { .i
= VIS_MOVE_LONGWORD_START_NEXT
}
385 [VIS_ACTION_CURSOR_LONGWORD_END_PREV
] = {
386 "vis-motion-bigword-end-prev",
387 VIS_HELP("Move cursor backwards to the end of WORD")
388 movement
, { .i
= VIS_MOVE_LONGWORD_END_PREV
}
390 [VIS_ACTION_CURSOR_LONGWORD_END_NEXT
] = {
391 "vis-motion-bigword-end-next",
392 VIS_HELP("Move cursor forward to the end of WORD")
393 movement
, { .i
= VIS_MOVE_LONGWORD_END_NEXT
}
395 [VIS_ACTION_CURSOR_LINE_UP
] = {
396 "vis-motion-line-up",
397 VIS_HELP("Move cursor line upwards")
398 movement
, { .i
= VIS_MOVE_LINE_UP
}
400 [VIS_ACTION_CURSOR_LINE_DOWN
] = {
401 "vis-motion-line-down",
402 VIS_HELP("Move cursor line downwards")
403 movement
, { .i
= VIS_MOVE_LINE_DOWN
}
405 [VIS_ACTION_CURSOR_LINE_START
] = {
406 "vis-motion-line-start",
407 VIS_HELP("Move cursor to first non-blank character of the line")
408 movement
, { .i
= VIS_MOVE_LINE_START
}
410 [VIS_ACTION_CURSOR_LINE_FINISH
] = {
411 "vis-motion-line-finish",
412 VIS_HELP("Move cursor to last non-blank character of the line")
413 movement
, { .i
= VIS_MOVE_LINE_FINISH
}
415 [VIS_ACTION_CURSOR_LINE_BEGIN
] = {
416 "vis-motion-line-begin",
417 VIS_HELP("Move cursor to first character of the line")
418 movement
, { .i
= VIS_MOVE_LINE_BEGIN
}
420 [VIS_ACTION_CURSOR_LINE_END
] = {
421 "vis-motion-line-end",
422 VIS_HELP("Move cursor to end of the line")
423 movement
, { .i
= VIS_MOVE_LINE_END
}
425 [VIS_ACTION_CURSOR_SCREEN_LINE_UP
] = {
426 "vis-motion-screenline-up",
427 VIS_HELP("Move cursor screen/display line upwards")
428 movement
, { .i
= VIS_MOVE_SCREEN_LINE_UP
}
430 [VIS_ACTION_CURSOR_SCREEN_LINE_DOWN
] = {
431 "vis-motion-screenline-down",
432 VIS_HELP("Move cursor screen/display line downwards")
433 movement
, { .i
= VIS_MOVE_SCREEN_LINE_DOWN
}
435 [VIS_ACTION_CURSOR_SCREEN_LINE_BEGIN
] = {
436 "vis-motion-screenline-begin",
437 VIS_HELP("Move cursor to beginning of screen/display line")
438 movement
, { .i
= VIS_MOVE_SCREEN_LINE_BEGIN
}
440 [VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE
] = {
441 "vis-motion-screenline-middle",
442 VIS_HELP("Move cursor to middle of screen/display line")
443 movement
, { .i
= VIS_MOVE_SCREEN_LINE_MIDDLE
}
445 [VIS_ACTION_CURSOR_SCREEN_LINE_END
] = {
446 "vis-motion-screenline-end",
447 VIS_HELP("Move cursor to end of screen/display line")
448 movement
, { .i
= VIS_MOVE_SCREEN_LINE_END
}
450 [VIS_ACTION_CURSOR_PERCENT
] = {
451 "vis-motion-percent",
452 VIS_HELP("Move to count % of file or matching item")
455 [VIS_ACTION_CURSOR_BYTE
] = {
457 VIS_HELP("Move to absolute byte position")
458 movement
, { .i
= VIS_MOVE_BYTE
}
460 [VIS_ACTION_CURSOR_BYTE_LEFT
] = {
461 "vis-motion-byte-left",
462 VIS_HELP("Move count bytes to the left")
463 movement
, { .i
= VIS_MOVE_BYTE_LEFT
}
465 [VIS_ACTION_CURSOR_BYTE_RIGHT
] = {
466 "vis-motion-byte-right",
467 VIS_HELP("Move count bytes to the right")
468 movement
, { .i
= VIS_MOVE_BYTE_RIGHT
}
470 [VIS_ACTION_CURSOR_PARAGRAPH_PREV
] = {
471 "vis-motion-paragraph-prev",
472 VIS_HELP("Move cursor paragraph backward")
473 movement
, { .i
= VIS_MOVE_PARAGRAPH_PREV
}
475 [VIS_ACTION_CURSOR_PARAGRAPH_NEXT
] = {
476 "vis-motion-paragraph-next",
477 VIS_HELP("Move cursor paragraph forward")
478 movement
, { .i
= VIS_MOVE_PARAGRAPH_NEXT
}
480 [VIS_ACTION_CURSOR_SENTENCE_PREV
] = {
481 "vis-motion-sentence-prev",
482 VIS_HELP("Move cursor sentence backward")
483 movement
, { .i
= VIS_MOVE_SENTENCE_PREV
}
485 [VIS_ACTION_CURSOR_SENTENCE_NEXT
] = {
486 "vis-motion-sentence-next",
487 VIS_HELP("Move cursor sentence forward")
488 movement
, { .i
= VIS_MOVE_SENTENCE_NEXT
}
490 [VIS_ACTION_CURSOR_BLOCK_START
] = {
491 "vis-motion-block-start",
492 VIS_HELP("Move cursor to the opening curly brace in a block")
493 movement
, { .i
= VIS_MOVE_BLOCK_START
}
495 [VIS_ACTION_CURSOR_BLOCK_END
] = {
496 "vis-motion-block-end",
497 VIS_HELP("Move cursor to the closing curly brace in a block")
498 movement
, { .i
= VIS_MOVE_BLOCK_END
}
500 [VIS_ACTION_CURSOR_PARENTHESIS_START
] = {
501 "vis-motion-parenthesis-start",
502 VIS_HELP("Move cursor to the opening parenthesis inside a pair of parentheses")
503 movement
, { .i
= VIS_MOVE_PARENTHESIS_START
}
505 [VIS_ACTION_CURSOR_PARENTHESIS_END
] = {
506 "vis-motion-parenthesis-end",
507 VIS_HELP("Move cursor to the closing parenthesis inside a pair of parentheses")
508 movement
, { .i
= VIS_MOVE_PARENTHESIS_END
}
510 [VIS_ACTION_CURSOR_COLUMN
] = {
512 VIS_HELP("Move cursor to given column of current line")
513 movement
, { .i
= VIS_MOVE_COLUMN
}
515 [VIS_ACTION_CURSOR_LINE_FIRST
] = {
516 "vis-motion-line-first",
517 VIS_HELP("Move cursor to given line (defaults to first)")
518 gotoline
, { .i
= -1 }
520 [VIS_ACTION_CURSOR_LINE_LAST
] = {
521 "vis-motion-line-last",
522 VIS_HELP("Move cursor to given line (defaults to last)")
523 gotoline
, { .i
= +1 }
525 [VIS_ACTION_CURSOR_WINDOW_LINE_TOP
] = {
526 "vis-motion-window-line-top",
527 VIS_HELP("Move cursor to top line of the window")
528 movement
, { .i
= VIS_MOVE_WINDOW_LINE_TOP
}
530 [VIS_ACTION_CURSOR_WINDOW_LINE_MIDDLE
] = {
531 "vis-motion-window-line-middle",
532 VIS_HELP("Move cursor to middle line of the window")
533 movement
, { .i
= VIS_MOVE_WINDOW_LINE_MIDDLE
}
535 [VIS_ACTION_CURSOR_WINDOW_LINE_BOTTOM
] = {
536 "vis-motion-window-line-bottom",
537 VIS_HELP("Move cursor to bottom line of the window")
538 movement
, { .i
= VIS_MOVE_WINDOW_LINE_BOTTOM
}
540 [VIS_ACTION_CURSOR_SEARCH_REPEAT_FORWARD
] = {
541 "vis-motion-search-repeat-forward",
542 VIS_HELP("Move cursor to next match in forward direction")
543 movement
, { .i
= VIS_MOVE_SEARCH_REPEAT_FORWARD
}
545 [VIS_ACTION_CURSOR_SEARCH_REPEAT_BACKWARD
] = {
546 "vis-motion-search-repeat-backward",
547 VIS_HELP("Move cursor to previous match in backward direction")
548 movement
, { .i
= VIS_MOVE_SEARCH_REPEAT_BACKWARD
}
550 [VIS_ACTION_CURSOR_SEARCH_REPEAT
] = {
551 "vis-motion-search-repeat",
552 VIS_HELP("Move cursor to next match")
553 movement
, { .i
= VIS_MOVE_SEARCH_REPEAT
}
555 [VIS_ACTION_CURSOR_SEARCH_REPEAT_REVERSE
] = {
556 "vis-motion-search-repeat-reverse",
557 VIS_HELP("Move cursor to next match in opposite direction")
558 movement
, { .i
= VIS_MOVE_SEARCH_REPEAT_REVERSE
}
560 [VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD
] = {
561 "vis-motion-search-word-forward",
562 VIS_HELP("Move cursor to next occurrence of the word under cursor")
563 movement
, { .i
= VIS_MOVE_SEARCH_WORD_FORWARD
}
565 [VIS_ACTION_CURSOR_SEARCH_WORD_BACKWARD
] = {
566 "vis-motion-search-word-backward",
567 VIS_HELP("Move cursor to previous occurrence of the word under cursor")
568 movement
, { .i
= VIS_MOVE_SEARCH_WORD_BACKWARD
}
570 [VIS_ACTION_WINDOW_PAGE_UP
] = {
571 "vis-window-page-up",
572 VIS_HELP("Scroll window pages backwards (upwards)")
573 wscroll
, { .i
= -PAGE
}
575 [VIS_ACTION_WINDOW_HALFPAGE_UP
] = {
576 "vis-window-halfpage-up",
577 VIS_HELP("Scroll window half pages backwards (upwards)")
578 wscroll
, { .i
= -PAGE_HALF
}
580 [VIS_ACTION_WINDOW_PAGE_DOWN
] = {
581 "vis-window-page-down",
582 VIS_HELP("Scroll window pages forwards (downwards)")
583 wscroll
, { .i
= +PAGE
}
585 [VIS_ACTION_WINDOW_HALFPAGE_DOWN
] = {
586 "vis-window-halfpage-down",
587 VIS_HELP("Scroll window half pages forwards (downwards)")
588 wscroll
, { .i
= +PAGE_HALF
}
590 [VIS_ACTION_MODE_NORMAL
] = {
592 VIS_HELP("Enter normal mode")
593 switchmode
, { .i
= VIS_MODE_NORMAL
}
595 [VIS_ACTION_MODE_NORMAL_ESCAPE
] = {
596 "vis-mode-normal-escape",
597 VIS_HELP("Reset count or remove all non-primary selections")
600 [VIS_ACTION_MODE_VISUAL
] = {
601 "vis-mode-visual-charwise",
602 VIS_HELP("Enter characterwise visual mode")
603 switchmode
, { .i
= VIS_MODE_VISUAL
}
605 [VIS_ACTION_MODE_VISUAL_ESCAPE
] = {
606 "vis-mode-visual-escape",
607 VIS_HELP("Reset count or switch to normal mode")
610 [VIS_ACTION_MODE_VISUAL_LINE
] = {
611 "vis-mode-visual-linewise",
612 VIS_HELP("Enter linewise visual mode")
613 switchmode
, { .i
= VIS_MODE_VISUAL_LINE
}
615 [VIS_ACTION_MODE_INSERT
] = {
617 VIS_HELP("Enter insert mode")
618 insertmode
, { .i
= VIS_MOVE_NOP
}
620 [VIS_ACTION_MODE_REPLACE
] = {
622 VIS_HELP("Enter replace mode")
623 replacemode
, { .i
= VIS_MOVE_NOP
}
625 [VIS_ACTION_DELETE_CHAR_PREV
] = {
626 "vis-delete-char-prev",
627 VIS_HELP("Delete the previous character")
628 delete, { .i
= VIS_MOVE_CHAR_PREV
}
630 [VIS_ACTION_DELETE_CHAR_NEXT
] = {
631 "vis-delete-char-next",
632 VIS_HELP("Delete the next character")
633 delete, { .i
= VIS_MOVE_CHAR_NEXT
}
635 [VIS_ACTION_DELETE_LINE_BEGIN
] = {
636 "vis-delete-line-begin",
637 VIS_HELP("Delete until the start of the current line")
638 delete, { .i
= VIS_MOVE_LINE_BEGIN
}
640 [VIS_ACTION_DELETE_WORD_PREV
] = {
641 "vis-delete-word-prev",
642 VIS_HELP("Delete the previous WORD")
643 delete, { .i
= VIS_MOVE_WORD_START_PREV
}
645 [VIS_ACTION_JUMPLIST_PREV
] = {
647 VIS_HELP("Go to older cursor position in jump list")
648 jumplist
, { .i
= -1 }
650 [VIS_ACTION_JUMPLIST_NEXT
] = {
652 VIS_HELP("Go to newer cursor position in jump list")
653 jumplist
, { .i
= +1 }
655 [VIS_ACTION_JUMPLIST_SAVE
] = {
657 VIS_HELP("Save current selections in jump list")
660 [VIS_ACTION_UNDO
] = {
662 VIS_HELP("Undo last change")
665 [VIS_ACTION_REDO
] = {
667 VIS_HELP("Redo last change")
670 [VIS_ACTION_EARLIER
] = {
672 VIS_HELP("Goto older text state")
675 [VIS_ACTION_LATER
] = {
677 VIS_HELP("Goto newer text state")
680 [VIS_ACTION_MACRO_RECORD
] = {
682 VIS_HELP("Record macro into given register")
685 [VIS_ACTION_MACRO_REPLAY
] = {
687 VIS_HELP("Replay macro, execute the content of the given register")
690 [VIS_ACTION_MARK
] = {
692 VIS_HELP("Use given mark for next action")
695 [VIS_ACTION_REDRAW
] = {
697 VIS_HELP("Redraw current editor content")
698 call
, { .f
= vis_redraw
}
700 [VIS_ACTION_REPLACE_CHAR
] = {
702 VIS_HELP("Replace the character under the cursor")
705 [VIS_ACTION_TOTILL_REPEAT
] = {
706 "vis-motion-totill-repeat",
707 VIS_HELP("Repeat latest to/till motion")
708 movement
, { .i
= VIS_MOVE_TOTILL_REPEAT
}
710 [VIS_ACTION_TOTILL_REVERSE
] = {
711 "vis-motion-totill-reverse",
712 VIS_HELP("Repeat latest to/till motion but in opposite direction")
713 movement
, { .i
= VIS_MOVE_TOTILL_REVERSE
}
715 [VIS_ACTION_PROMPT_SEARCH_FORWARD
] = {
716 "vis-search-forward",
717 VIS_HELP("Search forward")
718 prompt_show
, { .s
= "/" }
720 [VIS_ACTION_PROMPT_SEARCH_BACKWARD
] = {
721 "vis-search-backward",
722 VIS_HELP("Search backward")
723 prompt_show
, { .s
= "?" }
725 [VIS_ACTION_TILL_LEFT
] = {
726 "vis-motion-till-left",
727 VIS_HELP("Till after the occurrence of character to the left")
728 movement_key
, { .i
= VIS_MOVE_TILL_LEFT
}
730 [VIS_ACTION_TILL_RIGHT
] = {
731 "vis-motion-till-right",
732 VIS_HELP("Till before the occurrence of character to the right")
733 movement_key
, { .i
= VIS_MOVE_TILL_RIGHT
}
735 [VIS_ACTION_TILL_LINE_LEFT
] = {
736 "vis-motion-till-line-left",
737 VIS_HELP("Till after the occurrence of character to the left on the current line")
738 movement_key
, { .i
= VIS_MOVE_TILL_LINE_LEFT
}
740 [VIS_ACTION_TILL_LINE_RIGHT
] = {
741 "vis-motion-till-line-right",
742 VIS_HELP("Till before the occurrence of character to the right on the current line")
743 movement_key
, { .i
= VIS_MOVE_TILL_LINE_RIGHT
}
745 [VIS_ACTION_TO_LEFT
] = {
746 "vis-motion-to-left",
747 VIS_HELP("To the first occurrence of character to the left")
748 movement_key
, { .i
= VIS_MOVE_TO_LEFT
}
750 [VIS_ACTION_TO_RIGHT
] = {
751 "vis-motion-to-right",
752 VIS_HELP("To the first occurrence of character to the right")
753 movement_key
, { .i
= VIS_MOVE_TO_RIGHT
}
755 [VIS_ACTION_TO_LINE_LEFT
] = {
756 "vis-motion-to-line-left",
757 VIS_HELP("To the first occurrence of character to the left on the current line")
758 movement_key
, { .i
= VIS_MOVE_TO_LINE_LEFT
}
760 [VIS_ACTION_TO_LINE_RIGHT
] = {
761 "vis-motion-to-line-right",
762 VIS_HELP("To the first occurrence of character to the right on the current line")
763 movement_key
, { .i
= VIS_MOVE_TO_LINE_RIGHT
}
765 [VIS_ACTION_REGISTER
] = {
767 VIS_HELP("Use given register for next operator")
770 [VIS_ACTION_OPERATOR_CHANGE
] = {
771 "vis-operator-change",
772 VIS_HELP("Change operator")
773 operator, { .i
= VIS_OP_CHANGE
}
775 [VIS_ACTION_OPERATOR_DELETE
] = {
776 "vis-operator-delete",
777 VIS_HELP("Delete operator")
778 operator, { .i
= VIS_OP_DELETE
}
780 [VIS_ACTION_OPERATOR_YANK
] = {
782 VIS_HELP("Yank operator")
783 operator, { .i
= VIS_OP_YANK
}
785 [VIS_ACTION_OPERATOR_SHIFT_LEFT
] = {
786 "vis-operator-shift-left",
787 VIS_HELP("Shift left operator")
788 operator, { .i
= VIS_OP_SHIFT_LEFT
}
790 [VIS_ACTION_OPERATOR_SHIFT_RIGHT
] = {
791 "vis-operator-shift-right",
792 VIS_HELP("Shift right operator")
793 operator, { .i
= VIS_OP_SHIFT_RIGHT
}
795 [VIS_ACTION_COUNT
] = {
797 VIS_HELP("Count specifier")
800 [VIS_ACTION_INSERT_NEWLINE
] = {
801 "vis-insert-newline",
802 VIS_HELP("Insert a line break (depending on file type)")
803 call
, { .f
= vis_insert_nl
}
805 [VIS_ACTION_INSERT_TAB
] = {
807 VIS_HELP("Insert a tab (might be converted to spaces)")
808 call
, { .f
= vis_insert_tab
}
810 [VIS_ACTION_INSERT_VERBATIM
] = {
811 "vis-insert-verbatim",
812 VIS_HELP("Insert Unicode character based on code point")
815 [VIS_ACTION_INSERT_REGISTER
] = {
816 "vis-insert-register",
817 VIS_HELP("Insert specified register content")
820 [VIS_ACTION_WINDOW_NEXT
] = {
822 VIS_HELP("Focus next window")
823 call
, { .f
= vis_window_next
}
825 [VIS_ACTION_WINDOW_PREV
] = {
827 VIS_HELP("Focus previous window")
828 call
, { .f
= vis_window_prev
}
830 [VIS_ACTION_APPEND_CHAR_NEXT
] = {
831 "vis-append-char-next",
832 VIS_HELP("Append text after the cursor")
833 insertmode
, { .i
= VIS_MOVE_LINE_CHAR_NEXT
}
835 [VIS_ACTION_APPEND_LINE_END
] = {
836 "vis-append-line-end",
837 VIS_HELP("Append text after the end of the line")
838 insertmode
, { .i
= VIS_MOVE_LINE_END
},
840 [VIS_ACTION_INSERT_LINE_START
] = {
841 "vis-insert-line-start",
842 VIS_HELP("Insert text before the first non-blank in the line")
843 insertmode
, { .i
= VIS_MOVE_LINE_START
},
845 [VIS_ACTION_OPEN_LINE_ABOVE
] = {
846 "vis-open-line-above",
847 VIS_HELP("Begin a new line above the cursor")
848 openline
, { .i
= -1 }
850 [VIS_ACTION_OPEN_LINE_BELOW
] = {
851 "vis-open-line-below",
852 VIS_HELP("Begin a new line below the cursor")
853 openline
, { .i
= +1 }
855 [VIS_ACTION_JOIN_LINES
] = {
857 VIS_HELP("Join selected lines")
860 [VIS_ACTION_JOIN_LINES_TRIM
] = {
861 "vis-join-lines-trim",
862 VIS_HELP("Join selected lines, remove white space")
865 [VIS_ACTION_PROMPT_SHOW
] = {
867 VIS_HELP("Show editor command line prompt")
868 prompt_show
, { .s
= ":" }
870 [VIS_ACTION_REPEAT
] = {
872 VIS_HELP("Repeat latest editor command")
875 [VIS_ACTION_SELECTION_FLIP
] = {
876 "vis-selection-flip",
877 VIS_HELP("Flip selection, move cursor to other end")
880 [VIS_ACTION_WINDOW_REDRAW_TOP
] = {
881 "vis-window-redraw-top",
882 VIS_HELP("Redraw cursor line at the top of the window")
883 window
, { .w
= view_redraw_top
}
885 [VIS_ACTION_WINDOW_REDRAW_CENTER
] = {
886 "vis-window-redraw-center",
887 VIS_HELP("Redraw cursor line at the center of the window")
888 window
, { .w
= view_redraw_center
}
890 [VIS_ACTION_WINDOW_REDRAW_BOTTOM
] = {
891 "vis-window-redraw-bottom",
892 VIS_HELP("Redraw cursor line at the bottom of the window")
893 window
, { .w
= view_redraw_bottom
}
895 [VIS_ACTION_WINDOW_SLIDE_UP
] = {
896 "vis-window-slide-up",
897 VIS_HELP("Slide window content upwards")
900 [VIS_ACTION_WINDOW_SLIDE_DOWN
] = {
901 "vis-window-slide-down",
902 VIS_HELP("Slide window content downwards")
905 [VIS_ACTION_PUT_AFTER
] = {
907 VIS_HELP("Put text after the cursor")
908 operator, { .i
= VIS_OP_PUT_AFTER
}
910 [VIS_ACTION_PUT_BEFORE
] = {
912 VIS_HELP("Put text before the cursor")
913 operator, { .i
= VIS_OP_PUT_BEFORE
}
915 [VIS_ACTION_SELECTIONS_NEW_LINE_ABOVE
] = {
916 "vis-selection-new-lines-above",
917 VIS_HELP("Create a new selection on the line above")
918 selections_new
, { .i
= -1 }
920 [VIS_ACTION_SELECTIONS_NEW_LINE_ABOVE_FIRST
] = {
921 "vis-selection-new-lines-above-first",
922 VIS_HELP("Create a new selection on the line above the first selection")
923 selections_new
, { .i
= INT_MIN
}
925 [VIS_ACTION_SELECTIONS_NEW_LINE_BELOW
] = {
926 "vis-selection-new-lines-below",
927 VIS_HELP("Create a new selection on the line below")
928 selections_new
, { .i
= +1 }
930 [VIS_ACTION_SELECTIONS_NEW_LINE_BELOW_LAST
] = {
931 "vis-selection-new-lines-below-last",
932 VIS_HELP("Create a new selection on the line below the last selection")
933 selections_new
, { .i
= INT_MAX
}
935 [VIS_ACTION_SELECTIONS_NEW_LINES_BEGIN
] = {
936 "vis-selection-new-lines-begin",
937 VIS_HELP("Create a new selection at the start of every line covered by selection")
938 operator, { .i
= VIS_OP_CURSOR_SOL
}
940 [VIS_ACTION_SELECTIONS_NEW_LINES_END
] = {
941 "vis-selection-new-lines-end",
942 VIS_HELP("Create a new selection at the end of every line covered by selection")
943 operator, { .i
= VIS_OP_CURSOR_EOL
}
945 [VIS_ACTION_SELECTIONS_NEW_MATCH_ALL
] = {
946 "vis-selection-new-match-all",
947 VIS_HELP("Select all regions matching the current selection")
948 selections_match_next
, { .b
= true }
950 [VIS_ACTION_SELECTIONS_NEW_MATCH_NEXT
] = {
951 "vis-selection-new-match-next",
952 VIS_HELP("Select the next region matching the current selection")
953 selections_match_next
,
955 [VIS_ACTION_SELECTIONS_NEW_MATCH_SKIP
] = {
956 "vis-selection-new-match-skip",
957 VIS_HELP("Clear current selection, but select next match")
958 selections_match_skip
,
960 [VIS_ACTION_SELECTIONS_ALIGN
] = {
961 "vis-selections-align",
962 VIS_HELP("Try to align all selections on the same column")
965 [VIS_ACTION_SELECTIONS_ALIGN_INDENT_LEFT
] = {
966 "vis-selections-align-indent-left",
967 VIS_HELP("Left-align all selections by inserting spaces")
968 selections_align_indent
, { .i
= -1 }
970 [VIS_ACTION_SELECTIONS_ALIGN_INDENT_RIGHT
] = {
971 "vis-selections-align-indent-right",
972 VIS_HELP("Right-align all selections by inserting spaces")
973 selections_align_indent
, { .i
= +1 }
975 [VIS_ACTION_SELECTIONS_REMOVE_ALL
] = {
976 "vis-selections-remove-all",
977 VIS_HELP("Remove all but the primary selection")
980 [VIS_ACTION_SELECTIONS_REMOVE_LAST
] = {
981 "vis-selections-remove-last",
982 VIS_HELP("Remove primary selection")
985 [VIS_ACTION_SELECTIONS_REMOVE_COLUMN
] = {
986 "vis-selections-remove-column",
987 VIS_HELP("Remove count selection column")
988 selections_remove_column
, { .i
= 1 }
990 [VIS_ACTION_SELECTIONS_REMOVE_COLUMN_EXCEPT
] = {
991 "vis-selections-remove-column-except",
992 VIS_HELP("Remove all but the count selection column")
993 selections_remove_column_except
, { .i
= 1 }
995 [VIS_ACTION_SELECTIONS_PREV
] = {
996 "vis-selection-prev",
997 VIS_HELP("Move to the previous selection")
998 selections_navigate
, { .i
= -PAGE_HALF
}
1000 [VIS_ACTION_SELECTIONS_NEXT
] = {
1001 "vis-selection-next",
1002 VIS_HELP("Move to the next selection")
1003 selections_navigate
, { .i
= +PAGE_HALF
}
1005 [VIS_ACTION_SELECTIONS_ROTATE_LEFT
] = {
1006 "vis-selections-rotate-left",
1007 VIS_HELP("Rotate selections left")
1008 selections_rotate
, { .i
= -1 }
1010 [VIS_ACTION_SELECTIONS_ROTATE_RIGHT
] = {
1011 "vis-selections-rotate-right",
1012 VIS_HELP("Rotate selections right")
1013 selections_rotate
, { .i
= +1 }
1015 [VIS_ACTION_SELECTIONS_TRIM
] = {
1016 "vis-selections-trim",
1017 VIS_HELP("Remove leading and trailing white space from selections")
1020 [VIS_ACTION_SELECTIONS_SAVE
] = {
1021 "vis-selections-save",
1022 VIS_HELP("Save currently active selections to mark")
1025 [VIS_ACTION_SELECTIONS_RESTORE
] = {
1026 "vis-selections-restore",
1027 VIS_HELP("Restore selections from mark")
1030 [VIS_ACTION_SELECTIONS_UNION
] = {
1031 "vis-selections-union",
1032 VIS_HELP("Add selections from mark")
1035 [VIS_ACTION_SELECTIONS_INTERSECT
] = {
1036 "vis-selections-intersect",
1037 VIS_HELP("Intersect with selections from mark")
1038 selections_intersect
1040 [VIS_ACTION_SELECTIONS_COMPLEMENT
] = {
1041 "vis-selections-complement",
1042 VIS_HELP("Complement selections")
1043 selections_complement
1045 [VIS_ACTION_SELECTIONS_MINUS
] = {
1046 "vis-selections-minus",
1047 VIS_HELP("Subtract selections from mark")
1050 [VIS_ACTION_TEXT_OBJECT_WORD_OUTER
] = {
1051 "vis-textobject-word-outer",
1052 VIS_HELP("A word leading and trailing whitespace included")
1053 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_WORD
}
1055 [VIS_ACTION_TEXT_OBJECT_WORD_INNER
] = {
1056 "vis-textobject-word-inner",
1057 VIS_HELP("A word leading and trailing whitespace excluded")
1058 textobj
, { .i
= VIS_TEXTOBJECT_INNER_WORD
}
1060 [VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER
] = {
1061 "vis-textobject-bigword-outer",
1062 VIS_HELP("A WORD leading and trailing whitespace included")
1063 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_LONGWORD
}
1065 [VIS_ACTION_TEXT_OBJECT_LONGWORD_INNER
] = {
1066 "vis-textobject-bigword-inner",
1067 VIS_HELP("A WORD leading and trailing whitespace excluded")
1068 textobj
, { .i
= VIS_TEXTOBJECT_INNER_LONGWORD
}
1070 [VIS_ACTION_TEXT_OBJECT_SENTENCE
] = {
1071 "vis-textobject-sentence",
1072 VIS_HELP("A sentence")
1073 textobj
, { .i
= VIS_TEXTOBJECT_SENTENCE
}
1075 [VIS_ACTION_TEXT_OBJECT_PARAGRAPH
] = {
1076 "vis-textobject-paragraph",
1077 VIS_HELP("A paragraph")
1078 textobj
, { .i
= VIS_TEXTOBJECT_PARAGRAPH
}
1080 [VIS_ACTION_TEXT_OBJECT_PARAGRAPH_OUTER
] = {
1081 "vis-textobject-paragraph-outer",
1082 VIS_HELP("A paragraph (outer variant)")
1083 textobj
, { .i
= VIS_TEXTOBJECT_PARAGRAPH_OUTER
}
1085 [VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_OUTER
] = {
1086 "vis-textobject-square-bracket-outer",
1087 VIS_HELP("[] block (outer variant)")
1088 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET
}
1090 [VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_INNER
] = {
1091 "vis-textobject-square-bracket-inner",
1092 VIS_HELP("[] block (inner variant)")
1093 textobj
, { .i
= VIS_TEXTOBJECT_INNER_SQUARE_BRACKET
}
1095 [VIS_ACTION_TEXT_OBJECT_PARENTHESIS_OUTER
] = {
1096 "vis-textobject-parenthesis-outer",
1097 VIS_HELP("() block (outer variant)")
1098 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_PARENTHESIS
}
1100 [VIS_ACTION_TEXT_OBJECT_PARENTHESIS_INNER
] = {
1101 "vis-textobject-parenthesis-inner",
1102 VIS_HELP("() block (inner variant)")
1103 textobj
, { .i
= VIS_TEXTOBJECT_INNER_PARENTHESIS
}
1105 [VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_OUTER
] = {
1106 "vis-textobject-angle-bracket-outer",
1107 VIS_HELP("<> block (outer variant)")
1108 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_ANGLE_BRACKET
}
1110 [VIS_ACTION_TEXT_OBJECT_ANGLE_BRACKET_INNER
] = {
1111 "vis-textobject-angle-bracket-inner",
1112 VIS_HELP("<> block (inner variant)")
1113 textobj
, { .i
= VIS_TEXTOBJECT_INNER_ANGLE_BRACKET
}
1115 [VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_OUTER
] = {
1116 "vis-textobject-curly-bracket-outer",
1117 VIS_HELP("{} block (outer variant)")
1118 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_CURLY_BRACKET
}
1120 [VIS_ACTION_TEXT_OBJECT_CURLY_BRACKET_INNER
] = {
1121 "vis-textobject-curly-bracket-inner",
1122 VIS_HELP("{} block (inner variant)")
1123 textobj
, { .i
= VIS_TEXTOBJECT_INNER_CURLY_BRACKET
}
1125 [VIS_ACTION_TEXT_OBJECT_QUOTE_OUTER
] = {
1126 "vis-textobject-quote-outer",
1127 VIS_HELP("A quoted string, including the quotation marks")
1128 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_QUOTE
}
1130 [VIS_ACTION_TEXT_OBJECT_QUOTE_INNER
] = {
1131 "vis-textobject-quote-inner",
1132 VIS_HELP("A quoted string, excluding the quotation marks")
1133 textobj
, { .i
= VIS_TEXTOBJECT_INNER_QUOTE
}
1135 [VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_OUTER
] = {
1136 "vis-textobject-single-quote-outer",
1137 VIS_HELP("A single quoted string, including the quotation marks")
1138 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_SINGLE_QUOTE
}
1140 [VIS_ACTION_TEXT_OBJECT_SINGLE_QUOTE_INNER
] = {
1141 "vis-textobject-single-quote-inner",
1142 VIS_HELP("A single quoted string, excluding the quotation marks")
1143 textobj
, { .i
= VIS_TEXTOBJECT_INNER_SINGLE_QUOTE
}
1145 [VIS_ACTION_TEXT_OBJECT_BACKTICK_OUTER
] = {
1146 "vis-textobject-backtick-outer",
1147 VIS_HELP("A backtick delimited string (outer variant)")
1148 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_BACKTICK
}
1150 [VIS_ACTION_TEXT_OBJECT_BACKTICK_INNER
] = {
1151 "vis-textobject-backtick-inner",
1152 VIS_HELP("A backtick delimited string (inner variant)")
1153 textobj
, { .i
= VIS_TEXTOBJECT_INNER_BACKTICK
}
1155 [VIS_ACTION_TEXT_OBJECT_LINE_OUTER
] = {
1156 "vis-textobject-line-outer",
1157 VIS_HELP("The whole line")
1158 textobj
, { .i
= VIS_TEXTOBJECT_OUTER_LINE
}
1160 [VIS_ACTION_TEXT_OBJECT_LINE_INNER
] = {
1161 "vis-textobject-line-inner",
1162 VIS_HELP("The whole line, excluding leading and trailing whitespace")
1163 textobj
, { .i
= VIS_TEXTOBJECT_INNER_LINE
}
1165 [VIS_ACTION_TEXT_OBJECT_INDENTATION
] = {
1166 "vis-textobject-indentation",
1167 VIS_HELP("All adjacent lines with the same indentation level as the current one")
1168 textobj
, { .i
= VIS_TEXTOBJECT_INDENTATION
}
1170 [VIS_ACTION_TEXT_OBJECT_SEARCH_FORWARD
] = {
1171 "vis-textobject-search-forward",
1172 VIS_HELP("The next search match in forward direction")
1173 textobj
, { .i
= VIS_TEXTOBJECT_SEARCH_FORWARD
}
1175 [VIS_ACTION_TEXT_OBJECT_SEARCH_BACKWARD
] = {
1176 "vis-textobject-search-backward",
1177 VIS_HELP("The next search match in backward direction")
1178 textobj
, { .i
= VIS_TEXTOBJECT_SEARCH_BACKWARD
}
1180 [VIS_ACTION_UNICODE_INFO
] = {
1182 VIS_HELP("Show Unicode codepoint(s) of character under cursor")
1183 unicode_info
, { .i
= VIS_ACTION_UNICODE_INFO
}
1185 [VIS_ACTION_UTF8_INFO
] = {
1187 VIS_HELP("Show UTF-8 encoded codepoint(s) of character under cursor")
1188 unicode_info
, { .i
= VIS_ACTION_UTF8_INFO
}
1190 [VIS_ACTION_NOP
] = {
1192 VIS_HELP("Ignore key, do nothing")
1199 /** key bindings functions */
1201 static const char *nop(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1205 static const char *macro_record(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1206 if (!vis_macro_record_stop(vis
)) {
1209 const char *next
= vis_keys_next(vis
, keys
);
1210 if (next
- keys
> 1)
1212 enum VisRegister reg
= vis_register_from(vis
, keys
[0]);
1213 vis_macro_record(vis
, reg
);
1220 static const char *macro_replay(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1223 const char *next
= vis_keys_next(vis
, keys
);
1224 if (next
- keys
> 1)
1226 enum VisRegister reg
= vis_register_from(vis
, keys
[0]);
1227 vis_macro_replay(vis
, reg
);
1231 static const char *suspend(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1236 static const char *repeat(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1241 static const char *selections_new(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1242 View
*view
= vis_view(vis
);
1243 bool anchored
= view_selections_anchored(view_selections_primary_get(view
));
1244 VisCountIterator it
= vis_count_iterator_get(vis
, 1);
1245 while (vis_count_iterator_next(&it
)) {
1246 Selection
*sel
= NULL
;
1250 sel
= view_selections_primary_get(view
);
1253 sel
= view_selections(view
);
1256 for (Selection
*s
= view_selections(view
); s
; s
= view_selections_next(s
))
1264 size_t oldpos
= view_cursors_pos(sel
);
1266 view_line_down(sel
);
1267 else if (arg
->i
< 0)
1269 size_t newpos
= view_cursors_pos(sel
);
1270 view_cursors_to(sel
, oldpos
);
1271 Selection
*sel_new
= view_selections_new(view
, newpos
);
1274 sel_new
= view_selections_prev(sel
);
1275 else if (arg
->i
== +1)
1276 sel_new
= view_selections_next(sel
);
1279 view_selections_primary_set(sel_new
);
1280 view_selections_anchor(sel_new
, anchored
);
1283 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
1287 static const char *selections_align(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1288 View
*view
= vis_view(vis
);
1289 Text
*txt
= vis_text(vis
);
1290 int mincol
= INT_MAX
;
1291 for (Selection
*s
= view_selections(view
); s
; s
= view_selections_next(s
)) {
1292 int col
= view_cursors_cell_get(s
);
1293 if (col
>= 0 && col
< mincol
)
1296 for (Selection
*s
= view_selections(view
); s
; s
= view_selections_next(s
)) {
1297 if (view_cursors_cell_set(s
, mincol
) == -1) {
1298 size_t pos
= view_cursors_pos(s
);
1299 size_t col
= text_line_width_set(txt
, pos
, mincol
);
1300 view_cursors_to(s
, col
);
1306 static const char *selections_align_indent(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1307 View
*view
= vis_view(vis
);
1308 Text
*txt
= vis_text(vis
);
1309 bool left_align
= arg
->i
< 0;
1310 int columns
= view_selections_column_count(view
);
1312 for (int i
= 0; i
< columns
; i
++) {
1313 int mincol
= INT_MAX
, maxcol
= 0;
1314 for (Selection
*s
= view_selections_column(view
, i
); s
; s
= view_selections_column_next(s
, i
)) {
1315 Filerange sel
= view_selections_get(s
);
1316 size_t pos
= left_align
? sel
.start
: sel
.end
;
1317 int col
= text_line_width_get(txt
, pos
);
1324 size_t len
= maxcol
- mincol
;
1325 char *buf
= malloc(len
+1);
1328 memset(buf
, ' ', len
);
1330 for (Selection
*s
= view_selections_column(view
, i
); s
; s
= view_selections_column_next(s
, i
)) {
1331 Filerange sel
= view_selections_get(s
);
1332 size_t pos
= left_align
? sel
.start
: sel
.end
;
1333 size_t ipos
= sel
.start
;
1334 int col
= text_line_width_get(txt
, pos
);
1336 size_t off
= maxcol
- col
;
1338 text_insert(txt
, ipos
, buf
, off
);
1349 static const char *selections_clear(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1350 View
*view
= vis_view(vis
);
1351 if (view_selections_count(view
) > 1)
1352 view_selections_dispose_all(view
);
1354 view_selection_clear(view_selections_primary_get(view
));
1358 static Selection
*selection_new(View
*view
, Filerange
*r
, bool isprimary
) {
1359 Text
*txt
= view_text(view
);
1360 size_t pos
= text_char_prev(txt
, r
->end
);
1361 Selection
*s
= view_selections_new(view
, pos
);
1364 view_selections_set(s
, r
);
1365 view_selections_anchor(s
, true);
1367 view_selections_primary_set(s
);
1371 static const char *selections_match_next(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1372 Text
*txt
= vis_text(vis
);
1373 View
*view
= vis_view(vis
);
1374 Selection
*s
= view_selections_primary_get(view
);
1375 Filerange sel
= view_selections_get(s
);
1376 if (!text_range_valid(&sel
))
1379 static bool match_word
;
1381 if (view_selections_count(view
) == 1) {
1382 Filerange word
= text_object_word(txt
, view_cursors_pos(s
));
1383 match_word
= text_range_equal(&sel
, &word
);
1386 Filerange (*find_next
)(Text
*, size_t, const char *) = text_object_word_find_next
;
1387 Filerange (*find_prev
)(Text
*, size_t, const char *) = text_object_word_find_prev
;
1389 find_next
= text_object_find_next
;
1390 find_prev
= text_object_find_prev
;
1393 char *buf
= text_bytes_alloc0(txt
, sel
.start
, text_range_size(&sel
));
1397 bool match_all
= arg
->b
;
1398 Filerange primary
= sel
;
1401 sel
= find_next(txt
, sel
.end
, buf
);
1402 if (!text_range_valid(&sel
))
1404 if (selection_new(view
, &sel
, !match_all
) && !match_all
)
1411 sel
= find_prev(txt
, sel
.start
, buf
);
1412 if (!text_range_valid(&sel
))
1414 if (selection_new(view
, &sel
, !match_all
) && !match_all
)
1423 static const char *selections_match_skip(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1424 View
*view
= vis_view(vis
);
1425 Selection
*sel
= view_selections_primary_get(view
);
1426 keys
= selections_match_next(vis
, keys
, arg
);
1427 if (sel
!= view_selections_primary_get(view
))
1428 view_selections_dispose(sel
);
1432 static const char *selections_remove(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1433 View
*view
= vis_view(vis
);
1434 view_selections_dispose(view_selections_primary_get(view
));
1435 view_cursor_to(view
, view_cursor_get(view
));
1439 static const char *selections_remove_column(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1440 View
*view
= vis_view(vis
);
1441 int max
= view_selections_column_count(view
);
1442 int column
= vis_count_get_default(vis
, arg
->i
) - 1;
1445 if (view_selections_count(view
) == 1) {
1446 vis_keys_feed(vis
, "<Escape>");
1450 for (Selection
*s
= view_selections_column(view
, column
), *next
; s
; s
= next
) {
1451 next
= view_selections_column_next(s
, column
);
1452 view_selections_dispose(s
);
1455 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
1459 static const char *selections_remove_column_except(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1460 View
*view
= vis_view(vis
);
1461 int max
= view_selections_column_count(view
);
1462 int column
= vis_count_get_default(vis
, arg
->i
) - 1;
1465 if (view_selections_count(view
) == 1) {
1470 Selection
*sel
= view_selections(view
);
1471 Selection
*col
= view_selections_column(view
, column
);
1472 for (Selection
*next
; sel
; sel
= next
) {
1473 next
= view_selections_next(sel
);
1475 col
= view_selections_column_next(col
, column
);
1477 view_selections_dispose(sel
);
1480 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
1484 static const char *selections_navigate(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1485 View
*view
= vis_view(vis
);
1486 if (view_selections_count(view
) == 1)
1487 return wscroll(vis
, keys
, arg
);
1488 Selection
*s
= view_selections_primary_get(view
);
1489 VisCountIterator it
= vis_count_iterator_get(vis
, 1);
1490 while (vis_count_iterator_next(&it
)) {
1492 s
= view_selections_next(s
);
1494 s
= view_selections(view
);
1496 s
= view_selections_prev(s
);
1498 s
= view_selections(view
);
1499 for (Selection
*n
= s
; n
; n
= view_selections_next(n
))
1504 view_selections_primary_set(s
);
1505 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
1509 static const char *selections_rotate(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1518 Text
*txt
= vis_text(vis
);
1519 View
*view
= vis_view(vis
);
1520 int columns
= view_selections_column_count(view
);
1521 int selections
= columns
== 1 ? view_selections_count(view
) : columns
;
1522 int count
= vis_count_get_default(vis
, 1);
1523 array_init_sized(&arr
, sizeof(Rotate
));
1524 if (!array_reserve(&arr
, selections
))
1528 for (Selection
*s
= view_selections(view
), *next
; s
; s
= next
) {
1529 next
= view_selections_next(s
);
1530 size_t line_next
= 0;
1532 Filerange sel
= view_selections_get(s
);
1535 rot
.len
= text_range_size(&sel
);
1536 if ((rot
.data
= malloc(rot
.len
)))
1537 rot
.len
= text_bytes_get(txt
, sel
.start
, rot
.len
, rot
.data
);
1540 array_add(&arr
, &rot
);
1543 line
= text_lineno_by_pos(txt
, view_cursors_pos(s
));
1545 line_next
= text_lineno_by_pos(txt
, view_cursors_pos(next
));
1546 if (!next
|| (columns
> 1 && line
!= line_next
)) {
1547 size_t len
= array_length(&arr
);
1548 size_t off
= arg
->i
> 0 ? count
% len
: len
- (count
% len
);
1549 for (size_t i
= 0; i
< len
; i
++) {
1550 size_t j
= (i
+ off
) % len
;
1551 Rotate
*oldrot
= array_get(&arr
, i
);
1552 Rotate
*newrot
= array_get(&arr
, j
);
1553 if (!oldrot
|| !newrot
|| oldrot
== newrot
)
1555 Filerange newsel
= view_selections_get(newrot
->sel
);
1556 if (!text_range_valid(&newsel
))
1558 if (!text_delete_range(txt
, &newsel
))
1560 if (!text_insert(txt
, newsel
.start
, oldrot
->data
, oldrot
->len
))
1562 newsel
.end
= newsel
.start
+ oldrot
->len
;
1563 view_selections_set(newrot
->sel
, &newsel
);
1571 array_release(&arr
);
1572 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
1576 static const char *selections_trim(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1577 Text
*txt
= vis_text(vis
);
1578 View
*view
= vis_view(vis
);
1579 for (Selection
*s
= view_selections(view
), *next
; s
; s
= next
) {
1580 next
= view_selections_next(s
);
1581 Filerange sel
= view_selections_get(s
);
1582 if (!text_range_valid(&sel
))
1584 for (char b
; sel
.start
< sel
.end
&& text_byte_get(txt
, sel
.end
-1, &b
)
1585 && isspace((unsigned char)b
); sel
.end
--);
1586 for (char b
; sel
.start
<= sel
.end
&& text_byte_get(txt
, sel
.start
, &b
)
1587 && isspace((unsigned char)b
); sel
.start
++);
1588 if (sel
.start
< sel
.end
) {
1589 view_selections_set(s
, &sel
);
1590 } else if (!view_selections_dispose(s
)) {
1591 vis_mode_switch(vis
, VIS_MODE_NORMAL
);
1597 static void selections_set(Vis
*vis
, View
*view
, Array
*sel
) {
1598 enum VisMode mode
= vis_mode_get(vis
);
1599 bool anchored
= mode
== VIS_MODE_VISUAL
|| mode
== VIS_MODE_VISUAL_LINE
;
1600 view_selections_set_all(view
, sel
, anchored
);
1602 view_selections_clear_all(view
);
1605 static const char *selections_save(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1606 Win
*win
= vis_window(vis
);
1607 View
*view
= vis_view(vis
);
1608 enum VisMark mark
= vis_mark_used(vis
);
1609 Array sel
= view_selections_get_all(view
);
1610 vis_mark_set(win
, mark
, &sel
);
1611 array_release(&sel
);
1616 static const char *selections_restore(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1617 Win
*win
= vis_window(vis
);
1618 View
*view
= vis_view(vis
);
1619 enum VisMark mark
= vis_mark_used(vis
);
1620 Array sel
= vis_mark_get(win
, mark
);
1621 selections_set(vis
, view
, &sel
);
1622 array_release(&sel
);
1627 static const char *selections_union(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1628 Win
*win
= vis_window(vis
);
1629 View
*view
= vis_view(vis
);
1630 enum VisMark mark
= vis_mark_used(vis
);
1631 Array a
= vis_mark_get(win
, mark
);
1632 Array b
= view_selections_get_all(view
);
1634 array_init_from(&sel
, &a
);
1636 size_t i
= 0, j
= 0;
1637 Filerange
*r1
= array_get(&a
, i
), *r2
= array_get(&b
, j
), cur
= text_range_empty();
1639 if (r1
&& text_range_overlap(r1
, &cur
)) {
1640 cur
= text_range_union(r1
, &cur
);
1641 r1
= array_get(&a
, ++i
);
1642 } else if (r2
&& text_range_overlap(r2
, &cur
)) {
1643 cur
= text_range_union(r2
, &cur
);
1644 r2
= array_get(&b
, ++j
);
1646 if (text_range_valid(&cur
))
1647 array_add(&sel
, &cur
);
1650 r2
= array_get(&b
, ++j
);
1653 r1
= array_get(&a
, ++i
);
1655 if (r1
->start
< r2
->start
) {
1657 r1
= array_get(&a
, ++i
);
1660 r2
= array_get(&b
, ++j
);
1666 if (text_range_valid(&cur
))
1667 array_add(&sel
, &cur
);
1669 selections_set(vis
, view
, &sel
);
1674 array_release(&sel
);
1679 static void intersect(Array
*ret
, Array
*a
, Array
*b
) {
1680 size_t i
= 0, j
= 0;
1681 Filerange
*r1
= array_get(a
, i
), *r2
= array_get(b
, j
);
1683 if (text_range_overlap(r1
, r2
)) {
1684 Filerange
new = text_range_intersect(r1
, r2
);
1685 array_add(ret
, &new);
1687 if (r1
->end
< r2
->end
)
1688 r1
= array_get(a
, ++i
);
1690 r2
= array_get(b
, ++j
);
1694 static const char *selections_intersect(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1695 Win
*win
= vis_window(vis
);
1696 View
*view
= vis_view(vis
);
1697 enum VisMark mark
= vis_mark_used(vis
);
1698 Array a
= vis_mark_get(win
, mark
);
1699 Array b
= view_selections_get_all(view
);
1701 array_init_from(&sel
, &a
);
1703 intersect(&sel
, &a
, &b
);
1704 selections_set(vis
, view
, &sel
);
1709 array_release(&sel
);
1714 static void complement(Array
*ret
, Array
*a
, Filerange
*universe
) {
1715 size_t pos
= universe
->start
;
1716 for (size_t i
= 0, len
= array_length(a
); i
< len
; i
++) {
1717 Filerange
*r
= array_get(a
, i
);
1718 if (pos
< r
->start
) {
1719 Filerange
new = text_range_new(pos
, r
->start
);
1720 array_add(ret
, &new);
1724 if (pos
< universe
->end
) {
1725 Filerange
new = text_range_new(pos
, universe
->end
);
1726 array_add(ret
, &new);
1730 static const char *selections_complement(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1731 Text
*txt
= vis_text(vis
);
1732 View
*view
= vis_view(vis
);
1733 Filerange universe
= text_object_entire(txt
, 0);
1734 Array a
= view_selections_get_all(view
);
1736 array_init_from(&sel
, &a
);
1738 complement(&sel
, &a
, &universe
);
1740 selections_set(vis
, view
, &sel
);
1742 array_release(&sel
);
1746 static const char *selections_minus(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1747 Text
*txt
= vis_text(vis
);
1748 Win
*win
= vis_window(vis
);
1749 View
*view
= vis_view(vis
);
1750 enum VisMark mark
= vis_mark_used(vis
);
1751 Array a
= view_selections_get_all(view
);
1752 Array b
= vis_mark_get(win
, mark
);
1754 array_init_from(&sel
, &a
);
1756 array_init_from(&b_complement
, &b
);
1758 Filerange universe
= text_object_entire(txt
, 0);
1759 complement(&b_complement
, &b
, &universe
);
1760 intersect(&sel
, &a
, &b_complement
);
1762 selections_set(vis
, view
, &sel
);
1767 array_release(&b_complement
);
1768 array_release(&sel
);
1773 static const char *replace(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1775 vis_keymap_disable(vis
);
1779 const char *next
= vis_keys_next(vis
, keys
);
1783 char replacement
[UTFmax
+1];
1784 if (!vis_keys_utf8(vis
, keys
, replacement
))
1787 if (replacement
[0] == 0x1b) /* <Escape> */
1790 vis_operator(vis
, VIS_OP_REPLACE
, replacement
);
1791 if (vis_mode_get(vis
) == VIS_MODE_OPERATOR_PENDING
)
1792 vis_motion(vis
, VIS_MOVE_CHAR_NEXT
);
1796 static const char *count(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1797 int digit
= keys
[-1] - '0';
1798 int count
= vis_count_get_default(vis
, 0);
1799 if (0 <= digit
&& digit
<= 9) {
1800 if (digit
== 0 && count
== 0)
1801 vis_motion(vis
, VIS_MOVE_LINE_BEGIN
);
1803 vis_count_set(vis
, count
* 10 + digit
);
1808 static const char *gotoline(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1809 if (vis_count_get(vis
) != VIS_COUNT_UNKNOWN
)
1810 vis_motion(vis
, VIS_MOVE_LINE
);
1811 else if (arg
->i
< 0)
1812 vis_motion(vis
, VIS_MOVE_FILE_BEGIN
);
1814 vis_motion(vis
, VIS_MOVE_FILE_END
);
1818 static const char *operator(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1819 vis_operator(vis
, arg
->i
);
1823 static const char *movement_key(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1825 vis_keymap_disable(vis
);
1829 const char *next
= vis_keys_next(vis
, keys
);
1832 char utf8
[UTFmax
+1];
1833 if (vis_keys_utf8(vis
, keys
, utf8
))
1834 vis_motion(vis
, arg
->i
, utf8
);
1838 static const char *movement(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1839 vis_motion(vis
, arg
->i
);
1843 static const char *textobj(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1844 vis_textobject(vis
, arg
->i
);
1848 static const char *selection_end(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1849 for (Selection
*s
= view_selections(vis_view(vis
)); s
; s
= view_selections_next(s
))
1850 view_selections_flip(s
);
1854 static const char *reg(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1857 const char *next
= vis_keys_next(vis
, keys
);
1858 if (next
- keys
> 1)
1860 enum VisRegister reg
= vis_register_from(vis
, keys
[0]);
1861 vis_register(vis
, reg
);
1865 static const char *mark(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1868 const char *next
= vis_keys_next(vis
, keys
);
1869 if (next
- keys
> 1)
1871 enum VisMark mark
= vis_mark_from(vis
, keys
[0]);
1872 vis_mark(vis
, mark
);
1876 static const char *undo(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1877 size_t pos
= text_undo(vis_text(vis
));
1879 View
*view
= vis_view(vis
);
1880 if (view_selections_count(view
) == 1)
1881 view_cursor_to(view
, pos
);
1882 /* redraw all windows in case some display the same file */
1888 static const char *redo(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1889 size_t pos
= text_redo(vis_text(vis
));
1891 View
*view
= vis_view(vis
);
1892 if (view_selections_count(view
) == 1)
1893 view_cursor_to(view
, pos
);
1894 /* redraw all windows in case some display the same file */
1900 static const char *earlier(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1902 VisCountIterator it
= vis_count_iterator_get(vis
, 1);
1903 while (vis_count_iterator_next(&it
))
1904 pos
= text_earlier(vis_text(vis
));
1906 view_cursor_to(vis_view(vis
), pos
);
1907 /* redraw all windows in case some display the same file */
1913 static const char *later(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1915 VisCountIterator it
= vis_count_iterator_get(vis
, 1);
1916 while (vis_count_iterator_next(&it
))
1917 pos
= text_later(vis_text(vis
));
1919 view_cursor_to(vis_view(vis
), pos
);
1920 /* redraw all windows in case some display the same file */
1926 static const char *delete(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1927 vis_operator(vis
, VIS_OP_DELETE
);
1928 vis_motion(vis
, arg
->i
);
1932 static const char *insert_register(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1935 const char *next
= vis_keys_next(vis
, keys
);
1936 if (next
- keys
> 1)
1938 enum VisRegister reg
= vis_register_from(vis
, keys
[0]);
1939 if (reg
!= VIS_REG_INVALID
) {
1940 vis_register(vis
, reg
);
1941 vis_operator(vis
, VIS_OP_PUT_BEFORE_END
);
1946 static const char *prompt_show(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1947 vis_prompt_show(vis
, arg
->s
);
1951 static const char *insert_verbatim(Vis
*vis
, const char *keys
, const Arg
*arg
) {
1953 char buf
[4], type
= keys
[0];
1954 const char *data
= NULL
;
1955 int len
= 0, count
= 0, base
= 0;
1977 if ('0' <= type
&& type
<= '9') {
1986 for (keys
++; keys
[0] && count
> 0; keys
++, count
--) {
1988 if (base
== 8 && '0' <= keys
[0] && keys
[0] <= '7') {
1990 } else if ((base
== 10 || base
== 16) && '0' <= keys
[0] && keys
[0] <= '9') {
1992 } else if (base
== 16 && 'a' <= keys
[0] && keys
[0] <= 'f') {
1993 v
= 10 + keys
[0] - 'a';
1994 } else if (base
== 16 && 'A' <= keys
[0] && keys
[0] <= 'F') {
1995 v
= 10 + keys
[0] - 'A';
2000 rune
= rune
* base
+ v
;
2005 if (type
== 'u' || type
== 'U') {
2006 len
= runetochar(buf
, &rune
);
2014 const char *next
= vis_keys_next(vis
, keys
);
2017 if ((rune
= vis_keys_codepoint(vis
, keys
)) != (Rune
)-1) {
2018 len
= runetochar(buf
, &rune
);
2023 vis_info_show(vis
, "Unknown key");
2029 vis_insert_key(vis
, data
, len
);
2033 static const char *wscroll(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2034 View
*view
= vis_view(vis
);
2035 int count
= vis_count_get(vis
);
2038 view_scroll_page_up(view
);
2041 view_scroll_page_down(view
);
2044 view_scroll_halfpage_up(view
);
2047 view_scroll_halfpage_down(view
);
2050 if (count
== VIS_COUNT_UNKNOWN
)
2051 count
= arg
->i
< 0 ? -arg
->i
: arg
->i
;
2053 view_scroll_up(view
, count
);
2055 view_scroll_down(view
, count
);
2058 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
2062 static const char *wslide(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2063 View
*view
= vis_view(vis
);
2064 int count
= vis_count_get(vis
);
2065 if (count
== VIS_COUNT_UNKNOWN
)
2066 count
= arg
->i
< 0 ? -arg
->i
: arg
->i
;
2068 view_slide_down(view
, count
);
2070 view_slide_up(view
, count
);
2071 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
2075 static const char *call(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2080 static const char *window(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2081 arg
->w(vis_view(vis
));
2085 static const char *openline(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2086 vis_operator(vis
, VIS_OP_MODESWITCH
, VIS_MODE_INSERT
);
2088 vis_motion(vis
, VIS_MOVE_LINE_END
);
2089 vis_keys_feed(vis
, "<Enter>");
2091 if (vis_get_autoindent(vis
)) {
2092 vis_motion(vis
, VIS_MOVE_LINE_START
);
2093 vis_keys_feed(vis
, "<vis-motion-line-start>");
2095 vis_motion(vis
, VIS_MOVE_LINE_BEGIN
);
2096 vis_keys_feed(vis
, "<vis-motion-line-begin>");
2098 vis_keys_feed(vis
, "<Enter><vis-motion-line-up>");
2103 static const char *join(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2104 bool normal
= (vis_mode_get(vis
) == VIS_MODE_NORMAL
);
2105 vis_operator(vis
, VIS_OP_JOIN
, arg
->s
);
2107 int count
= vis_count_get_default(vis
, 0);
2109 vis_count_set(vis
, count
-1);
2110 vis_motion(vis
, VIS_MOVE_LINE_NEXT
);
2115 static const char *normalmode_escape(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2116 if (vis_count_get(vis
) == VIS_COUNT_UNKNOWN
)
2117 selections_clear(vis
, keys
, arg
);
2119 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
2123 static const char *visualmode_escape(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2124 if (vis_count_get(vis
) == VIS_COUNT_UNKNOWN
)
2125 vis_mode_switch(vis
, VIS_MODE_NORMAL
);
2127 vis_count_set(vis
, VIS_COUNT_UNKNOWN
);
2131 static const char *switchmode(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2132 vis_mode_switch(vis
, arg
->i
);
2136 static const char *insertmode(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2137 vis_operator(vis
, VIS_OP_MODESWITCH
, VIS_MODE_INSERT
);
2138 vis_motion(vis
, arg
->i
);
2142 static const char *replacemode(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2143 vis_operator(vis
, VIS_OP_MODESWITCH
, VIS_MODE_REPLACE
);
2144 vis_motion(vis
, arg
->i
);
2148 static const char *unicode_info(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2149 View
*view
= vis_view(vis
);
2150 Text
*txt
= vis_text(vis
);
2151 size_t start
= view_cursor_get(view
);
2152 size_t end
= text_char_next(txt
, start
);
2153 char *grapheme
= text_bytes_alloc0(txt
, start
, end
-start
), *codepoint
= grapheme
;
2158 mbstate_t ps
= { 0 };
2159 Iterator it
= text_iterator_get(txt
, start
);
2160 for (size_t pos
= start
; it
.pos
< end
; pos
= it
.pos
) {
2161 if (!text_iterator_codepoint_next(&it
, NULL
)) {
2162 vis_info_show(vis
, "Failed to parse code point");
2165 size_t len
= it
.pos
- pos
;
2166 wchar_t wc
= 0xFFFD;
2167 size_t res
= mbrtowc(&wc
, codepoint
, len
, &ps
);
2168 bool combining
= false;
2169 if (res
!= (size_t)-1 && res
!= (size_t)-2)
2170 combining
= (wc
!= L
'\0' && wcwidth(wc
) == 0);
2171 unsigned char ch
= *codepoint
;
2172 if (ch
< 128 && !isprint(ch
))
2173 buffer_appendf(&info
, "<^%c> ", ch
== 127 ? '?' : ch
+ 64);
2175 buffer_appendf(&info
, "<%s%.*s> ", combining
? " " : "", (int)len
, codepoint
);
2176 if (arg
->i
== VIS_ACTION_UNICODE_INFO
) {
2177 buffer_appendf(&info
, "U+%04"PRIX32
" ", (uint32_t)wc
);
2179 for (size_t i
= 0; i
< len
; i
++)
2180 buffer_appendf(&info
, "%02x ", (uint8_t)codepoint
[i
]);
2184 vis_info_show(vis
, "%s", buffer_content0(&info
));
2187 buffer_release(&info
);
2191 static const char *percent(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2192 if (vis_count_get(vis
) == VIS_COUNT_UNKNOWN
)
2193 vis_motion(vis
, VIS_MOVE_BRACKET_MATCH
);
2195 vis_motion(vis
, VIS_MOVE_PERCENT
);
2199 static const char *jumplist(Vis
*vis
, const char *keys
, const Arg
*arg
) {
2201 vis_jumplist_prev(vis
);
2202 else if (arg
->i
> 0)
2203 vis_jumplist_next(vis
);
2205 vis_jumplist_save(vis
);
2211 static void signal_handler(int signum
, siginfo_t
*siginfo
, void *context
) {
2212 vis_signal_handler(vis
, signum
, siginfo
, context
);
2215 int main(int argc
, char *argv
[]) {
2218 .init
= vis_lua_init
,
2219 .start
= vis_lua_start
,
2220 .quit
= vis_lua_quit
,
2221 .mode_insert_input
= vis_lua_mode_insert_input
,
2222 .mode_replace_input
= vis_lua_mode_replace_input
,
2223 .file_open
= vis_lua_file_open
,
2224 .file_save_pre
= vis_lua_file_save_pre
,
2225 .file_save_post
= vis_lua_file_save_post
,
2226 .file_close
= vis_lua_file_close
,
2227 .win_open
= vis_lua_win_open
,
2228 .win_close
= vis_lua_win_close
,
2229 .win_highlight
= vis_lua_win_highlight
,
2230 .win_status
= vis_lua_win_status
,
2231 .term_csi
= vis_lua_term_csi
,
2234 vis
= vis_new(ui_term_new(), &event
);
2236 return EXIT_FAILURE
;
2238 for (int i
= 0; i
< LENGTH(vis_action
); i
++) {
2239 const KeyAction
*action
= &vis_action
[i
];
2240 if (!vis_action_register(vis
, action
))
2241 vis_die(vis
, "Could not register action: %s\n", action
->name
);
2244 for (int i
= 0; i
< LENGTH(default_bindings
); i
++) {
2245 for (const KeyBinding
**binding
= default_bindings
[i
]; binding
&& *binding
; binding
++) {
2246 for (const KeyBinding
*kb
= *binding
; kb
->key
; kb
++) {
2247 vis_mode_map(vis
, i
, false, kb
->key
, kb
);
2252 for (const char **k
= keymaps
; k
[0]; k
+= 2)
2253 vis_keymap_add(vis
, k
[0], k
[1]);
2255 /* install signal handlers etc. */
2256 struct sigaction sa
;
2257 memset(&sa
, 0, sizeof sa
);
2258 sigfillset(&sa
.sa_mask
);
2259 sa
.sa_flags
= SA_SIGINFO
;
2260 sa
.sa_sigaction
= signal_handler
;
2261 if (sigaction(SIGBUS
, &sa
, NULL
) == -1 ||
2262 sigaction(SIGINT
, &sa
, NULL
) == -1 ||
2263 sigaction(SIGCONT
, &sa
, NULL
) == -1 ||
2264 sigaction(SIGWINCH
, &sa
, NULL
) == -1 ||
2265 sigaction(SIGTERM
, &sa
, NULL
) == -1 ||
2266 sigaction(SIGHUP
, &sa
, NULL
) == -1) {
2267 vis_die(vis
, "Failed to set signal handler: %s\n", strerror(errno
));
2270 sa
.sa_handler
= SIG_IGN
;
2271 if (sigaction(SIGPIPE
, &sa
, NULL
) == -1 || sigaction(SIGQUIT
, &sa
, NULL
) == -1)
2272 vis_die(vis
, "Failed to ignore signals\n");
2275 sigemptyset(&blockset
);
2276 sigaddset(&blockset
, SIGBUS
);
2277 sigaddset(&blockset
, SIGCONT
);
2278 sigaddset(&blockset
, SIGWINCH
);
2279 sigaddset(&blockset
, SIGTERM
);
2280 sigaddset(&blockset
, SIGHUP
);
2281 if (sigprocmask(SIG_BLOCK
, &blockset
, NULL
) == -1)
2282 vis_die(vis
, "Failed to block signals\n");
2284 for (int i
= 1; i
< argc
; i
++) {
2285 if (argv
[i
][0] != '-') {
2287 } else if (strcmp(argv
[i
], "-") == 0) {
2289 } else if (strcmp(argv
[i
], "--") == 0) {
2291 } else if (strcmp(argv
[i
], "-v") == 0) {
2292 printf("vis %s%s%s%s%s%s%s\n", VERSION
,
2293 CONFIG_CURSES
? " +curses" : "",
2294 CONFIG_LUA
? " +lua" : "",
2295 CONFIG_LPEG
? " +lpeg" : "",
2296 CONFIG_TRE
? " +tre" : "",
2297 CONFIG_ACL
? " +acl" : "",
2298 CONFIG_SELINUX
? " +selinux" : "");
2301 fprintf(stderr
, "Unknown command option: %s\n", argv
[i
]);
2307 bool end_of_options
= false, win_created
= false;
2309 for (int i
= 1; i
< argc
; i
++) {
2310 if (argv
[i
][0] == '-' && !end_of_options
) {
2311 if (strcmp(argv
[i
], "-") == 0) {
2312 if (!vis_window_new_fd(vis
, STDOUT_FILENO
))
2313 vis_die(vis
, "Can not create empty buffer\n");
2316 Text
*txt
= vis_text(vis
);
2317 while ((len
= read(STDIN_FILENO
, buf
, sizeof buf
)) > 0)
2318 text_insert(txt
, text_size(txt
), buf
, len
);
2320 vis_die(vis
, "Can not read from stdin\n");
2322 int fd
= open("/dev/tty", O_RDWR
);
2324 vis_die(vis
, "Can not reopen stdin\n");
2325 dup2(fd
, STDIN_FILENO
);
2327 } else if (strcmp(argv
[i
], "--") == 0) {
2328 end_of_options
= true;
2331 } else if (argv
[i
][0] == '+' && !end_of_options
) {
2332 cmd
= argv
[i
] + (argv
[i
][1] == '/' || argv
[i
][1] == '?');
2334 } else if (!vis_window_new(vis
, argv
[i
])) {
2335 vis_die(vis
, "Can not load `%s': %s\n", argv
[i
], strerror(errno
));
2339 vis_prompt_cmd(vis
, cmd
);
2344 if (!vis_window(vis
) && !win_created
) {
2345 if (!vis_window_new(vis
, NULL
))
2346 vis_die(vis
, "Can not create empty buffer\n");
2348 vis_prompt_cmd(vis
, cmd
);
2351 int status
= vis_run(vis
);