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