1 /* $NetBSD: v_cmd.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 static const char sccsid
[] = "Id: v_cmd.c,v 10.9 1996/03/28 15:18:39 bostic Exp (Berkeley) Date: 1996/03/28 15:18:39 ";
19 __RCSID("$NetBSD: v_cmd.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
30 #include "../common/common.h"
33 #define VINULLKEY { NULL, 0, NULL, NULL }
35 * This array maps keystrokes to vi command functions. It is known
36 * in ex/ex_usage.c that it takes four columns to name a vi character.
38 VIKEYS
const vikeys
[MAXVIKEY
+ 1] = {
39 /* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
42 {v_searchw
, V_ABS
|V_CNT
|V_MOVE
|V_KEYW
|VM_CUTREQ
|VM_RCM_SET
,
44 "^A search forward for cursor word"},
46 {v_pageup
, V_CNT
|VM_RCM_SET
,
48 "^B scroll up by screens"},
52 "^C interrupt an operation (e.g. read, write, search)"},
54 {v_hpagedown
, V_CNT
|VM_RCM_SET
,
56 "^D scroll down by half screens (setting count)"},
60 "^E scroll down by lines"},
62 {v_pagedown
, V_CNT
|VM_RCM_SET
,
64 "^F scroll down by screens"},
70 {v_left
, V_CNT
|V_MOVE
|VM_RCM_SET
,
72 "^H move left by characters"},
76 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
78 "^J move down by lines"},
86 {v_cr
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
88 "^M move down by lines (to first non-blank)"},
90 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
92 "^N move down by lines"},
96 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
98 "^P move up by lines"},
99 /* 021 ^Q -- same as ^V if not used for hardware flow control. */
105 /* 023 ^S -- not available, used for hardware flow control. */
108 {v_tagpop
, V_ABS
|VM_RCM_SET
,
112 {v_hpageup
, V_CNT
|VM_RCM_SET
,
114 "^U half page up (set count)"},
118 "^V input a literal character"},
122 "^W move to next screen"},
128 "^Y page up by lines"},
130 {v_suspend
, V_SECURE
,
132 "^Z suspend editor"},
136 "^[ <escape> exit input mode, cancel partial commands"},
140 " ^\\ switch to ex mode"},
142 {v_tagpush
, V_ABS
|V_KEYW
|VM_RCM_SET
,
144 "^] tag push cursor word"},
148 "^^ switch to previous file"},
152 {v_right
, V_CNT
|V_MOVE
|VM_RCM_SET
,
154 " <space> move right by columns"},
156 {v_filter
, V_CNT
|V_DOT
|V_MOTION
|V_SECURE
|VM_RCM_SET
,
157 "[count]![count]motion command(s)",
158 " ! filter through command(s) to motion"},
162 {v_increment
, V_CHAR
|V_CNT
|V_DOT
|VM_RCM_SET
,
164 " # number increment/decrement"},
166 {v_dollar
, V_CNT
|V_MOVE
|VM_RCM_SETLAST
,
168 " $ move to last column"},
170 {v_match
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
176 " & repeat substitution"},
178 {v_fmark
, V_ABS_L
|V_CHAR
|V_MOVE
|VM_LMODE
|VM_RCM_SET
,
180 " ' move to mark (to first non-blank)"},
182 {v_sentenceb
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
184 " ( move back sentence"},
186 {v_sentencef
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
188 " ) move forward sentence"},
192 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
194 " + move down by lines (to first non-blank)"},
196 {v_chrrepeat
, V_CNT
|V_MOVE
|VM_RCM_SET
,
198 " , reverse last F, f, T or t search"},
200 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
202 " - move up by lines (to first non-blank)"},
206 " . repeat the last command"},
208 {v_searchf
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
210 " / search forward"},
212 {v_zero
, V_MOVE
|VM_RCM_SET
,
214 " 0 move to first character"},
235 ":command [| command] ...",
238 {v_chrepeat
, V_CNT
|V_MOVE
|VM_RCM_SET
,
240 " ; repeat last F, f, T or t search"},
242 {v_shiftl
, V_CNT
|V_DOT
|V_MOTION
|VM_RCM_SET
,
243 "[count]<[count]motion",
244 " < shift lines left to motion"},
248 {v_shiftr
, V_CNT
|V_DOT
|V_MOTION
|VM_RCM_SET
,
249 "[count]>[count]motion",
250 " > shift lines right to motion"},
252 {v_searchb
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
254 " ? search backward"},
256 {v_at
, V_CNT
|V_RBUF
|VM_RCM_SET
,
258 " @ execute buffer"},
260 {v_iA
, V_CNT
|V_DOT
|VM_RCM_SET
,
262 " A append to the line"},
264 {v_wordB
, V_CNT
|V_MOVE
|VM_RCM_SET
,
266 " B move back bigword"},
270 " C change to end-of-line"},
274 " D delete to end-of-line"},
276 {v_wordE
, V_CNT
|V_MOVE
|VM_RCM_SET
,
278 " E move to end of bigword"},
280 {v_chF
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
281 "[count]F character",
282 " F character in line backward search"},
284 {v_lgoto
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
288 {v_home
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
290 " H move to count lines from screen top"},
292 {v_iI
, V_CNT
|V_DOT
|VM_RCM_SET
,
294 " I insert before first nonblank"},
296 {v_join
, V_CNT
|V_DOT
|VM_RCM_SET
,
302 {v_bottom
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
304 " L move to screen bottom"},
306 {v_middle
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
308 " M move to screen middle"},
310 {v_searchN
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
312 " N reverse last search"},
314 {v_iO
, V_CNT
|V_DOT
|VM_RCM_SET
,
316 " O insert above line"},
318 {v_Put
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
320 " P insert before cursor from buffer"},
324 " Q switch to ex mode"},
326 {v_Replace
, V_CNT
|V_DOT
|VM_RCM_SET
,
328 " R replace characters"},
332 " S substitute for the line(s)"},
334 {v_chT
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
335 "[count]T character",
336 " T before character in line backward search"},
340 " U Restore the current line"},
344 {v_wordW
, V_CNT
|V_MOVE
|VM_RCM_SET
,
346 " W move to next bigword"},
348 {v_Xchar
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
350 " X delete character before cursor"},
358 "ZZ save file and exit"},
360 {v_sectionb
, V_ABS
|V_CNT
|V_MOVE
|VM_RCM_SET
,
362 "[[ move back section"},
366 {v_sectionf
, V_ABS
|V_CNT
|V_MOVE
|VM_RCM_SET
,
368 "]] move forward section"},
371 * DON'T set the VM_RCM_SETFNB flag, the function has to do the work
372 * anyway, in case it's a motion component. DO set VM_RCM_SET, so
373 * that any motion that's part of a command is preserved.
375 {v_first
, V_CNT
|V_MOVE
|VM_RCM_SET
,
377 " ^ move to first non-blank"},
380 * Needs both to set the VM_RCM_SETFNB flag, and to do the work
381 * in the function, in case it's a delete.
383 {v_cfirst
, V_CNT
|V_MOVE
|VM_RCM_SETFNB
,
385 " _ move to first non-blank"},
387 {v_bmark
, V_ABS_C
|V_CHAR
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
391 {v_ia
, V_CNT
|V_DOT
|VM_RCM_SET
,
393 " a append after cursor"},
395 {v_wordb
, V_CNT
|V_MOVE
|VM_RCM_SET
,
397 " b move back word"},
399 {v_change
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
400 "[buffer][count]c[count]motion",
401 " c change to motion"},
403 {v_delete
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
404 "[buffer][count]d[count]motion",
405 " d delete to motion"},
407 {v_worde
, V_CNT
|V_MOVE
|VM_RCM_SET
,
409 " e move to end of word"},
411 {v_chf
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
412 "[count]f character",
413 " f character in line forward search"},
417 {v_left
, V_CNT
|V_MOVE
|VM_RCM_SET
,
419 " h move left by columns"},
421 {v_ii
, V_CNT
|V_DOT
|VM_RCM_SET
,
423 " i insert before cursor"},
425 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
427 " j move down by lines"},
429 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
431 " k move up by lines"},
433 {v_right
, V_CNT
|V_MOVE
|VM_RCM_SET
,
435 " l move right by columns"},
441 {v_searchn
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
443 " n repeat last search"},
445 {v_io
, V_CNT
|V_DOT
|VM_RCM_SET
,
447 " o append after line"},
449 {v_put
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
451 " p insert after cursor from buffer"},
455 {v_replace
, V_CNT
|V_DOT
|VM_RCM_SET
,
456 "[count]r character",
457 " r replace character"},
459 {v_subst
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
461 " s substitute character"},
463 {v_cht
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
464 "[count]t character",
465 " t before character in line forward search"},
468 * DON'T set the V_DOT flag, it' more complicated than that.
469 * See vi/vi.c for details.
473 " u undo last change"},
477 {v_wordw
, V_CNT
|V_MOVE
|VM_RCM_SET
,
479 " w move to next word"},
481 {v_xchar
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
483 " x delete character"},
485 {v_yank
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
486 "[buffer][count]y[count]motion",
487 " y copy text to motion into a cut buffer"},
490 * DON'T set the V_CHAR flag, the char isn't required,
491 * so it's handled specially in getcmd().
493 {v_z
, V_ABS_L
|V_CNT
|VM_RCM_SETFNB
,
494 "[line]z[window_size][-|.|+|^|<CR>]",
495 " z reposition the screen"},
497 {v_paragraphb
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
499 " { move back paragraph"},
501 {v_ncol
, V_CNT
|V_MOVE
|VM_RCM_SET
,
503 " | move to column"},
505 {v_paragraphf
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
507 " } move forward paragraph"},
509 {v_ulcase
, V_CNT
|V_DOT
|VM_RCM_SET
,