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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
20 #include "../common/common.h"
23 * This array maps ex command names to command functions.
25 * The order in which command names are listed below is important --
26 * ambiguous abbreviations are resolved to be the first possible match,
27 * e.g. "r" means "read", not "rewind", because "read" is listed before
30 * The syntax of the ex commands is unbelievably irregular, and a special
31 * case from beginning to end. Each command has an associated "syntax
32 * script" which describes the "arguments" that are possible. The script
33 * syntax is as follows:
36 * 1 -- flags: [+-]*[pl#][+-]*
40 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
41 * f[N#][or] -- file (a number or N, optional or required)
43 * S -- string with file name expansion
46 * w[N#][or] -- word (a number or N, optional or required)
48 EXCMDLIST const cmds[] = {
50 {L("\004"), ex_pr, E_ADDR2,
55 {L("!"), ex_bang, E_ADDR2_NONE|E_SECURE,
57 "[line [,line]] ! command",
58 "filter lines through commands or run commands"},
60 {L("#"), ex_number, E_ADDR2|E_CLRFLAG,
62 "[line [,line]] # [count] [l]",
63 "display numbered lines"},
65 {L("&"), ex_subagain, E_ADDR2|E_ADDR_ZERO,
67 "[line [,line]] & [cgr] [count] [#lp]",
68 "repeat the last subsitution"},
75 {L("<"), ex_shiftl, E_ADDR2|E_AUTOPRINT,
77 "[line [,line]] <[<...] [count] [flags]",
80 {L("="), ex_equal, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
83 "display line number"},
85 {L(">"), ex_shiftr, E_ADDR2|E_AUTOPRINT,
87 "[line [,line]] >[>...] [count] [flags]",
90 {L("@"), ex_at, E_ADDR2,
95 {L("append"), ex_append, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
98 "append input to a line"},
100 {L("abbreviate"), ex_abbr, 0,
102 "ab[brev] [word replace]",
103 "specify an input abbreviation"},
105 {L("args"), ex_args, 0,
108 "display file argument list"},
110 {L("bg"), ex_bg, E_VIONLY,
113 "put a foreground screen into the background"},
115 {L("change"), ex_change, E_ADDR2|E_ADDR_ZERODEF,
117 "[line [,line]] c[hange][!] [count]",
118 "change lines to input"},
123 "change the current directory"},
125 {L("chdir"), ex_cd, 0,
127 "chd[ir][!] [directory]",
128 "change the current directory"},
130 {L("copy"), ex_copy, E_ADDR2|E_AUTOPRINT,
132 "[line [,line]] co[py] line [flags]",
133 "copy lines elsewhere in the file"},
135 {L("cscope"), ex_cscope, 0,
137 "cs[cope] command [args]",
138 "create a set of tags using a cscope command"},
141 * Adding new commands starting with 'd' may break the delete command code
142 * in ex_cmd() (the ex parser). Read through the comments there, first.
145 {L("delete"), ex_delete, E_ADDR2|E_AUTOPRINT,
147 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
148 "delete lines from the file"},
150 {L("display"), ex_display, 0,
152 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
153 "display buffers, connections, screens or tags"},
155 {L("edit"), ex_edit, E_NEWSCREEN,
157 "[Ee][dit][!] [+cmd] [file]",
158 "begin editing another file"},
160 {L("ex"), ex_edit, E_NEWSCREEN,
162 "[Ee]x[!] [+cmd] [file]",
163 "begin editing another file"},
165 {L("exusage"), ex_usage, 0,
167 "[exu]sage [command]",
168 "display ex command usage statement"},
170 {L("file"), ex_file, 0,
173 "display (and optionally set) file name"},
175 {L("fg"), ex_fg, E_NEWSCREEN|E_VIONLY,
178 "bring a backgrounded screen into the foreground"},
180 {L("global"), ex_global, E_ADDR2_ALL,
182 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
183 "execute a global command on lines matching an RE"},
185 {L("help"), ex_help, 0,
188 "display help statement"},
190 {L("insert"), ex_insert, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
192 "[line] i[nsert][!]",
193 "insert input before a line"},
195 {L("join"), ex_join, E_ADDR2|E_AUTOPRINT,
197 "[line [,line]] j[oin][!] [count] [flags]",
198 "join lines into a single line"},
200 {L("k"), ex_mark, E_ADDR1,
203 "mark a line position"},
205 {L("list"), ex_list, E_ADDR2|E_CLRFLAG,
207 "[line [,line]] l[ist] [count] [#]",
208 "display lines in an unambiguous form"},
210 {L("move"), ex_move, E_ADDR2|E_AUTOPRINT,
212 "[line [,line]] m[ove] line",
213 "move lines elsewhere in the file"},
215 {L("mark"), ex_mark, E_ADDR1,
218 "mark a line position"},
220 {L("map"), ex_map, 0,
222 "map[!] [keys replace]",
223 "map input or commands to one or more keys"},
225 {L("mkexrc"), ex_mkexrc, 0,
228 "write a .exrc file"},
230 {L("next"), ex_next, E_NEWSCREEN,
232 "[Nn][ext][!] [+cmd] [file ...]",
233 "edit (and optionally specify) the next file"},
235 {L("number"), ex_number, E_ADDR2|E_CLRFLAG,
237 "[line [,line]] nu[mber] [count] [l]",
238 "change display to number lines"},
240 {L("open"), ex_open, E_ADDR1,
242 "[line] o[pen] [/RE/] [flags]",
243 "enter \"open\" mode (not implemented)"},
245 {L("print"), ex_pr, E_ADDR2|E_CLRFLAG,
247 "[line [,line]] p[rint] [count] [#l]",
250 {L("preserve"), ex_preserve, 0,
253 "preserve an edit session for recovery"},
255 {L("previous"), ex_prev, E_NEWSCREEN,
258 "edit the previous file in the file argument list"},
261 E_ADDR1|E_AUTOPRINT|E_ADDR_ZERO|E_ADDR_ZERODEF,
263 "[line] pu[t] [buffer]",
264 "append a cut buffer to the line"},
266 {L("quit"), ex_quit, 0,
271 {L("read"), ex_read, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
273 "[line] r[ead] [!cmd | [file]]",
274 "append input from a command or file to the line"},
276 {L("recover"), ex_recover, 0,
279 "recover a saved file"},
281 {L("resize"), ex_resize, E_VIONLY,
284 "grow or shrink the current screen"},
286 {L("rewind"), ex_rew, 0,
289 "re-edit all the files in the file argument list"},
292 * Adding new commands starting with 's' may break the substitute command code
293 * in ex_cmd() (the ex parser). Read through the comments there, first.
296 {L("s"), ex_s, E_ADDR2|E_ADDR_ZERO,
298 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
299 "substitute on lines matching an RE"},
301 {L("script"), ex_script, E_SECURE,
303 "sc[ript][!] [file]",
304 "run a shell in a screen"},
306 {L("set"), ex_set, 0,
308 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
309 "set options (use \":set all\" to see all options)"},
311 {L("shell"), ex_shell, E_SECURE,
314 "suspend editing and run a shell"},
316 {L("source"), ex_source, 0,
319 "read a file of ex commands"},
321 {L("stop"), ex_stop, E_SECURE,
324 "suspend the edit session"},
326 {L("suspend"), ex_stop, E_SECURE,
329 "suspend the edit session"},
331 {L("t"), ex_copy, E_ADDR2|E_AUTOPRINT,
333 "[line [,line]] t line [flags]",
334 "copy lines elsewhere in the file"},
336 {L("tag"), ex_tag_push, E_NEWSCREEN,
338 "[Tt]a[g][!] [string]",
339 "edit the file containing the tag"},
341 {L("tagnext"), ex_tag_next, 0,
344 "move to the next tag"},
346 {L("tagpop"), ex_tag_pop, 0,
348 "tagp[op][!] [number | file]",
349 "return to the previous group of tags"},
351 {L("tagprev"), ex_tag_prev, 0,
354 "move to the previous tag"},
356 {L("tagtop"), ex_tag_top, 0,
361 {L("undo"), ex_undo, E_AUTOPRINT,
364 "undo the most recent change"},
366 {L("unabbreviate"),ex_unabbr, 0,
369 "delete an abbreviation"},
371 {L("unmap"), ex_unmap, 0,
374 "delete an input or command map"},
376 {L("v"), ex_v, E_ADDR2_ALL,
378 "[line [,line]] v [;/]RE[;/] [commands]",
379 "execute a global command on lines NOT matching an RE"},
381 {L("version"), ex_version, 0,
384 "display the program version information"},
386 {L("visual"), ex_visual, E_ADDR1|E_ADDR_ZERODEF,
388 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
389 "enter visual (vi) mode from ex mode"},
391 {L("visual"), ex_edit, E_NEWSCREEN,
393 "[Vv]i[sual][!] [+cmd] [file]",
394 "edit another file (from vi mode only)"},
396 {L("viusage"), ex_viusage, 0,
399 "display vi key usage statement"},
401 {L("vsplit"), ex_edit, E_VIONLY,
403 "vs[plit] [+cmd] [file]",
404 "split the current screen vertically"},
406 {L("write"), ex_write, E_ADDR2_ALL|E_ADDR_ZERODEF,
408 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
411 {L("wn"), ex_wn, E_ADDR2_ALL|E_ADDR_ZERODEF,
413 "[line [,line]] wn[!] [>>] [file]",
414 "write the file and switch to the next file"},
416 {L("wq"), ex_wq, E_ADDR2_ALL|E_ADDR_ZERODEF,
418 "[line [,line]] wq[!] [>>] [file]",
419 "write the file and exit"},
421 {L("xit"), ex_xit, E_ADDR2_ALL|E_ADDR_ZERODEF,
423 "[line [,line]] x[it][!] [file]",
426 {L("yank"), ex_yank, E_ADDR2,
428 "[line [,line]] ya[nk] [buffer] [count]",
429 "copy lines to a cut buffer"},
431 {L("z"), ex_z, E_ADDR1,
433 "[line] z [-|.|+|^|=] [count] [flags]",
434 "display different screens of the file"},
436 {L("~"), ex_subtilde, E_ADDR2|E_ADDR_ZERO,
438 "[line [,line]] ~ [cgr] [count] [#lp]",
439 "replace previous RE with previous replacement string,"},