Changing all of the occurences of the "vi" and "ex" directory to "vi.d"
[unix-history] / usr.bin / vi / nvi / vcmd.c
CommitLineData
18ae9d6b
AS
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char sccsid[] = "@(#)vcmd.c 8.22 (Berkeley) 1/8/94";
36#endif /* not lint */
37
38#include <sys/types.h>
39
40#include "vi.h"
41#include "vcmd.h"
42
43/*
44 * This array maps keystrokes to vi command functions. It is known
45 * in ex/ex_usage.c that it takes four columns to name a vi character.
46 */
47VIKEYS const vikeys [MAXVIKEY + 1] = {
48/* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
49 {NULL},
50/* 001 ^A */
51 {v_searchw, V_ABS|V_CNT|V_MOVE|V_KEYW|V_RCM_SET,
52 "[count]^A",
53 "^A search forward for cursor word"},
54/* 002 ^B */
55 {v_pageup, V_ABS|V_CNT|V_RCM_SETLFNB,
56 "[count]^B",
57 "^B page up by screens"},
58/* 003 ^C */
59 {NULL, 0,
60 "^C",
61 "^C interrupt a search or global command"},
62/* 004 ^D */
63 {v_hpagedown, V_ABS|V_CNT|V_RCM_SETLFNB,
64 "[count]^D",
65 "^D page down by half screens (setting count)"},
66/* 005 ^E */
67 {v_linedown, V_CNT,
68 "[count]^E",
69 "^E page down by lines"},
70/* 006 ^F */
71 {v_pagedown, V_ABS|V_CNT|V_RCM_SETLFNB,
72 "[count]^F",
73 "^F page down by screens"},
74/* 007 ^G */
75 {v_status, 0,
76 "^G",
77 "^G file status"},
78/* 010 ^H */
79 {v_left, V_CNT|V_MOVE|V_RCM_SET,
80 "[count]^H",
81 "^H move left by columns"},
82/* 011 ^I */
83 {NULL},
84/* 012 ^J */
85 {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
86 "[count]^J",
87 "^J move down by lines"},
88/* 013 ^K */
89 {NULL},
90/* 014 ^L */
91 {v_redraw, 0,
92 "^L",
93 "^L redraw screen"},
94/* 015 ^M */
95 {v_cr, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
96 "[count]^M",
97 "^M move down by lines (to first non-blank)"},
98/* 016 ^N */
99 {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
100 "[count]^N",
101 "^N move down by lines"},
102/* 017 ^O */
103 {NULL},
104/* 020 ^P */
105 {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM,
106 "[count]^P",
107 "^P move up by lines"},
108/* 021 ^Q -- not available, used for hardware flow control. */
109 {NULL},
110/* 022 ^R */
111 {v_redraw, 0,
112 "^R",
113 "^R redraw screen"},
114/* 023 ^S -- not available, used for hardware flow control. */
115 {NULL},
116/* 024 ^T */
117 {v_tagpop, V_RCM_SET,
118 "^T",
119 "^T tag pop"},
120/* 025 ^U */
121 {v_hpageup, V_ABS|V_CNT|V_RCM_SETLFNB,
122 "[count]^U",
123 "^U half page up (set count)"},
124/* 026 ^V */
125 {NULL, 0,
126 "^V",
127 "^V input a literal character"},
128/* 027 ^W */
129 {v_screen, 0,
130 "^W",
131 "^W move to next screen"},
132/* 030 ^X */
133 {NULL},
134/* 031 ^Y */
135 {v_lineup, V_CNT,
136 "[count]^Y",
137 "^Y page up by lines"},
138/* 032 ^Z */
139 {v_stop, 0,
140 "^Z",
141 "^Z suspend editor"},
142/* 033 ^[ */
143 {NULL, 0,
144 "^[ <escape>",
145 "^[ <escape> leave input mode, return to command mode"},
146/* 034 ^\ */
147 {NULL},
148/* 035 ^] */
149 {v_tagpush, V_KEYW|V_RCM_SET,
150 "^]",
151 "^] tag push cursor word"},
152/* 036 ^^ */
153 {v_switch, 0,
154 "^^",
155 "^^ switch to previous file"},
156/* 037 ^_ */
157 {NULL},
158/* 040 ' ' */
159 {v_right, V_CNT|V_MOVE|V_RCM_SET,
160 "[count]' '",
161 " <space> move right by columns"},
162/* 041 ! */
163 {v_filter, V_CNT|V_DOT|V_MOTION|V_RCM_SET,
164 "[count]![count]motion command(s)",
165 " ! filter through command(s) to motion"},
166/* 042 " */
167 {NULL},
168/* 043 # */
169 {v_increment, V_CHAR|V_CNT|V_DOT|V_KEYNUM|V_RCM_SET,
170 "[count]#[#+-]",
171 " # number increment/decrement"},
172/* 044 $ */
173 {v_dollar, V_CNT|V_MOVE|V_RCM_SETLAST,
174 " [count]$",
175 " $ move to last column"},
176/* 045 % */
177 {v_match, V_ABS|V_MOVE|V_RCM_SET,
178 "%",
179 " % move to match"},
180/* 046 & */
181 {v_again, 0,
182 "&",
183 " & repeat substitution"},
184/* 047 ' */
185 {v_gomark, V_ABS|V_CHAR|V_LMODE|V_MOVE|V_RCM_SETFNB,
186 "'['a-z]",
187 " ' move to mark (to first non-blank)"},
188/* 050 ( */
189 {v_sentenceb, V_CNT|V_MOVE|V_RCM_SET,
190 "[count](",
191 " ( move back sentence"},
192/* 051 ) */
193 {v_sentencef, V_ABS|V_CNT|V_MOVE|V_RCM_SET,
194 "[count])",
195 " ) move forward sentence"},
196/* 052 * */
197 {NULL},
198/* 053 + */
199 {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
200 "[count]+",
201 " + move down by lines (to first non-blank)"},
202/* 054 , */
203 {v_chrrepeat, V_CNT|V_MOVE|V_RCM_SET,
204 "[count],",
205 " , reverse last F, f, T or t search"},
206/* 055 - */
207 {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
208 "[count]-",
209 " - move up by lines (to first non-blank)"},
210/* 056 . */
211 {NULL, 0,
212 ".",
213 " . repeat the last command"},
214/* 057 / */
215 {v_searchf, V_ABS|V_MOVE|V_RCM_SET,
216 "/RE[/ offset]",
217 " / search forward"},
218/* 060 0 */
219 {v_zero, V_MOVE|V_RCM_SET,
220 "0",
221 " 0 move to first character"},
222/* 061 1 */
223 {NULL},
224/* 062 2 */
225 {NULL},
226/* 063 3 */
227 {NULL},
228/* 064 4 */
229 {NULL},
230/* 065 5 */
231 {NULL},
232/* 066 6 */
233 {NULL},
234/* 067 7 */
235 {NULL},
236/* 070 8 */
237 {NULL},
238/* 071 9 */
239 {NULL},
240/* 072 : */
241 {v_ex, 0,
242 ":command [| command] ...",
243 " : ex command"},
244/* 073 ; */
245 {v_chrepeat, V_CNT|V_MOVE|V_RCM_SET,
246 "[count];",
247 " ; repeat last F, f, T or t search"},
248/* 074 < */
249 {v_shiftl, V_CNT|V_DOT|V_MOTION|V_RCM_SET|VC_SH,
250 "[count]<[count]motion",
251 " < shift lines left to motion"},
252/* 075 = */
253 {NULL},
254/* 076 > */
255 {v_shiftr, V_CNT|V_DOT|V_MOTION|V_RCM_SET|VC_SH,
256 "[count]>[count]motion",
257 " > shift lines right to motion"},
258/* 077 ? */
259 {v_searchb, V_ABS|V_MOVE|V_RCM_SET,
260 "?RE[? offset]",
261 " ? search backward"},
262/* 100 @ */
263 {v_at, V_RBUF|V_RCM_SET,
264 "@buffer",
265 " @ execute buffer"},
266/* 101 A */
267 {v_iA, V_CNT|V_DOT|V_RCM_SET,
268 "[count]A",
269 " A append to the line"},
270/* 102 B */
271 {v_wordB, V_CNT|V_MOVE|V_RCM_SET,
272 "[count]B",
273 " B move back bigword"},
274/* 103 C */
275 {v_Change, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
276 "[buffer][count]C",
277 " C change to end-of-line"},
278/* 104 D */
279 {v_Delete, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
280 "[buffer][count]D",
281 " D delete to end-of-line"},
282/* 105 E */
283 {v_wordE, V_CNT|V_MOVE|V_RCM_SET,
284 "[count]E",
285 " E move to end of bigword"},
286/* 106 F */
287 {v_chF, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
288 "[count]F character",
289 " F character in line backward search"},
290/* 107 G */
291 {v_lgoto, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SETFNB,
292 "[count]G",
293 " G move to line"},
294/* 110 H */
295 {v_home, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
296 "[count]H",
297 " H move to count lines from screen top"},
298/* 111 I */
299 {v_iI, V_CNT|V_DOT|V_RCM_SET,
300 "[count]I",
301 " I insert at line beginning"},
302/* 112 J */
303 {v_join, V_CNT|V_DOT|V_RCM_SET,
304 "[count]J",
305 " J join lines"},
306/* 113 K */
307 {NULL},
308/* 114 L */
309 {v_bottom, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
310 "[count]L",
311 " L move to screen bottom"},
312/* 115 M */
313 {v_middle, V_CNT|V_LMODE|V_MOVE|V_RCM_SETNNB,
314 "M",
315 " M move to screen middle"},
316/* 116 N */
317 {v_searchN, V_ABS|V_MOVE|V_RCM_SET,
318 "n",
319 " N reverse last search"},
320/* 117 O */
321 {v_iO, V_CNT|V_DOT|V_RCM_SET,
322 "[count]O",
323 " O insert above line"},
324/* 120 P */
325 {v_Put, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
326 "[buffer]P",
327 " P insert before cursor from buffer"},
328/* 121 Q */
329 {v_exmode, 0,
330 "Q",
331 " Q switch to ex mode"},
332/* 122 R */
333 {v_Replace, V_CNT|V_DOT|V_RCM_SET,
334 "[count]R",
335 " R replace characters"},
336/* 123 S */
337 {v_Subst, V_CNT|V_DOT|V_LMODE|V_OBUF|V_RCM_SET,
338 "[buffer][count]S",
339 " S substitute for the line(s)"},
340/* 124 T */
341 {v_chT, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
342 "[count]T character",
343 " T before character in line backward search"},
344/* 125 U */
345 {v_Undo, V_RCM_SET,
346 "U",
347 " U Restore the current line"},
348/* 126 V */
349 {NULL},
350/* 127 W */
351 {v_wordW, V_CNT|V_MOVE|V_RCM_SET,
352 "[count]W",
353 " W move to next bigword"},
354/* 130 X */
355 {v_Xchar, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
356 "[buffer][count]X",
357 " X delete character before cursor"},
358/* 131 Y */
359 {v_Yank, V_CNT|V_LMODE|V_OBUF,
360 "[buffer][count]Y",
361 " Y copy line"},
362/* 132 Z */
363 {v_exit, 0,
364 "ZZ",
365 "ZZ save file and exit"},
366/* 133 [ */
367 {v_sectionb, V_ABS|V_LMODE|V_MOVE|V_RCM_SET,
368 "[[",
369 "[[ move back section"},
370/* 134 \ */
371 {NULL},
372/* 135 ] */
373 {v_sectionf, V_ABS|V_LMODE|V_MOVE|V_RCM_SET,
374 "]]",
375 "]] move forward section"},
376/* 136 ^ */
377 /*
378 * DON'T set the V_RCM_SETFNB flag, the function has to do
379 * the work anyway, in case it's a motion component. DO set
380 * V_RCM_SET, so that any motion that's part of a command is
381 * preserved.
382 */
383 {v_first, V_CNT|V_MOVE|V_RCM_SET,
384 "^",
385 " ^ move to first non-blank"},
386/* 137 _ */
387 /*
388 * DON'T set the V_RCM_SETFNB flag, the function has to do
389 * the work anyway, in case it's a motion component. DO set
390 * V_RCM_SET, so that any motion that's part of a command is
391 * preserved.
392 */
393 {v_cfirst, V_CNT|V_MOVE|V_RCM_SET,
394 "_",
395 " _ move to first non-blank"},
396/* 140 ` */
397 {v_gomark, V_ABS|V_CHAR|V_MOVE|V_RCM_SET,
398 "`[`a-z]",
399 " ` move to mark"},
400/* 141 a */
401 {v_ia, V_CNT|V_DOT|V_RCM_SET,
402 "[count]a",
403 " a append after cursor"},
404/* 142 b */
405 {v_wordb, V_CNT|V_MOVE|V_RCM_SET,
406 "[count]b",
407 " b move back word"},
408/* 143 c */
409 {v_change, V_CNT|V_DOT|V_MOTION|V_OBUF|V_RCM_SET|VC_C,
410 "[buffer][count]c[count]motion",
411 " c change to motion"},
412/* 144 d */
413 {v_delete, V_CNT|V_DOT|V_MOTION|V_OBUF|V_RCM_SET|VC_D,
414 "[buffer][count]d[count]motion",
415 " d delete to motion"},
416/* 145 e */
417 {v_worde, V_CNT|V_MOVE|V_RCM_SET,
418 "[count]e",
419 " e move to end of word"},
420/* 146 f */
421 {v_chf, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
422 "[count]f character",
423 " f character in line forward search"},
424/* 147 g */
425 {NULL},
426/* 150 h */
427 {v_left, V_CNT|V_MOVE|V_RCM_SET,
428 "[count]h",
429 " h move left by columns"},
430/* 151 i */
431 {v_ii, V_CNT|V_DOT|V_RCM_SET,
432 "[count]i",
433 " i insert before cursor"},
434/* 152 j */
435 {v_down, V_CNT|V_LMODE|V_MOVE|V_RCM,
436 "[count]j",
437 " j move down by lines"},
438/* 153 k */
439 {v_up, V_CNT|V_LMODE|V_MOVE|V_RCM,
440 "[count]k",
441 " k move up by lines"},
442/* 154 l */
443 {v_right, V_CNT|V_MOVE|V_RCM_SET,
444 "[count]l",
445 " l move right by columns"},
446/* 155 m */
447 {v_mark, V_CHAR,
448 "m[a-z]",
449 " m set mark"},
450/* 156 n */
451 {v_searchn, V_ABS|V_MOVE|V_RCM_SET,
452 "n",
453 " n repeat last search"},
454/* 157 o */
455 {v_io, V_CNT|V_DOT|V_RCM_SET,
456 "[count]o",
457 " o append after line"},
458/* 160 p */
459 {v_put, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
460 "[buffer]p",
461 " p insert after cursor from buffer"},
462/* 161 q */
463 {NULL},
464/* 162 r */
465 {v_replace, V_CNT|V_DOT|V_RCM_SET,
466 "[count]r character",
467 " r replace character"},
468/* 163 s */
469 {v_subst, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
470 "[buffer][count]s",
471 " s substitute character"},
472/* 164 t */
473 {v_cht, V_CHAR|V_CNT|V_MOVE|V_RCM_SET,
474 "[count]t character",
475 " t before character in line forward search"},
476/* 165 u */
477 /*
478 * DON'T set the V_DOT flag, it' more complicated than that.
479 * See vi/vi.c for details.
480 */
481 {v_undo, V_RCM_SET,
482 "u",
483 " u undo last change"},
484/* 166 v */
485 {NULL},
486/* 167 w */
487 {v_wordw, V_CNT|V_MOVE|V_RCM_SET,
488 "[count]w",
489 " w move to next word"},
490/* 170 x */
491 {v_xchar, V_CNT|V_DOT|V_OBUF|V_RCM_SET,
492 "[buffer][count]x",
493 " x delete character"},
494/* 171 y */
495 {v_yank, V_CNT|V_MOTION|V_OBUF|V_RCM_SET|VC_Y,
496 "[buffer][count]y[count]motion",
497 " y copy text to motion into a cut buffer"},
498/* 172 z */
499 /*
500 * DON'T set the V_CHAR flag, the char isn't required,
501 * so it's handled specially in getcmd().
502 */
503 {v_z, V_CNT|V_RCM_SETFNB,
504 "[line]z[window_size][-|.|+|^|<CR>]",
505 " z redraw window"},
506/* 173 { */
507 {v_paragraphb, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SET,
508 "[count]{",
509 " { move back paragraph"},
510/* 174 | */
511 {v_ncol, V_ABS|V_CNT|V_MOVE|V_RCM_SET,
512 "[count]|",
513 " | move to column"},
514/* 175 } */
515 {v_paragraphf, V_ABS|V_CNT|V_LMODE|V_MOVE|V_RCM_SET,
516 "[count]}",
517 " } move forward paragraph"},
518/* 176 ~ */
519 {v_ulcase, V_CNT|V_DOT|V_RCM_SET,
520 "[count]~",
521 " ~ reverse case"},
522};