386BSD 0.1 development
[unix-history] / usr / src / usr.bin / elvis / doc / ex.ms
CommitLineData
f5bcab4b
WJ
1.Go 3 "COLON MODE COMMANDS"
2.ID
3.ps
4.in 0.8i
5.ta 2i 3.i
6.\" NOTE: The following macro is used to output a single line of the
7.\" command chart. Its usage is:
8.\"
9.\" .Cm <linespecs> <name> <arguments>...
10.\"
11.de Cm
12.if "\\$1"0" \t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
13.if "\\$1"1" \s-2[line]\s+2\t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
14.if "\\$1"2" \s-2[line][,line]\s+2\t\\$2\t\\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
15..
16.if t .ds Q ``
17.if t .ds U ''
18.if n .ds Q "
19.if n .ds U "
20\s+2LINES COMMAND ARGUMENTS\s-2
21.Cm 0 ab[br] [short] [expanded form]
22.Cm 1 a[ppend][!]
23.Cm 0 ar[gs] [files]
24.Cm 0 cc [files]
25.Cm 0 cd[!] [directory]
26.Cm 2 c[hange]
27.Cm 0 chd[ir][!] [directory]
28.Cm 2 co[py] line
29.Cm 0 col[or] [when] [[\*Qlight\*U] color] [\*Qon\*U color]
30.Cm 2 d[elete] [\*Ux]
31.Cm 0 dig[raph][!] [XX [Y]]
32.Cm 0 e[dit][!] [file]
33.Cm 0 er[rlist][!] [errlist]
34.Cm 0 f[ile] [file]
35.Cm 2 g[lobal] /regexp/ command
36.Cm 1 i[nsert]
37.Cm 2 j[oin][!]
38.Cm 2 l[ist]
39.Cm 0 mak[e] [target]
40.Cm 0 map[!] key mapped_to
41.Cm 1 ma[rk] \*Ux
42.Cm 0 mk[exrc]
43.Cm 2 m[ove] line
44.Cm 0 n[ext][!] [files]
45.Cm 0 N[ext][!]
46.Cm 2 nu[mber]
47.Cm 2 p[rint]
48.Cm 1 pu[t] [\*Ux]
49.Cm 0 q[uit][!]
50.Cm 1 r[ead] file
51.Cm 0 rew[ind][!]
52.Cm 0 se[t] [options]
53.Cm 0 so[urce] file
54.Cm 2 s[ubstitute] /regexp/replacement/[p][g][c]
55.Cm 0 ta[g][!] tagname
56.Cm 0 una[bbr] [short]
57.Cm 0 u[ndo]
58.Cm 0 unm[ap][!] key
59.Cm 0 ve[rsion]
60.Cm 2 v[global] /regexp/ command
61.Cm 0 vi[sual] [filename]
62.Cm 0 wq
63.Cm 2 w[rite][!] [[>>]file]
64.Cm 0 x[it][!]
65.Cm 2 y[ank] [\*Ux]
66.Cm 2 ! command
67.Cm 2 <
68.Cm 2 =
69.Cm 2 >
70.Cm 2 &
71.Cm 0 @ "" \*Ux
72.DE
73.TA
74.PP
75To use colon mode commands, you must switch from visual command
76mode to colon command mode.
77The visual mode commands to do this are ":" for a single colon command,
78or "Q" for many colon mode commands.
79.NH 2
80Line Specifiers
81.PP
82Line specifiers are always optional.
83The first line specifier of most commands usually defaults to the current line.
84The second line specifier usually defaults to be the same
85as the first line specifier.
86Exceptions are :write, :global, and :vglobal, which act on all lines of the
87file by default, and :!, which acts on no lines by default.
88.PP
89Line specifiers consist of an absolute part and a relative part.
90The absolute part of a line specifier may be either an explicit line number,
91a mark, a dot to denote the current line, a dollar sign to denote the last
92line of the file, or a forward or backward search.
93.PP
94An explicit line number is simply a decimal number, expressed as a
95string of digits.
96.PP
97A mark is typed in as an apostrophe followed by a letter.
98Marks must be set before they can be used.
99You can set a mark in visual command mode by typing "m" and a letter,
100or you can set it in colon command mode via the "mark" command.
101.PP
102A forward search is typed in as a regular expression surrounded by
103slash characters; searching begins at the default line.
104A backward search is typed in as a regular expression surrounded by
105question marks; searching begins at the line before the default line.
106.PP
107If you omit the absolute part, then the default line is used.
108.PP
109The relative part of a line specifier is typed as a "+" or "-" character
110followed by a decimal number.
111The number is added to or subtracted from the absolute part
112of the line specifier to produce the final line number.
113.PP
114As a special case, the % character may be used to specify all lines of the file.
115It is roughly equivelent to saying 1,$.
116This can be a handy shortcut.
117.PP
118Some examples:
119.LD
120.ps
121.ta 0.5i 1.8i
122 :p print the current line
123 :37p print line 37
124 :'gp print the line which contains mark g
125 :/foo/p print the next line that contains "foo"
126 :$p print the last line of the file
127 :20,30p print lines 20 through 30
128 :1,$p print all lines of the file
129 :%p print all lines of the file
130 :/foo/-2,+4p print 5 lines around the next "foo"
131.TA
132.DE
133.NH 2
134Text Entry Commands
135.if n .ul 0
136.ID
137.ps
138[line] append
139[line][,line] change ["x]
140[line] insert
141.DE
142.PP
143The \fBa\fRppend command inserts text after the specified line.
144.PP
145The \fBi\fRnsert command inserts text before the specified line.
146.PP
147The \fBc\fRhange command copies the range of lines into a cut buffer,
148deletes them, and inserts new text where the old text used to be.
149.PP
150For all of these commands, you indicate the end of the text you're
151inserting by hitting ^D or by entering a line which contains only a
152period.
153.NH 2
154Cut & Paste Commands
155.if n .ul 0
156.ID
157.ps
158[line][,line] delete ["x]
159[line][,line] yank ["x]
160[line] put ["x]
161[line][,line] copy line
162[line][,line] to line
163[line][,line] move line
164.DE
165.PP
166The \fBd\fRelete command copies the specified range of lines into a
167cut buffer, and then deletes them.
168.PP
169The \fBy\fRank command copies the specified range of lines into a cut
170buffer, but does *not* delete them.
171.PP
172The \fBpu\fRt command inserts text from a cut buffer after the
173specified line.
174.PP
175The \fBco\fRpy and \fBt\fRo commands yank the specified range of lines and
176then immediately paste them after some other line.
177.PP
178The \fBm\fRove command deletes the specified range of lines and then
179immediately pastes them after some other line.
180If the destination line comes after the deleted text,
181then it will be adjusted automatically to account for the deleted lines.
182.NH 2
183Display Text Commands
184.if n .ul 0
185.ID
186.ps
187[line][,line] print
188[line][,line] list
189[line][,line] number
190.DE
191.PP
192The \fBp\fRrint command displays the specified range of lines.
193.PP
194The \fBnu\fRmber command displays the lines, with line numbers.
195.PP
196The \fBl\fRist command also displays them, but it is careful to make
197control characters visible.
198.NH 2
199Global Operations Commands
200.if n .ul 0
201.ID
202.ps
203[line][,line] global /regexp/ command
204[line][,line] vglobal /regexp/ command
205.DE
206.PP
207The \fBg\fRlobal command searches through the lines of the specified range
208(or through the whole file if no range is specified)
209for lines that contain a given regular expression.
210It then moves the cursor to each of these lines and
211runs some other command on them.
212.PP
213The \fBv\fRglobal command is similar, but it searches for lines that \fIdon't\fR
214contain the regular expression.
215.NH 2
216Line Editing Commands
217.if n .ul 0
218.ID
219.ps
220[line][,line] join[!]
221[line][,line] ! program
222[line][,line] <
223[line][,line] >
224[line][,line] substitute /regexp/replacement/[p][g][c]
225[line][,line] &
226.DE
227.PP
228The \fBj\fRoin command catenates all lines in the specified range together
229to form one big line.
230If only a single line is specified, then the following line is catenated
231onto it.
232The normal ":join" inserts one or two spaces between the lines;
233the ":join!" variation (with a '!') doesn't insert spaces.
234.PP
235The \fB!\fR command runs an external filter program,
236and feeds the specified range of lines to it's stdin.
237The lines are then replaced by the output of the filter.
238A typical example would be ":'a,'z!sort" to sort the lines 'a,'z.
239.PP
240The \fB<\fR and \fB>\fR commands shift the specified range of lines left or right,
241normally by the width of 1 tab character.
242The "shiftwidth" option determines the shifting amount.
243.PP
244The \fBs\fRubstitute command finds the regular expression in each line,
245and replaces it with the replacement text.
246The "p" option causes the altered lines to be printed.
247The "g" option permits all instances of the regular expression
248to be found & replaced.
249(Without "g", only the first occurrence in each line is replaced.)
250The "c" option asks for confirmation before each substitution.
251.PP
252The \fB&\fR command repeats the previous substitution command.
253Actually, "&" is equivelent to "s//~/" with the same options as last time.
254It searches for the last regular expression that you specified for any purpose,
255and replaces it with the the same text
256that was used in the previous substitution.
257.NH 2
258Undo Command
259.if n .ul 0
260.ID
261.ps
262undo
263.DE
264.PP
265The \fBu\fRndo command restores the file to the state it was in before
266your most recent command which changed text.
267.NH 2
268Configuration & Status Commands
269.if n .ul 0
270.ID
271.ps
272map[!] [key mapped_to]
273unmap[!] key
274abbr [word expanded_form_of_word]
275unabbr word
276digraph[!] [XX [Y]]
277set [options]
278mkexrc
279[line] mark "x
280visual
281version
282[line][,line] =
283file [file]
284source file
285@ "x
286color [when] [["light"] color] ["on" color]
287.DE
288.PP
289The \fBma\fRp command allows you to configure \*E to recognize your function keys,
290and treat them as though they transmitted some other sequence of characters.
291Normally this mapping is done only when in the visual command mode,
292but with the [!] present it will map keys under input and replace modes as well.
293When this command is given with no arguments,
294it prints a table showing all mappings currently in effect.
295When called with two arguments, the first is the sequence that your
296function key really sends, and the second is the sequence that you want
297\*E to treat it as having sent.
298As a special case, if the first argument is a number then \*E will map the
299corresponding function key;
300for example, ":map 7 dd" will cause the <F7> key to delete a line.
301.PP
302The \fBunm\fRap command removes key definitions that were made via the map command.
303.PP
304The \fBab\fRbr command is used to define/list a table of abbreviations.
305The table contains both the abbreviated form and the fully spelled-out form.
306When you're in visual input mode, and you type in the abbreviated form,
307\*E will replace the abbreviated form with the fully spelled-out form.
308When this command is called without arguments, it lists the table;
309with two or more arguments, the first argument is taken as the abbreviated
310form, and the rest of the command line is the fully-spelled out form.
311.PP
312The \fBuna\fRbbr command deletes entries from the abbr table.
313.PP
314The \fBdi\fRgraph command allows you to display the set of digraphs that \*E is
315using, or add/remove a digraph.
316To list the set of digraphs, use the digraph command with no arguments.
317To add a digraph, you should give the digraph command two arguments.
318The first argument is the two ASCII characters that are to be combined;
319the second is the non-ASCII character that they represent.
320The non-ASCII character's most significant bit is automatically set by the
321digraph command, unless to append a ! to the command name.
322Removal of a digraph is similar to adding a digraph, except that you should
323leave off the second argument.
324.PP
325The \fBse\fRt command allows you examine or set various options.
326With no arguments, it displays the values of options that have been changed.
327With the single argument "all" it displays the values of all options,
328regardless of whether they've been explicitly set or not.
329Otherwise, the arguments are treated as options to be set.
330.PP
331The \fBmk\fRexrc command saves the current configuration to a file
332called ".exrc" in the current directory.
333.PP
334The mar\fBk\fR command defines a named mark to refer to a specific place
335in the file.
336This mark may be used later to specify lines for other commands.
337.PP
338The \fBvi\fRsual command puts the editor into visual mode.
339Instead of emulating ex, \*E will start emulating vi.
340.PP
341The \fBve\fRrsion command tells you that what version of \*E this is.
342.PP
343The \fB=\fR command tells you what line you specified, or,
344if you specified a range of lines, it will tell you both endpoints and
345the number of lines included in the range.
346.PP
347The \fBf\fRile command tells you the name of the file,
348whether it has been modified,
349the number of lines in the file,
350and the current line number.
351You can also use it to change the name of the current file.
352.PP
353The \fBso\fRurce command reads a sequence of colon mode commands from a file,
354and interprets them.
355.PP
356The \fB@\fR command executes the contents of a cut-buffer as EX commands.
357.PP
358The \fBcol\fRor command only works under MS-DOS, or if you have an ANSI-compatible
359color terminal.
360It allows you to set the foreground and background colors
361for different types of text:
362normal, bold, italic, underlined, standout, pop-up menu, and visible selection.
363By default, it changes the "normal" colors;
364to change other colors, the first argument to the :color command should be
365the first letter of the type of text you want.
366The syntax for the colors themselves is fairly intuitive.
367For example, ":color light cyan on blue" causes normal text to be displayed
368in light cyan on a blue background, and
369":color b bright white" causes bold text to be displayed in bright white on
370a blue background.
371The background color always defaults to the current background color of
372normal text.
373Your first :color command \fImust\fP specify both the foreground and background
374for normal text.
375.NH 2
376Multiple File Commands
377.if n .ul 0
378.ID
379.ps
380args [files]
381next[!] [files]
382Next[!]
383previous[!]
384rewind[!]
385.DE
386.PP
387When you invoke \*E from your shell's command line,
388any filenames that you give to \*E as arguments are stored in the args list.
389The \fBar\fRgs command will display this list, or define a new one.
390.PP
391The \fBn\fRext command switches from the current file to the next one
392in the args list.
393You may specify a new args list here, too.
394.PP
395The \fBN\fRext and \fBpre\fRvious commands
396(they're really aliases for the same command)
397switch from the current file to the preceding file in the args list.
398.PP
399The \fBrew\fRind command switches from the current file to the first file
400in the args list.
401.NH 2
402Switching Files
403.if n .ul 0
404.ID
405.ps
406edit[!] [file]
407tag[!] tagname
408.DE
409.PP
410The \fBe\fRdit command allows to switch from the current file to some other file.
411This has nothing to do with the args list, by the way.
412.PP
413The \fBta\fRg command looks up a given tagname in a file called "tags".
414This tells it which file the tag is in, and how to find it in that file.
415\*E then switches to the tag's file and finds the tag.
416.NH 2
417Working with a Compiler
418.if n .ul 0
419.ID
420.ps
421cc [files]
422make [target]
423errlist[!] [errlist]
424.DE
425.PP
426The \fBcc\fR and \fBmak\fRe commands execute your compiler or "make" utility
427and redirect any error messages into a file called "errlist".
428By default, cc is run on the current file.
429(You should write it before running cc.)
430The contents of the "errlist" file are then scanned for error messages.
431If an error message is found, then the cursor is moved to the line where
432the error was detected,
433and the description of the error is displayed on the status line.
434.PP
435After you've fixed one error, the \fBer\fRrlist command will move
436the cursor to the next error.
437In visual command mode,
438hitting `*' will do this, too.
439.PP
440You can also create an "errlist" file from outside of \*E,
441and use "\*E -m" to start elvis and have the cursor moved to the
442first error.
443Note that you don't need to supply a filename with "\*E -m" because
444the error messages always say which source file an error is in.
445.PP
446Note:
447When you use errlist repeatedly to fix several errors in a single file,
448it will attempt to adjust the reported line numbers to allow for lines
449that you have inserted or deleted.
450These adjustments are made with the assumption that you will work though
451the file from the beginning to the end.
452.NH 2
453Exit Commands
454.if n .ul 0
455.ID
456.ps
457quit[!]
458wq
459xit
460.DE
461.PP
462The \fBq\fRuit command exits from the editor without saving your file.
463.PP
464The \fBwq\fR command writes your file out, then then exits.
465.PP
466The \fBx\fRit command is similar to the \fBwq\fR command, except that
467\fBx\fRit won't bother to write your file if you haven't modified it.
468.NH 2
469File I/O Commands
470.if n .ul 0
471.ID
472.ps
473[line] read file
474[line][,line] write[!] [[>>]file]
475.DE
476.PP
477The \fBr\fRead command gets text from another file and inserts it
478after the specified line.
479It can also read the output of a program;
480simply precede the program name by a '!' and use it in place of the file name.
481.PP
482The \fBw\fRrite command writes the whole file, or just part of it,
483to some other file.
484The !, if present, will permit the lines to be written even if you've set
485the readonly option.
486If you precede the filename by >> then the lines will be appended to the file.
487You can send the lines to the standard input of a program by replacing the
488filename with a '!' followed by the command and its arguments.
489.PP
490Note: Be careful not to confuse ":w!filename" and ":w !command".
491To write to a program, you must have at least one blank before the '!'.
492.NH 2
493Directory Commands
494.if n .ul 0
495.ID
496.ps
497cd [directory]
498chdir [directory]
499shell
500.DE
501.PP
502The \fBcd\fR and \fBchd\fRir commands
503(really two names for one command)
504switch the current working directory.
505.PP
506The \fBsh\fRell command starts an interactive shell.
507.NH 2
508Debugging Commands
509.if n .ul 0
510.ID
511.ps
512[line][,line] debug[!]
513validate[!]
514.DE
515.PP
516These commands are only available if you compile \*E with the -DDEBUG flag.
517.PP
518The de\fBb\fRug command lists statistics for the blocks which contain
519the specified range of lines.
520If the ! is present, then the contents of those blocks is displayed, too.
521.PP
522The \fBva\fRlidate command checks certain variables for internal consistency.
523Normally it doesn't output anything unless it detects a problem.
524With the !, though, it will always produce *some* output.