2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid[] = "@(#)v_cmd.c 10.9 (Berkeley) 3/28/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
24 #include "../common/common.h"
28 * This array maps keystrokes to vi command functions. It is known
29 * in ex/ex_usage.c that it takes four columns to name a vi character.
31 VIKEYS const vikeys [MAXVIKEY + 1] = {
32 /* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
35 {v_searchw, V_ABS|V_CNT|V_MOVE|V_KEYW|VM_CUTREQ|VM_RCM_SET,
37 "^A search forward for cursor word"},
39 {v_pageup, V_CNT|VM_RCM_SET,
41 "^B scroll up by screens"},
45 "^C interrupt an operation (e.g. read, write, search)"},
47 {v_hpagedown, V_CNT|VM_RCM_SET,
49 "^D scroll down by half screens (setting count)"},
53 "^E scroll down by lines"},
55 {v_pagedown, V_CNT|VM_RCM_SET,
57 "^F scroll down by screens"},
63 {v_left, V_CNT|V_MOVE|VM_RCM_SET,
65 "^H move left by characters"},
69 {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
71 "^J move down by lines"},
79 {v_cr, V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
81 "^M move down by lines (to first non-blank)"},
83 {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
85 "^N move down by lines"},
89 {v_up, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
91 "^P move up by lines"},
92 /* 021 ^Q -- same as ^V if not used for hardware flow control. */
98 /* 023 ^S -- not available, used for hardware flow control. */
101 {v_tagpop, V_ABS|VM_RCM_SET,
105 {v_hpageup, V_CNT|VM_RCM_SET,
107 "^U half page up (set count)"},
111 "^V input a literal character"},
115 "^W move to next screen"},
121 "^Y page up by lines"},
123 {v_suspend, V_SECURE,
125 "^Z suspend editor"},
129 "^[ <escape> exit input mode, cancel partial commands"},
133 " ^\\ switch to ex mode"},
135 {v_tagpush, V_ABS|V_KEYW|VM_RCM_SET,
137 "^] tag push cursor word"},
141 "^^ switch to previous file"},
145 {v_right, V_CNT|V_MOVE|VM_RCM_SET,
147 " <space> move right by columns"},
149 {v_filter, V_CNT|V_DOT|V_MOTION|V_SECURE|VM_RCM_SET,
150 "[count]![count]motion command(s)",
151 " ! filter through command(s) to motion"},
155 {v_increment, V_CHAR|V_CNT|V_DOT|VM_RCM_SET,
157 " # number increment/decrement"},
159 {v_dollar, V_CNT|V_MOVE|VM_RCM_SETLAST,
161 " $ move to last column"},
163 {v_match, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
169 " & repeat substitution"},
171 {v_fmark, V_ABS_L|V_CHAR|V_MOVE|VM_LMODE|VM_RCM_SET,
173 " ' move to mark (to first non-blank)"},
175 {v_sentenceb, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
177 " ( move back sentence"},
179 {v_sentencef, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
181 " ) move forward sentence"},
185 {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
187 " + move down by lines (to first non-blank)"},
189 {v_chrrepeat, V_CNT|V_MOVE|VM_RCM_SET,
191 " , reverse last F, f, T or t search"},
193 {v_up, V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
195 " - move up by lines (to first non-blank)"},
199 " . repeat the last command"},
201 {v_searchf, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
203 " / search forward"},
205 {v_zero, V_MOVE|VM_RCM_SET,
207 " 0 move to first character"},
228 ":command [| command] ...",
231 {v_chrepeat, V_CNT|V_MOVE|VM_RCM_SET,
233 " ; repeat last F, f, T or t search"},
235 {v_shiftl, V_CNT|V_DOT|V_MOTION|VM_RCM_SET,
236 "[count]<[count]motion",
237 " < shift lines left to motion"},
241 {v_shiftr, V_CNT|V_DOT|V_MOTION|VM_RCM_SET,
242 "[count]>[count]motion",
243 " > shift lines right to motion"},
245 {v_searchb, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
247 " ? search backward"},
249 {v_at, V_CNT|V_RBUF|VM_RCM_SET,
251 " @ execute buffer"},
253 {v_iA, V_CNT|V_DOT|VM_RCM_SET,
255 " A append to the line"},
257 {v_wordB, V_CNT|V_MOVE|VM_RCM_SET,
259 " B move back bigword"},
263 " C change to end-of-line"},
267 " D delete to end-of-line"},
269 {v_wordE, V_CNT|V_MOVE|VM_RCM_SET,
271 " E move to end of bigword"},
273 {v_chF, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
274 "[count]F character",
275 " F character in line backward search"},
277 {v_lgoto, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
281 {v_home, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
283 " H move to count lines from screen top"},
285 {v_iI, V_CNT|V_DOT|VM_RCM_SET,
287 " I insert before first nonblank"},
289 {v_join, V_CNT|V_DOT|VM_RCM_SET,
295 {v_bottom, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
297 " L move to screen bottom"},
299 {v_middle, V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
301 " M move to screen middle"},
303 {v_searchN, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
305 " N reverse last search"},
307 {v_iO, V_CNT|V_DOT|VM_RCM_SET,
309 " O insert above line"},
311 {v_Put, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
313 " P insert before cursor from buffer"},
317 " Q switch to ex mode"},
319 {v_Replace, V_CNT|V_DOT|VM_RCM_SET,
321 " R replace characters"},
325 " S substitute for the line(s)"},
327 {v_chT, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
328 "[count]T character",
329 " T before character in line backward search"},
333 " U Restore the current line"},
337 {v_wordW, V_CNT|V_MOVE|VM_RCM_SET,
339 " W move to next bigword"},
341 {v_Xchar, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
343 " X delete character before cursor"},
351 "ZZ save file and exit"},
353 {v_sectionb, V_ABS|V_CNT|V_MOVE|VM_RCM_SET,
355 "[[ move back section"},
359 {v_sectionf, V_ABS|V_CNT|V_MOVE|VM_RCM_SET,
361 "]] move forward section"},
364 * DON'T set the VM_RCM_SETFNB flag, the function has to do the work
365 * anyway, in case it's a motion component. DO set VM_RCM_SET, so
366 * that any motion that's part of a command is preserved.
368 {v_first, V_CNT|V_MOVE|VM_RCM_SET,
370 " ^ move to first non-blank"},
373 * Needs both to set the VM_RCM_SETFNB flag, and to do the work
374 * in the function, in case it's a delete.
376 {v_cfirst, V_CNT|V_MOVE|VM_RCM_SETFNB,
378 " _ move to first non-blank"},
380 {v_bmark, V_ABS_C|V_CHAR|V_MOVE|VM_CUTREQ|VM_RCM_SET,
384 {v_ia, V_CNT|V_DOT|VM_RCM_SET,
386 " a append after cursor"},
388 {v_wordb, V_CNT|V_MOVE|VM_RCM_SET,
390 " b move back word"},
392 {v_change, V_CNT|V_DOT|V_MOTION|V_OBUF|VM_RCM_SET,
393 "[buffer][count]c[count]motion",
394 " c change to motion"},
396 {v_delete, V_CNT|V_DOT|V_MOTION|V_OBUF|VM_RCM_SET,
397 "[buffer][count]d[count]motion",
398 " d delete to motion"},
400 {v_worde, V_CNT|V_MOVE|VM_RCM_SET,
402 " e move to end of word"},
404 {v_chf, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
405 "[count]f character",
406 " f character in line forward search"},
410 {v_left, V_CNT|V_MOVE|VM_RCM_SET,
412 " h move left by columns"},
414 {v_ii, V_CNT|V_DOT|VM_RCM_SET,
416 " i insert before cursor"},
418 {v_down, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
420 " j move down by lines"},
422 {v_up, V_CNT|V_MOVE|VM_LMODE|VM_RCM,
424 " k move up by lines"},
426 {v_right, V_CNT|V_MOVE|VM_RCM_SET,
428 " l move right by columns"},
434 {v_searchn, V_ABS_C|V_MOVE|VM_CUTREQ|VM_RCM_SET,
436 " n repeat last search"},
438 {v_io, V_CNT|V_DOT|VM_RCM_SET,
440 " o append after line"},
442 {v_put, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
444 " p insert after cursor from buffer"},
448 {v_replace, V_CNT|V_DOT|VM_RCM_SET,
449 "[count]r character",
450 " r replace character"},
452 {v_subst, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
454 " s substitute character"},
456 {v_cht, V_CHAR|V_CNT|V_MOVE|VM_RCM_SET,
457 "[count]t character",
458 " t before character in line forward search"},
461 * DON'T set the V_DOT flag, it' more complicated than that.
462 * See vi/vi.c for details.
466 " u undo last change"},
470 {v_wordw, V_CNT|V_MOVE|VM_RCM_SET,
472 " w move to next word"},
474 {v_xchar, V_CNT|V_DOT|V_OBUF|VM_RCM_SET,
476 " x delete character"},
478 {v_yank, V_CNT|V_DOT|V_MOTION|V_OBUF|VM_RCM_SET,
479 "[buffer][count]y[count]motion",
480 " y copy text to motion into a cut buffer"},
483 * DON'T set the V_CHAR flag, the char isn't required,
484 * so it's handled specially in getcmd().
486 {v_z, V_ABS_L|V_CNT|VM_RCM_SETFNB,
487 "[line]z[window_size][-|.|+|^|<CR>]",
488 " z reposition the screen"},
490 {v_paragraphb, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
492 " { move back paragraph"},
494 {v_ncol, V_CNT|V_MOVE|VM_RCM_SET,
496 " | move to column"},
498 {v_paragraphf, V_ABS|V_CNT|V_MOVE|VM_CUTREQ|VM_RCM_SET,
500 " } move forward paragraph"},
502 {v_ulcase, V_CNT|V_DOT|VM_RCM_SET,