BSD 2 development
[unix-history] / doc / ex / ex.summary
CommitLineData
cc7bb264
BJ
1.ds p \v'-0.2'.\v'+0.2'
2.ds U \s-2UNIX\s+2
3.ds c \v'-0.2':\v'+0.2'
4.nr PO .25i
5.nr LL 6.75i
6.lt 6.75i
7.ll 6.75i
8.ds CH
9.ds LF Computing Services, U.C. Berkeley
10.ds RF April 3, 1979
11.de SP
12.sp 1v
13..
14.nr PI 3n
15.nr PD 0
16.ND
17.ps 12
18.ft B
19.ce 1
20Ex/Edit Command Summary (Version 2.0)
21.ft R
22.nr VS 11
23.nr PS 9
24.nr HM 0.5i
25.nr CW
26.2C
27.PP
28.I Ex
29and
30.I edit
31are text editors, used for creating
32and modifying files of text on the \*U
33computer system.
34.I Edit
35is a variant of
36.I ex
37with features designed to
38make it less complicated
39to learn and use.
40In terms of command syntax and effect
41the editors are essentially identical,
42and this command summary applies to both.
43.PP
44The summary is meant as a quick reference
45for users already acquainted
46with
47.I edit
48or \fIex\fP.
49Fuller explanations of the editors are available
50in the documents
51.I
52Edit: A Tutorial
53.R
54(a self-teaching introduction) and the
55.I
56Ex Reference Manual
57.R
58(the comprehensive reference source for
59both \fIedit\fP and \fIex\fP).
60Both of these writeups are available in the
61Computing Services Library.
62.PP
63In the examples included with the
64summary, commands and text entered by
65the user are printed in \fBboldface\fR to
66distinguish them from responses printed
67by the computer.
68.sp 0.45v
69.LP
70.B
71The Editor Buffer
72.PP
73In order to perform its tasks
74the editor sets aside a temporary
75work space,
76called a \fIbuffer\fR,
77separate from the user's permanent
78file.
79Before starting to work on an existing
80file the editor makes a copy of it in the
81buffer, leaving the original untouched.
82All editing changes are made to the
83buffer copy, which must then
84be written back to the permanent
85file in order to update the
86old version.
87The buffer disappears
88at the end of the editing session.
89.sp 0.45v
90.LP
91.B
92Editing: Command and Text Input Modes
93.PP
94.R
95During an editing session there are
96two usual modes of operation:
97\fIcommand\fP mode and \fItext input\fP
98mode.
99(This disregards, for the moment,
100.I open
101and
102.I visual
103modes, discussed below.)
104In command mode, the editor issues a
105colon prompt (:)
106to show that it is ready to
107accept and execute a command.
108In text input mode, on the other hand, there is
109no prompt and the editor merely accepts text to
110be added to the buffer.
111Text input mode is initiated by the commands
112\fIappend\fP, \fIinsert\fP, and \fIchange\fP,
113and is terminated by typing a period as the
114first and only character on a line.
115.sp 0.45v
116.LP
117.B
118Line Numbers and Command Syntax
119.PP
120.R
121The editor keeps track of lines of text
122in the buffer by numbering them consecutively
123starting with 1 and renumbering
124as lines are added or deleted.
125At any given time the editor is positioned
126at one of these lines; this position is
127called the \fIcurrent line\fP.
128Generally, commands that change the
129contents of the buffer print the
130new current line at the end of their
131execution.
132.PP
133Most commands can be preceded by one or two
134line-number addresses which indicate the lines
135to be affected.
136If one number is given the command operates on
137that line only; if two, on an inclusive range
138of lines.
139Commands that can take line-number prefixes also
140assume default prefixes if none are given.
141The default assumed by each command is designed
142to make it convenient to use in many instances
143without any line-number prefix.
144For the most part, a command used without a
145prefix operates on the current line,
146though exceptions to this rule should be noted.
147The \fIprint\fP command
148by itself, for instance, causes
149one line, the current line, to be
150printed at the terminal.
151.PP
152The summary shows the number of line addresses
153that can be
154prefixed to each command as well as
155the defaults assumed if they are omitted.
156For example,
157.I (.,.)
158means that up to 2 line-numbers may be given,
159and that if none is given the
160command operates on the current line.
161(In the address prefix notation, ``.'' stands
162for the current line and ``$'' stands for
163the last line of the buffer.)
164If no such notation appears, no
165line-number prefix may be used.
166.PP
167Some commands take trailing
168information;
169only
170the more important instances of this
171are mentioned in the summary.
172.sp 0.25v
173.LP
174.B
175Open and Visual Modes
176.PP
177.R
178Besides command and text input modes,
179.I ex
180and
181.I edit
182provide on some CRT terminals other modes of editing,
183.I open
184and
185.I visual .
186In these modes the cursor can
187be moved to individual words
188or characters in a line.
189The commands then given are very different
190from the standard editor commands; most do not appear on the screen when
191typed.
192.I
193An Introduction to Display Editing with Vi
194.R
195provides a full discussion.
196.sp 0.25v
197.LP
198.B
199Special Characters
200.PP
201.R
202.fi
203Some characters take on special meanings
204when used in context searches
205and in patterns given to the \fIsubstitute\fP command.
206For \fIedit\fR, these are ``^'' and ``$'',
207meaning the beginning and end of a line,
208respectively.
209.I Ex
210has the following additional special characters:
211.B
212.ce 1
213\&. & * [ ] ~
214.R
215To use one of the special characters as its
216simple graphic representation
217rather than with its special meaning,
218precede it by a backslash (\\).
219The backslash always has a special meaning.
220.1C
221.rm LF
222.rm RF
223.rm CF
224.nr FM 0.4
225.TS
226cp10 cp10 cp10 cp10
227ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
228Name Abbr Description Examples
229.sp 1.75
230(.)\fBappend a T{
231Begins text input mode,
232adding lines to the buffer after
233the line specified. Appending continues
234until ``.'' is typed alone at the
235beginning of a new line, followed by
236a carriage return. \fI0a\fR places
237lines at the beginning of the buffer.
238T} T{
239.nf
240\fR:\fBa
241Three lines of text
242are added to the buffer
243after the current line.
244\*p
245.R
246\*c
247.fi
248T}
249.SP
250\fR(.,.)\fBchange c T{
251Deletes indicated line(s) and
252initiates text input mode to
253replace them with new text which follows.
254New text is terminated the same way
255as with \fIappend\fR.
256T} T{
257.nf
258:\fB5,6c
259Lines 5 and 6 are
260deleted and replaced by
261these three lines.
262\*p
263.R
264\*c
265.fi
266T}
267.SP
268\fR(.,.)\fBcopy \fIaddr co T{
269Places a copy of the specified lines
270after the line indicated by \fIaddr\fR.
271The example places a copy of lines 8 through
27212, inclusive, after line 25.
273T} T{
274.nf
275\fR:\fB8,12co 25
276\fRLast line copied is printed
277\fR\*c
278.fi
279T}
280.SP
281\fR(.,.)\fBdelete d T{
282Removes lines from the buffer
283and prints the current line after the deletion.
284T} T{
285.nf
286\fR:\fB13,15d
287\fRNew current line is printed
288\*c
289.fi
290T}
291.TE
292.sp 0.5v
293.TS
294ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
295T{
296\fBedit \fIfile\fP
297.br
298\fBedit! \fIfile\fP
299T} T{
300e
301.br
302e!
303T} T{
304.fi
305\fRClears the editor buffer and then
306copies into it the named \fIfile\fR,
307which becomes the current file.
308This is a way of shifting to a different
309file
310without leaving the editor.
311The editor issues a warning
312message if this command is used before
313saving changes
314made to the file already in the buffer;
315using the form \fBe!\fR overrides this protective mechanism.
316T} T{
317.nf
318\fR:\fBe ch10\fR
319No write since last change
320:\fBe! ch10\fR
321"ch10" 3 lines, 62 characters
322\*c
323.fi
324T}
325.SP
326\fBfile \fIname\fR f T{
327\fRIf followed by a \fIname\fR, renames
328the current file to \fIname\fR.
329If used without \fIname\fR, prints
330the name of the current file.
331T} T{
332.nf
333\fR:\fBf ch9
334\fR"ch9" [Modified] 3 lines ...
335:\fBf
336\fR"ch9" [Modified] 3 lines ...
337\*c
338.fi
339T}
340.SP
341(1,$)\fBglobal g \fBglobal/\fIpattern\fB/\fIcommands T{
342.nf
343:\fBg/nonsense/d
344\fR\*c
345.fi
346T}
347\fR(1,$)\fBglobal! g!\fR or \fBv T{
348Searches the entire buffer (unless a smaller
349range is specified by line-number prefixes) and
350executes \fIcommands\fR on every line with
351an expression matching \fIpattern\fR.
352The second form, abbreviated
353either \fBg!\fR or \fBv\fR,
354executes \fIcommands\fR on lines that \fIdo
355not\fR contain the expression \fIpattern\fR.
356T} \^
357.SP
358\fR(.)\fBinsert i T{
359Inserts new lines of text immediately before the speciffied line.
360Differs from
361.I append
362only in that text is placed before, rather than after, the indicated lne.
363In other words, \fB1i\fR has the same effect as \fB0a\fR.
364T} T{
365.nf
366:\fB1i
367These lines of text will
368be added prior to line 1.
369\&.
370\fR:
371.fi
372T} \^
373.SP
374\fR(.,.+1)\fBjoin j T{
375Join lines together, adjusting white space (spaces
376and tabs) as necessary.
377T} T{
378.nf
379:\fB2,5j\fR
380Resulting line is printed
381:
382.fi
383T} \^
384.TE
385.bp
386.TS
387cp10 cp10 cp10 cp10
388ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
389Name Abbr Description Examples
390.sp 1.75
391\fR(.,.)\fBlist l T{
392\fRPrints lines in a more
393unambiguous way than the \fIprint\fR
394command does. The end of a line,
395for example, is marked with a ``$'',
396and tabs printed as ``^I''.
397T} T{
398.nf
399:\fB9l
400\fRThis is line 9$
401\*c
402.fi
403T}
404.TE
405.sp 0.5v
406.TS
407ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
408\fR(.,.)\fBmove \fIaddr\fB m T{
409\fRMoves the specified lines
410to a position after the line
411indicated by \fIaddr\fR.
412T} T{
413.nf
414\fR:\fB12,15m 25\fR
415New current line is printed
416\*c
417.fi
418T}
419.SP
420\fR(.,.)\fBnumber nu T{
421Prints each line preceded
422by its buffer line number.
423T} T{
424.nf
425\fR:\fBnu
426\0\0\fR10\0 This is line 10
427\*c
428.fi
429T}
430.SP
431\fR(.)\fBopen o T{
432Too involved to discuss here,
433but if you enter open mode
434accidentally, press
435the \s-2ESC\s0 key followed by
436\fBq\fR to
437get back into normal editor
438command mode.
439\fIEdit\fP is designed to
440prevent accidental use of
441the open command.
442T}
443.SP
444\fBpreserve pre T{
445Saves a copy of the current buffer contents as though the system had
446just crashed. This is for use in an emergency when a
447.I write
448command has failed and you don't know how else to save your work.\(dg
449T} T{
450.nf
451:\fBpreserve\fR
452File preserved.
453:
454.fi
455T}
456.SP
457\fR(.,.)\fBprint p Prints the text of line(s). T{
458.nf
459:\fB+2,+3p\fR
460The second and third lnes
461after the current line
462:
463.fi
464T}
465.TE
466.FS
467\(dg Seek assistance from a consultant as soon as possible
468after saving a file with the
469.I preserve
470command, because the file is saved on system storage space for only one week.
471.FE
472.SP
473.nf
474.TS
475ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
476T{
477.nf
478\fBquit
479quit!
480.fi
481T} T{
482.nf
483q
484q!
485T} T{
486.fi
487\fREnds the editing session.
488You will receive a
489warning if you have changed the buffer
490since last writing its contents
491to the file. In this event you
492must either type \fBw\fR to write,
493or type \fBq!\fR to exit from
494the editor without saving your changes.
495T} T{
496.nf
497\fR:\fBq
498\fRNo write since last change
499:\fBq!
500\fR%
501.fi
502T}
503.SP
504\fR(.)\fBread \fIfile\fP r T{
505.fi
506\fRPlaces a copy of \fIfile\fR in the
507buffer after the specified line.
508Address 0 is permissible and causes
509the copy of \fIfile\fR to be placed
510at the beginning of the buffer.
511The \fIread\fP command does not
512erase any text already in the buffer.
513If no line number is specified,
514\fIfile\fR is placed after the
515current line.
516T} T{
517.nf
518\fR:\fB0r newfile
519\fR"newfile" 5 lines, 86 characters
520\*c
521.fi
522T}
523.SP
524\fBrecover \fIfile\fP rec T{
525.fi
526Retrieves a copy of the editor buffer
527after a system crash, editor crash,
528phone line disconnection, or
529\fIpreserve\fR command.
530T}
531.SP
532\fR(.,.)\fBsubstitute s T{
533.nf
534\fBsubstitute/\fIpattern\fB/\fIreplacement\fB/
535substitute/\fIpattern\fB/\fIreplacement\fB/gc
536.fi
537\fRReplaces the first ocurrence of \fIpattern\fR
538on a line
539with \fIreplacement\fP.
540Including a \fBg\fR after the command
541changes all occurrences of \fIpattern\fP
542on the line.
543The \fBc\fR option allows the user to
544confirm each substitution before it is
545made; see the manual for details.
546T} T{
547.nf
548:\fB3p
549\fRLine 3 contains a misstake
550:\fBs/misstake/mistake/
551\fRLine 3 contains a mistake
552\*c
553.fi
554T}
555.TE
556.bp
557.TS
558cp10 cp10 cp10 cp10
559ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
560Name Abbr Description Examples
561.sp 1.75
562\fBundo u T{
563.fi
564\fRReverses the changes made in
565the buffer by the last buffer-editing
566command.
567Note that this example contains
568a notification about the number of
569lines affected.
570T} T{
571.nf
572\fR:\fB1,15d
573\fR15 lines deleted
574new line number 1 is printed
575:\fBu
576\fR15 more lines in file ...
577old line number 1 is printed
578\*c
579.fi
580T}
581.SP
582\fR(1,$)\fBwrite \fIfile\fR w T{
583.fi
584\fRCopies data from the buffer onto
585a permanent file. If no \fIfile\fR
586is named, the current filename
587is used.
588The file is automatically created
589if it does not yet exist.
590A response containing the number of
591lines and characters in the file
592indicates that the write
593has been completed successfully.
594The editor's built-in protections
595against overwriting existing files
596will in some circumstances
597inhibit a write.
598The form \fBw!\fR forces the
599write, confirming that
600an existing file is to be overwritten.
601T} T{
602.nf
603\fR:\fBw
604\fR"file7" 64 lines, 1122 characters
605:\fBw file8
606\fR"file8" File exists ...
607:\fBw! file8
608\fR"file8" 64 lines, 1122 characters
609\*c
610.fi
611T}
612\fR(1,$)\fBwrite! \fIfile\fP w! \^ \^
613.TE
614.sp 0.5v
615.TS
616ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
617\fR(.)\fBz \fIcount\fP z T{
618.fi
619\fRPrints a screen full of text starting
620with the line indicated;
621or, if \fIcount\fR is specified,
622prints that number of lines.
623Variants of the \fIz\fR command
624are described in the manual.
625T}
626.SP
627\fB!\fIcommand T{
628.fi
629Executes the remainder of the line
630after \fB!\fR as a \*U command.
631The buffer is unchanged by this, and
632control is returned to the editor when
633the execution of \fIcommand\fR is complete.
634T} T{
635.nf
636\fR:\fB!date
637\fRFri Jun 9 12:15:11 PDT 1978
638!
639\*c
640.fi
641T}
642.SP
643\fRcontrol-d T{
644.fi
645Prints the next \fIscroll\fR of text,
646normally half of a screen. See the
647manual for details of the \fIscroll\fR
648option.
649T}
650.SP
651\fR(.+1)<cr> T{
652.fi
653An address alone followed by a carriage
654return causes the line to be printed.
655A carriage return by itself prints the
656line following the current line.
657T} T{
658.nf
659:\fR<cr>
660the line after the current line
661\*c
662.fi
663T}
664.TE
665.sp 0.5v
666.TS
667ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
668\fB/\fIpattern\fB/ T{
669.fi
670\fRSearches for the next line in which
671\fIpattern\fR occurs and prints it.
672T} T{
673.nf
674\fR:\fB/This pattern/
675\fRThis pattern next occurs here.
676\*c
677.fi
678T}
679.SP
680\fB// T{
681Repeats the most recent search.
682T} T{
683.nf
684\fR:\fB//
685\fRThis pattern also occurs here.
686\*c
687.fi
688T}
689.SP
690\fB?\fIpattern\fB? T{
691Searches in the reverse direction
692for \fIpattern\fP.
693T}
694.SP
695\fB?? T{
696Repeats the most recent search,
697moving in the reverse direction
698through the buffer.
699T}
700.TE
701