1 /* $NetBSD: v_cmd.c,v 1.1.1.2 2008/05/18 14:31:41 aymeric Exp $ */
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 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";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
26 #include "../common/common.h"
29 #define VINULLKEY { NULL, 0, NULL, NULL }
31 * This array maps keystrokes to vi command functions. It is known
32 * in ex/ex_usage.c that it takes four columns to name a vi character.
34 VIKEYS
const vikeys
[MAXVIKEY
+ 1] = {
35 /* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
38 {v_searchw
, V_ABS
|V_CNT
|V_MOVE
|V_KEYW
|VM_CUTREQ
|VM_RCM_SET
,
40 "^A search forward for cursor word"},
42 {v_pageup
, V_CNT
|VM_RCM_SET
,
44 "^B scroll up by screens"},
48 "^C interrupt an operation (e.g. read, write, search)"},
50 {v_hpagedown
, V_CNT
|VM_RCM_SET
,
52 "^D scroll down by half screens (setting count)"},
56 "^E scroll down by lines"},
58 {v_pagedown
, V_CNT
|VM_RCM_SET
,
60 "^F scroll down by screens"},
66 {v_left
, V_CNT
|V_MOVE
|VM_RCM_SET
,
68 "^H move left by characters"},
72 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
74 "^J move down by lines"},
82 {v_cr
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
84 "^M move down by lines (to first non-blank)"},
86 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
88 "^N move down by lines"},
92 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
94 "^P move up by lines"},
95 /* 021 ^Q -- same as ^V if not used for hardware flow control. */
101 /* 023 ^S -- not available, used for hardware flow control. */
104 {v_tagpop
, V_ABS
|VM_RCM_SET
,
108 {v_hpageup
, V_CNT
|VM_RCM_SET
,
110 "^U half page up (set count)"},
114 "^V input a literal character"},
118 "^W move to next screen"},
124 "^Y page up by lines"},
126 {v_suspend
, V_SECURE
,
128 "^Z suspend editor"},
132 "^[ <escape> exit input mode, cancel partial commands"},
136 " ^\\ switch to ex mode"},
138 {v_tagpush
, V_ABS
|V_KEYW
|VM_RCM_SET
,
140 "^] tag push cursor word"},
144 "^^ switch to previous file"},
148 {v_right
, V_CNT
|V_MOVE
|VM_RCM_SET
,
150 " <space> move right by columns"},
152 {v_filter
, V_CNT
|V_DOT
|V_MOTION
|V_SECURE
|VM_RCM_SET
,
153 "[count]![count]motion command(s)",
154 " ! filter through command(s) to motion"},
158 {v_increment
, V_CHAR
|V_CNT
|V_DOT
|VM_RCM_SET
,
160 " # number increment/decrement"},
162 {v_dollar
, V_CNT
|V_MOVE
|VM_RCM_SETLAST
,
164 " $ move to last column"},
166 {v_match
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
172 " & repeat substitution"},
174 {v_fmark
, V_ABS_L
|V_CHAR
|V_MOVE
|VM_LMODE
|VM_RCM_SET
,
176 " ' move to mark (to first non-blank)"},
178 {v_sentenceb
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
180 " ( move back sentence"},
182 {v_sentencef
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
184 " ) move forward sentence"},
188 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
190 " + move down by lines (to first non-blank)"},
192 {v_chrrepeat
, V_CNT
|V_MOVE
|VM_RCM_SET
,
194 " , reverse last F, f, T or t search"},
196 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
198 " - move up by lines (to first non-blank)"},
202 " . repeat the last command"},
204 {v_searchf
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
206 " / search forward"},
208 {v_zero
, V_MOVE
|VM_RCM_SET
,
210 " 0 move to first character"},
231 ":command [| command] ...",
234 {v_chrepeat
, V_CNT
|V_MOVE
|VM_RCM_SET
,
236 " ; repeat last F, f, T or t search"},
238 {v_shiftl
, V_CNT
|V_DOT
|V_MOTION
|VM_RCM_SET
,
239 "[count]<[count]motion",
240 " < shift lines left to motion"},
244 {v_shiftr
, V_CNT
|V_DOT
|V_MOTION
|VM_RCM_SET
,
245 "[count]>[count]motion",
246 " > shift lines right to motion"},
248 {v_searchb
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
250 " ? search backward"},
252 {v_at
, V_CNT
|V_RBUF
|VM_RCM_SET
,
254 " @ execute buffer"},
256 {v_iA
, V_CNT
|V_DOT
|VM_RCM_SET
,
258 " A append to the line"},
260 {v_wordB
, V_CNT
|V_MOVE
|VM_RCM_SET
,
262 " B move back bigword"},
266 " C change to end-of-line"},
270 " D delete to end-of-line"},
272 {v_wordE
, V_CNT
|V_MOVE
|VM_RCM_SET
,
274 " E move to end of bigword"},
276 {v_chF
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
277 "[count]F character",
278 " F character in line backward search"},
280 {v_lgoto
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETFNB
,
284 {v_home
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
286 " H move to count lines from screen top"},
288 {v_iI
, V_CNT
|V_DOT
|VM_RCM_SET
,
290 " I insert before first nonblank"},
292 {v_join
, V_CNT
|V_DOT
|VM_RCM_SET
,
298 {v_bottom
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
300 " L move to screen bottom"},
302 {v_middle
, V_ABS_L
|V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM_SETNNB
,
304 " M move to screen middle"},
306 {v_searchN
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
308 " N reverse last search"},
310 {v_iO
, V_CNT
|V_DOT
|VM_RCM_SET
,
312 " O insert above line"},
314 {v_Put
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
316 " P insert before cursor from buffer"},
320 " Q switch to ex mode"},
322 {v_Replace
, V_CNT
|V_DOT
|VM_RCM_SET
,
324 " R replace characters"},
328 " S substitute for the line(s)"},
330 {v_chT
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
331 "[count]T character",
332 " T before character in line backward search"},
336 " U Restore the current line"},
340 {v_wordW
, V_CNT
|V_MOVE
|VM_RCM_SET
,
342 " W move to next bigword"},
344 {v_Xchar
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
346 " X delete character before cursor"},
354 "ZZ save file and exit"},
356 {v_sectionb
, V_ABS
|V_CNT
|V_MOVE
|VM_RCM_SET
,
358 "[[ move back section"},
362 {v_sectionf
, V_ABS
|V_CNT
|V_MOVE
|VM_RCM_SET
,
364 "]] move forward section"},
367 * DON'T set the VM_RCM_SETFNB flag, the function has to do the work
368 * anyway, in case it's a motion component. DO set VM_RCM_SET, so
369 * that any motion that's part of a command is preserved.
371 {v_first
, V_CNT
|V_MOVE
|VM_RCM_SET
,
373 " ^ move to first non-blank"},
376 * Needs both to set the VM_RCM_SETFNB flag, and to do the work
377 * in the function, in case it's a delete.
379 {v_cfirst
, V_CNT
|V_MOVE
|VM_RCM_SETFNB
,
381 " _ move to first non-blank"},
383 {v_bmark
, V_ABS_C
|V_CHAR
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
387 {v_ia
, V_CNT
|V_DOT
|VM_RCM_SET
,
389 " a append after cursor"},
391 {v_wordb
, V_CNT
|V_MOVE
|VM_RCM_SET
,
393 " b move back word"},
395 {v_change
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
396 "[buffer][count]c[count]motion",
397 " c change to motion"},
399 {v_delete
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
400 "[buffer][count]d[count]motion",
401 " d delete to motion"},
403 {v_worde
, V_CNT
|V_MOVE
|VM_RCM_SET
,
405 " e move to end of word"},
407 {v_chf
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
408 "[count]f character",
409 " f character in line forward search"},
413 {v_left
, V_CNT
|V_MOVE
|VM_RCM_SET
,
415 " h move left by columns"},
417 {v_ii
, V_CNT
|V_DOT
|VM_RCM_SET
,
419 " i insert before cursor"},
421 {v_down
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
423 " j move down by lines"},
425 {v_up
, V_CNT
|V_MOVE
|VM_LMODE
|VM_RCM
,
427 " k move up by lines"},
429 {v_right
, V_CNT
|V_MOVE
|VM_RCM_SET
,
431 " l move right by columns"},
437 {v_searchn
, V_ABS_C
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
439 " n repeat last search"},
441 {v_io
, V_CNT
|V_DOT
|VM_RCM_SET
,
443 " o append after line"},
445 {v_put
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
447 " p insert after cursor from buffer"},
451 {v_replace
, V_CNT
|V_DOT
|VM_RCM_SET
,
452 "[count]r character",
453 " r replace character"},
455 {v_subst
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
457 " s substitute character"},
459 {v_cht
, V_CHAR
|V_CNT
|V_MOVE
|VM_RCM_SET
,
460 "[count]t character",
461 " t before character in line forward search"},
464 * DON'T set the V_DOT flag, it' more complicated than that.
465 * See vi/vi.c for details.
469 " u undo last change"},
473 {v_wordw
, V_CNT
|V_MOVE
|VM_RCM_SET
,
475 " w move to next word"},
477 {v_xchar
, V_CNT
|V_DOT
|V_OBUF
|VM_RCM_SET
,
479 " x delete character"},
481 {v_yank
, V_CNT
|V_DOT
|V_MOTION
|V_OBUF
|VM_RCM_SET
,
482 "[buffer][count]y[count]motion",
483 " y copy text to motion into a cut buffer"},
486 * DON'T set the V_CHAR flag, the char isn't required,
487 * so it's handled specially in getcmd().
489 {v_z
, V_ABS_L
|V_CNT
|VM_RCM_SETFNB
,
490 "[line]z[window_size][-|.|+|^|<CR>]",
491 " z reposition the screen"},
493 {v_paragraphb
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
495 " { move back paragraph"},
497 {v_ncol
, V_CNT
|V_MOVE
|VM_RCM_SET
,
499 " | move to column"},
501 {v_paragraphf
, V_ABS
|V_CNT
|V_MOVE
|VM_CUTREQ
|VM_RCM_SET
,
503 " } move forward paragraph"},
505 {v_ulcase
, V_CNT
|V_DOT
|VM_RCM_SET
,