2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_cmd.c,v 8.33 1993/12/22 16:59:37 bostic Exp $ (Berkeley) $Date: 1993/12/22 16:59:37 $";
12 #include <sys/types.h>
18 * This array maps ex command names to command functions.
20 * The order in which command names are listed below is important --
21 * ambiguous abbreviations are resolved to be the first possible match,
22 * e.g. "r" means "read", not "rewind", because "read" is listed before
25 * The syntax of the ex commands is unbelievably irregular, and a special
26 * case from beginning to end. Each command has an associated "syntax
27 * script" which describes the "arguments" that are possible. The script
28 * syntax is as follows:
31 * 1 -- flags: [+-]*[pl#][+-]*
35 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
36 * f[N#][or] -- file (a number or N, optional or required)
38 * S -- string with file name expansion
41 * w[N#][or] -- word (a number or N, optional or required)
43 EXCMDLIST
const cmds
[] = {
45 {"!", ex_bang
, E_ADDR2_NONE
|E_NORC
,
47 "[line [,line]] ! command",
48 "filter lines through commands or run commands"},
50 {"#", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
52 "[line [,line]] # [count] [l]",
53 "display numbered lines"},
55 {"&", ex_subagain
, E_ADDR2
|E_NORC
,
57 "[line [,line]] & [cgr] [count] [#lp]",
58 "repeat the last subsitution"},
65 {"<", ex_shiftl
, E_ADDR2
|E_NORC
,
67 "[line [,line]] <[<...] [count] [flags]",
70 {"=", ex_equal
, E_ADDR1
|E_NORC
,
73 "display line number"},
75 {">", ex_shiftr
, E_ADDR2
|E_NORC
,
77 "[line [,line]] >[>...] [count] [flags]",
85 {"~", ex_subtilde
, E_ADDR2
|E_NORC
,
87 "[line [,line]] ~ [cgr] [count] [#lp]",
88 "replace previous RE with previous replacement string,"},
91 * If you enter any multiple letter commands that sort before "append",
92 * you'll have to modify ex.c:ex_comm_search routine to start searching
93 * at that command instead of at C_APPEND.
96 {"append", ex_append
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
99 "append input to a line"},
101 {"abbreviate", ex_abbr
, E_NOGLOBAL
,
103 "ab[brev] word replace",
104 "specify an input abbreviation"},
106 {"args", ex_args
, E_NOGLOBAL
|E_NORC
,
109 "display file argument list"},
111 {"bg", ex_bg
, E_NOGLOBAL
|E_NORC
,
114 "background the current screen"},
116 {"change", ex_change
, E_ADDR2
|E_NORC
|E_ZERODEF
,
118 "[line [,line]] c[hange][!] [count]",
119 "change lines to input"},
121 {"cd", ex_cd
, E_NOGLOBAL
,
124 "change the current directory"},
126 {"chdir", ex_cd
, E_NOGLOBAL
,
128 "chd[ir][!] [directory]",
129 "change the current directory"},
131 {"copy", ex_copy
, E_ADDR2
|E_NORC
,
133 "[line [,line]] co[py] line [flags]",
134 "copy lines elsewhere in the file"},
136 {"delete", ex_delete
, E_ADDR2
|E_NORC
,
138 "[line [,line]] d[elete] [buffer] [count] [flags]",
139 "delete lines from the file"},
141 {"display", ex_display
, E_NOGLOBAL
|E_NORC
,
143 "display b[uffers] | s[creens] | t[ags]",
144 "display buffers, screens or tags"},
146 {"digraph", ex_digraph
, E_NOGLOBAL
|E_NOPERM
|E_NORC
,
149 "specify digraphs (not implemented)"},
151 {"edit", ex_edit
, E_NOGLOBAL
|E_NORC
,
153 "e[dit][!] [+cmd] [file]",
154 "begin editing another file"},
156 {"ex", ex_edit
, E_NOGLOBAL
|E_NORC
,
158 "ex[!] [+cmd] [file]",
159 "begin editing another file"},
161 {"exusage", ex_usage
, E_NOGLOBAL
|E_NORC
,
163 "[exu]sage [command]",
164 "display ex command usage statement"},
166 {"file", ex_file
, E_NOGLOBAL
|E_NORC
,
169 "display (and optionally set) file name"},
171 {"fg", ex_fg
, E_NOGLOBAL
|E_NORC
,
174 "switch the current screen and a backgrounded screen"},
176 {"global", ex_global
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
178 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
179 "execute a global command on lines matching a pattern"},
181 {"help", ex_help
, E_NOGLOBAL
|E_NORC
,
184 "display help statement"},
186 {"insert", ex_insert
, E_ADDR1
|E_NORC
,
188 "[line] i[nsert][!]",
189 "insert input before a line"},
191 {"join", ex_join
, E_ADDR2
|E_NORC
,
193 "[line [,line]] j[oin][!] [count] [flags]",
194 "join lines into a single line"},
196 {"k", ex_mark
, E_ADDR1
|E_NORC
,
199 "mark a line position"},
201 {"list", ex_list
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
203 "[line [,line]] l[ist] [count] [#]",
204 "display lines in an unambiguous form"},
206 {"move", ex_move
, E_ADDR2
|E_NORC
,
208 "[line [,line]] m[ove] line",
209 "move lines elsewhere in the file"},
211 {"mark", ex_mark
, E_ADDR1
|E_NORC
,
214 "mark a line position"},
218 "map[!] [keys replace]",
219 "map input or commands to one or more keys"},
221 {"mkexrc", ex_mkexrc
, E_NOGLOBAL
|E_NORC
,
224 "write a .exrc file"},
226 {"next", ex_next
, E_NOGLOBAL
|E_NORC
,
228 "n[ext][!] [file ...]",
229 "edit (and optionally specify) the next file"},
231 {"number", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
233 "[line [,line]] nu[mber] [count] [l]",
234 "change display to number lines"},
236 {"open", ex_open
, E_ADDR1
,
238 "[line] o[pen] [/pattern/] [flags]",
239 "enter \"open\" mode (not implemented)"},
241 {"print", ex_pr
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
243 "[line [,line]] p[rint] [count] [#l]",
246 {"preserve", ex_preserve
, E_NOGLOBAL
|E_NORC
,
249 "preserve an edit session for recovery"},
251 {"previous", ex_prev
, E_NOGLOBAL
|E_NORC
,
254 "edit the previous file in the file argument list"},
256 {"put", ex_put
, E_ADDR1
|E_NORC
|E_ZERO
,
258 "[line] pu[t] [buffer]",
259 "append a cut buffer to the line"},
261 {"quit", ex_quit
, E_NOGLOBAL
,
266 {"read", ex_read
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
268 "[line] r[ead] [!cmd | [file]]",
269 "append input from a command or file to the line"},
271 {"resize", ex_resize
, E_NOGLOBAL
|E_NORC
,
274 "grow or shrink the current screen"},
276 {"rewind", ex_rew
, E_NOGLOBAL
|E_NORC
,
279 "re-edit all the files in the file argument list"},
281 {"substitute", ex_substitute
, E_ADDR2
|E_NORC
,
283 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
284 "substitute on lines matching a pattern"},
286 {"script", ex_script
, E_NOGLOBAL
|E_NORC
,
288 "sc[ript][!] [file]",
289 "run a shell in a screen"},
291 {"set", ex_set
, E_NOGLOBAL
,
293 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
294 "set options (use \":set all\" to see all options)"},
296 {"shell", ex_shell
, E_NOGLOBAL
|E_NORC
,
299 "suspend editing and run a shell"},
301 {"source", ex_source
, E_NOGLOBAL
,
304 "read a file of ex commands"},
306 {"split", ex_split
, E_NOGLOBAL
|E_NORC
,
308 "s[plit] [file ...]",
309 "split the current screen into two screens"},
311 {"stop", ex_stop
, E_NOGLOBAL
|E_NORC
,
314 "suspend the edit session"},
316 {"suspend", ex_stop
, E_NOGLOBAL
|E_NORC
,
319 "suspend the edit session"},
321 {"t", ex_copy
, E_ADDR2
|E_NORC
,
323 "[line [,line]] t line [flags]",
324 "move lines elsewhere in the file"},
326 {"tag", ex_tagpush
, E_NOGLOBAL
,
329 "edit the file containing the tag"},
331 {"tagpop", ex_tagpop
, E_NOGLOBAL
|E_NORC
,
333 "tagp[op][!] [number | file]",
334 "return to a previous tag"},
336 {"tagtop", ex_tagtop
, E_NOGLOBAL
|E_NORC
,
339 "return to the first tag"},
341 {"Undo", ex_undol
, E_NOGLOBAL
|E_NORC
,
344 "undo all the changes to this line"},
346 {"undo", ex_undo
, E_NOGLOBAL
|E_NORC
,
349 "undo the most recent change"},
351 {"unabbreviate",ex_unabbr
, E_NOGLOBAL
,
354 "delete an abbreviation"},
356 {"unmap", ex_unmap
, E_NOGLOBAL
,
359 "delete an input or command map"},
361 {"vglobal", ex_vglobal
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
363 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
364 "execute a global command on lines NOT matching a pattern"},
366 {"version", ex_version
, E_NOGLOBAL
|E_NORC
,
369 "display the program version information"},
371 {"visual", ex_visual
, E_ADDR1
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
373 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
374 "enter visual (vi) mode from ex mode"},
376 {"visual", ex_edit
, E_NOGLOBAL
|E_NORC
,
378 "vi[sual][!] [+cmd] [file]",
379 "edit another file (from vi mode only)"},
381 {"viusage", ex_viusage
, E_NOGLOBAL
|E_NORC
,
384 "display vi key usage statement"},
386 {"write", ex_write
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
388 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
391 {"wq", ex_wq
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
393 "[line [,line]] wq[!] [>>] [file]",
394 "write the file and exit"},
396 {"xit", ex_xit
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
398 "[line [,line]] x[it][!] [file]",
401 {"yank", ex_yank
, E_ADDR2
|E_NORC
,
403 "[line [,line]] ya[nk] [buffer] [count]",
404 "copy lines to a cut buffer"},
406 {"z", ex_z
, E_ADDR1
|E_NOGLOBAL
|E_NORC
,
408 "[line] z [-|.|+|^|=] [count] [flags]",
409 "display different screens of the file"},