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
[] = "$Id: ex_cmd.c,v 10.22 1996/10/31 09:29:47 bostic Exp $ (Berkeley) $Date: 1996/10/31 09:29:47 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
23 #include "../common/common.h"
26 * This array maps ex command names to command functions.
28 * The order in which command names are listed below is important --
29 * ambiguous abbreviations are resolved to be the first possible match,
30 * e.g. "r" means "read", not "rewind", because "read" is listed before
33 * The syntax of the ex commands is unbelievably irregular, and a special
34 * case from beginning to end. Each command has an associated "syntax
35 * script" which describes the "arguments" that are possible. The script
36 * syntax is as follows:
39 * 1 -- flags: [+-]*[pl#][+-]*
43 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
44 * f[N#][or] -- file (a number or N, optional or required)
46 * S -- string with file name expansion
49 * w[N#][or] -- word (a number or N, optional or required)
51 EXCMDLIST
const cmds
[] = {
53 {"\004", ex_pr
, E_ADDR2
,
58 {"!", ex_bang
, E_ADDR2_NONE
| E_SECURE
,
60 "[line [,line]] ! command",
61 "filter lines through commands or run commands"},
63 {"#", ex_number
, E_ADDR2
|E_CLRFLAG
,
65 "[line [,line]] # [count] [l]",
66 "display numbered lines"},
68 {"&", ex_subagain
, E_ADDR2
,
70 "[line [,line]] & [cgr] [count] [#lp]",
71 "repeat the last subsitution"},
78 {"<", ex_shiftl
, E_ADDR2
|E_AUTOPRINT
,
80 "[line [,line]] <[<...] [count] [flags]",
83 {"=", ex_equal
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
86 "display line number"},
88 {">", ex_shiftr
, E_ADDR2
|E_AUTOPRINT
,
90 "[line [,line]] >[>...] [count] [flags]",
98 {"append", ex_append
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
100 "[line] a[ppend][!]",
101 "append input to a line"},
103 {"abbreviate", ex_abbr
, 0,
105 "ab[brev] [word replace]",
106 "specify an input abbreviation"},
111 "display file argument list"},
113 {"bg", ex_bg
, E_VIONLY
,
116 "put a foreground screen into the background"},
118 {"change", ex_change
, E_ADDR2
|E_ADDR_ZERODEF
,
120 "[line [,line]] c[hange][!] [count]",
121 "change lines to input"},
126 "change the current directory"},
130 "chd[ir][!] [directory]",
131 "change the current directory"},
133 {"copy", ex_copy
, E_ADDR2
|E_AUTOPRINT
,
135 "[line [,line]] co[py] line [flags]",
136 "copy lines elsewhere in the file"},
138 {"cscope", ex_cscope
, 0,
140 "cs[cope] command [args]",
141 "create a set of tags using a cscope command"},
144 * Adding new commands starting with 'd' may break the delete command code
145 * in ex_cmd() (the ex parser). Read through the comments there, first.
148 {"delete", ex_delete
, E_ADDR2
|E_AUTOPRINT
,
150 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
151 "delete lines from the file"},
153 {"display", ex_display
, 0,
155 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
156 "display buffers, connections, screens or tags"},
158 {"edit", ex_edit
, E_NEWSCREEN
,
160 "[Ee][dit][!] [+cmd] [file]",
161 "begin editing another file"},
163 {"ex", ex_edit
, E_NEWSCREEN
,
165 "[Ee]x[!] [+cmd] [file]",
166 "begin editing another file"},
168 {"exusage", ex_usage
, 0,
170 "[exu]sage [command]",
171 "display ex command usage statement"},
176 "display (and optionally set) file name"},
178 {"fg", ex_fg
, E_NEWSCREEN
|E_VIONLY
,
181 "bring a backgrounded screen into the foreground"},
183 {"global", ex_global
, E_ADDR2_ALL
,
185 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
186 "execute a global command on lines matching an RE"},
191 "display help statement"},
193 {"insert", ex_insert
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
195 "[line] i[nsert][!]",
196 "insert input before a line"},
198 {"join", ex_join
, E_ADDR2
|E_AUTOPRINT
,
200 "[line [,line]] j[oin][!] [count] [flags]",
201 "join lines into a single line"},
203 {"k", ex_mark
, E_ADDR1
,
206 "mark a line position"},
208 {"list", ex_list
, E_ADDR2
|E_CLRFLAG
,
210 "[line [,line]] l[ist] [count] [#]",
211 "display lines in an unambiguous form"},
213 {"move", ex_move
, E_ADDR2
|E_AUTOPRINT
,
215 "[line [,line]] m[ove] line",
216 "move lines elsewhere in the file"},
218 {"mark", ex_mark
, E_ADDR1
,
221 "mark a line position"},
225 "map[!] [keys replace]",
226 "map input or commands to one or more keys"},
228 {"mkexrc", ex_mkexrc
, 0,
231 "write a .exrc file"},
233 {"next", ex_next
, E_NEWSCREEN
,
235 "[Nn][ext][!] [+cmd] [file ...]",
236 "edit (and optionally specify) the next file"},
238 {"number", ex_number
, E_ADDR2
|E_CLRFLAG
,
240 "[line [,line]] nu[mber] [count] [l]",
241 "change display to number lines"},
243 {"open", ex_open
, E_ADDR1
,
245 "[line] o[pen] [/RE/] [flags]",
246 "enter \"open\" mode (not implemented)"},
248 {"print", ex_pr
, E_ADDR2
|E_CLRFLAG
,
250 "[line [,line]] p[rint] [count] [#l]",
253 {"perl", ex_perl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
254 E_ADDR_ZERODEF
|E_SECURE
,
257 "run the perl interpreter with the command"},
259 {"perldo", ex_perl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
260 E_ADDR_ZERODEF
|E_SECURE
,
263 "run the perl interpreter with the command, on each line"},
265 {"preserve", ex_preserve
, 0,
268 "preserve an edit session for recovery"},
270 {"previous", ex_prev
, E_NEWSCREEN
,
273 "edit the previous file in the file argument list"},
276 E_ADDR1
|E_AUTOPRINT
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
278 "[line] pu[t] [buffer]",
279 "append a cut buffer to the line"},
286 {"read", ex_read
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
288 "[line] r[ead] [!cmd | [file]]",
289 "append input from a command or file to the line"},
291 {"recover", ex_recover
, 0,
294 "recover a saved file"},
296 {"resize", ex_resize
, E_VIONLY
,
299 "grow or shrink the current screen"},
301 {"rewind", ex_rew
, 0,
304 "re-edit all the files in the file argument list"},
307 * Adding new commands starting with 's' may break the substitute command code
308 * in ex_cmd() (the ex parser). Read through the comments there, first.
313 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
314 "substitute on lines matching an RE"},
316 {"script", ex_script
, E_SECURE
,
318 "sc[ript][!] [file]",
319 "run a shell in a screen"},
323 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
324 "set options (use \":set all\" to see all options)"},
326 {"shell", ex_shell
, E_SECURE
,
329 "suspend editing and run a shell"},
331 {"source", ex_source
, 0,
334 "read a file of ex commands"},
336 {"stop", ex_stop
, E_SECURE
,
339 "suspend the edit session"},
341 {"suspend", ex_stop
, E_SECURE
,
344 "suspend the edit session"},
346 {"t", ex_copy
, E_ADDR2
|E_AUTOPRINT
,
348 "[line [,line]] t line [flags]",
349 "copy lines elsewhere in the file"},
351 {"tag", ex_tag_push
, E_NEWSCREEN
,
353 "[Tt]a[g][!] [string]",
354 "edit the file containing the tag"},
356 {"tagnext", ex_tag_next
, 0,
359 "move to the next tag"},
361 {"tagpop", ex_tag_pop
, 0,
363 "tagp[op][!] [number | file]",
364 "return to the previous group of tags"},
366 {"tagprev", ex_tag_prev
, 0,
369 "move to the previous tag"},
371 {"tagtop", ex_tag_top
, 0,
376 {"tcl", ex_tcl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
377 E_ADDR_ZERODEF
|E_SECURE
,
380 "run the tcl interpreter with the command"},
382 {"undo", ex_undo
, E_AUTOPRINT
,
385 "undo the most recent change"},
387 {"unabbreviate",ex_unabbr
, 0,
390 "delete an abbreviation"},
392 {"unmap", ex_unmap
, 0,
395 "delete an input or command map"},
397 {"v", ex_v
, E_ADDR2_ALL
,
399 "[line [,line]] v [;/]RE[;/] [commands]",
400 "execute a global command on lines NOT matching an RE"},
402 {"version", ex_version
, 0,
405 "display the program version information"},
407 {"visual", ex_visual
, E_ADDR1
|E_ADDR_ZERODEF
,
409 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
410 "enter visual (vi) mode from ex mode"},
412 {"visual", ex_edit
, E_NEWSCREEN
,
414 "[Vv]i[sual][!] [+cmd] [file]",
415 "edit another file (from vi mode only)"},
417 {"viusage", ex_viusage
, 0,
420 "display vi key usage statement"},
422 {"vsplit", ex_edit
, E_VIONLY
,
424 "vs[plit] [+cmd] [file]",
425 "split the current screen vertically"},
427 {"write", ex_write
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
429 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
432 {"wn", ex_wn
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
434 "[line [,line]] wn[!] [>>] [file]",
435 "write the file and switch to the next file"},
437 {"wq", ex_wq
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
439 "[line [,line]] wq[!] [>>] [file]",
440 "write the file and exit"},
442 {"xit", ex_xit
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
444 "[line [,line]] x[it][!] [file]",
447 {"yank", ex_yank
, E_ADDR2
,
449 "[line [,line]] ya[nk] [buffer] [count]",
450 "copy lines to a cut buffer"},
454 "[line] z [-|.|+|^|=] [count] [flags]",
455 "display different screens of the file"},
457 {"~", ex_subtilde
, E_ADDR2
,
459 "[line [,line]] ~ [cgr] [count] [#lp]",
460 "replace previous RE with previous replacement string,"},