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