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