]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/usd/10.exref/exref/ex.rm
Upgrade Unbound to 1.6.4. More to follow.
[FreeBSD/FreeBSD.git] / share / doc / usd / 10.exref / exref / ex.rm
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. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)ex.rm       8.5 (Berkeley) 8/18/96
33 .\" $FreeBSD$
34 .\"
35 .nr LL 6.5i
36 .nr FL 6.5i
37 .EH 'USD:12-%''Ex Reference Manual'
38 .OH 'Ex Reference Manual''USD:12-%'
39 .ND
40 .nr )P 0
41 .de ZP
42 .nr pd \\n()P
43 .nr )P 0
44 .if \\n(.$=0 .IP
45 .if \\n(.$=1 .IP "\\$1"
46 .if \\n(.$>=2 .IP "\\$1" "\\$2"
47 .nr )P \\n(pd
48 .rm pd
49 ..
50 .de LC
51 .br
52 .sp .1i
53 .ne 4
54 .LP
55 .ta 4.0i
56 ..
57 .bd S B 3
58 .\".RP
59 .TL
60 Ex Reference Manual
61 .br
62 Version 3.7
63 .AU
64 William Joy
65 .AU
66 Mark Horton
67 .AI
68 Computer Science Division
69 Department of Electrical Engineering and Computer Science
70 University of California, Berkeley
71 Berkeley, Ca.  94720
72 .AB
73 .I Ex
74 a line oriented text editor, which supports both command and display
75 oriented editing.
76 This reference manual describes the command oriented part of
77 .I ex;
78 the display editing features of
79 .I ex
80 are described in
81 .I "An Introduction to Display Editing with Vi."
82 Other documents about the editor include the introduction
83 .I "Edit: A tutorial",
84 the
85 .I "Ex/edit Command Summary",
86 and a
87 .I "Vi Quick Reference"
88 card.
89 .AE
90 .NH 1
91 Starting ex
92 .PP
93 .FS
94 The financial support of an \s-2IBM\s0 Graduate Fellowship and the National
95 Science Foundation under grants MCS74-07644-A03 and MCS78-07291 is gratefully
96 acknowledged.
97 .FE
98 Each instance of the editor has a set of options,
99 which can be set to tailor it to your liking.
100 The command
101 .I edit
102 invokes a version of
103 .I ex
104 designed for more casual or beginning
105 users by changing the default settings of some of these options.
106 To simplify the description which follows we
107 assume the default settings of the options.
108 .PP
109 When invoked,
110 .I ex
111 determines the terminal type from the \s-2TERM\s0 variable in the environment.
112 It there is a \s-2TERMCAP\s0 variable in the environment, and the type
113 of the terminal described there matches the \s-2TERM\s0 variable,
114 then that description
115 is used.  Also if the \s-2TERMCAP\s0 variable contains a pathname (beginning
116 with a \fB/\fR) then the editor will seek the description of the terminal
117 in that file (rather than the default /etc/termcap).
118 If there is a variable \s-2EXINIT\s0 in the environment, then the editor
119 will execute the commands in that variable,
120 otherwise if there is a file
121 .I \&.exrc
122 in your \s-2HOME\s0 directory
123 .I ex
124 reads commands from that file, simulating a
125 .I source
126 command.
127 Option setting commands placed in
128 \s-2EXINIT\s0 or
129 .I \&.exrc
130 will be executed before each editor session.
131 .PP
132 A command to enter
133 .I ex
134 has the following prototype:\(dg
135 .FS
136 \(dg Brackets `[' `]' surround optional parameters here.
137 .FE
138 .DS
139 \fBex\fP [ \fB\-\fP ] [ \fB\-v\fP ] [ \fB\-t\fP \fItag\fP ] [ \fB\-r\fP ] [ \fB\-l\fP ] [ \fB\-w\fP\fIn\fP ] [ \fB\-x\fP ] [ \fB\-R\fP ] [ \fB+\fP\fIcommand\fP ] name ...
140 .DE
141 The most common case edits a single file with no options, i.e.:
142 .DS
143 \fBex\fR name
144 .DE
145 The
146 .B \-
147 command line option
148 option suppresses all interactive-user feedback
149 and is useful in processing editor scripts in command files.
150 The
151 .B \-v
152 option is equivalent to using
153 .I vi
154 rather than
155 .I ex.
156 The
157 .B \-t
158 option is equivalent to an initial
159 .I tag
160 command, editing the file containing the
161 .I tag
162 and positioning the editor at its definition.
163 The
164 .B \-r
165 option is used in recovering after an editor or system crash,
166 retrieving the last saved version of the named file or,
167 if no file is specified,
168 typing a list of saved files.
169 The
170 .B \-l
171 option sets up for editing \s-2LISP\s0, setting the
172 .I showmatch
173 and
174 .I lisp
175 options.
176 The
177 .B \-w
178 option sets the default window size to
179 .I n,
180 and is useful on dialups to start in small windows.
181 The
182 .B \-x
183 option causes
184 .I ex
185 to prompt for a
186 .I key ,
187 which is used to encrypt and decrypt the contents of the file,
188 which should already be encrypted using the same key,
189 see
190 .I crypt (1).
191 The
192 .B \-R
193 option sets the
194 .I readonly
195 option at the start.
196 .I Name
197 arguments indicate files to be edited.
198 An argument of the form
199 \fB+\fIcommand\fR
200 indicates that the editor should begin by executing the specified command.
201 If
202 .I command
203 is omitted, then it defaults to ``$'', positioning the editor at the last
204 line of the first file initially.  Other useful commands here are scanning
205 patterns of the form ``/pat'' or line numbers, e.g. ``+100'' starting
206 at line 100.
207 .NH 1
208 File manipulation
209 .NH 2
210 Current file
211 .PP
212 .I Ex
213 is normally editing the contents of a single file,
214 whose name is recorded in the
215 .I current
216 file name.
217 .I Ex
218 performs all editing actions in a buffer
219 (actually a temporary file)
220 into which the text of the file is initially read.
221 Changes made to the buffer have no effect on the file being
222 edited unless and until the buffer contents are written out to the
223 file with a
224 .I write
225 command.
226 After the buffer contents are written,
227 the previous contents of the written file are no longer accessible.
228 When a file is edited,
229 its name becomes the current file name,
230 and its contents are read into the buffer.
231 .PP
232 The current file is almost always considered to be
233 .I edited.
234 This means that the contents of the buffer are logically
235 connected with the current file name,
236 so that writing the current buffer contents onto that file,
237 even if it exists,
238 is a reasonable action.
239 If the current file is not 
240 .I edited
241 then
242 .I ex
243 will not normally write on it if it already exists.*
244 .FS
245 * The
246 .I file
247 command will say ``[Not edited]'' if the current file is not considered
248 edited.
249 .FE
250 .NH 2
251 Alternate file
252 .PP
253 Each time a new value is given to the current file name,
254 the previous current file name is saved as the
255 .I alternate
256 file name.
257 Similarly if a file is mentioned but does not become the current file,
258 it is saved as the alternate file name.
259 .NH 2
260 Filename expansion
261 .PP
262 Filenames within the editor may be specified using the normal
263 shell expansion conventions.
264 In addition,
265 the character `%' in filenames is replaced by the
266 .I current
267 file name and the character
268 `#' by the
269 .I alternate
270 file name.\(dg
271 .FS
272 \(dg This makes it easy to deal alternately with
273 two files and eliminates the need for retyping the
274 name supplied on an
275 .I edit
276 command after a 
277 .I "No write since last change"
278 diagnostic is received.
279 .FE
280 .NH 2
281 Multiple files and named buffers
282 .PP
283 If more than one file is given on the command line,
284 then the first file is edited as described above.
285 The remaining arguments are placed with the first file in the
286 .I "argument list."
287 The current argument list may be displayed with the
288 .I args
289 command.
290 The next file in the argument list may be edited with the
291 .I next
292 command.
293 The argument list may also be respecified by specifying
294 a list of names to the
295 .I next
296 command.
297 These names are expanded,
298 the resulting list of names becomes the new argument list,
299 and
300 .I ex
301 edits the first file on the list.
302 .PP
303 For saving blocks of text while editing, and especially when editing
304 more than one file,
305 .I ex
306 has a group of named buffers.
307 These are similar to the normal buffer, except that only a limited number
308 of operations are available on them.
309 The buffers have names
310 .I a
311 through
312 .I z.\(dd
313 .FS
314 \(dd It is also possible to refer to
315 .I A
316 through
317 .I Z;
318 the upper case buffers are the same as the lower but commands
319 append to named buffers rather than replacing
320 if upper case names are used.
321 .FE
322 .NH 2
323 Read only
324 .PP
325 It is possible to use
326 .I ex
327 in
328 .I "read only"
329 mode to look at files that you have no intention of modifying.
330 This mode protects you from accidently overwriting the file.
331 Read only mode is on when the
332 .I readonly
333 option is set.
334 It can be turned on with the
335 .B \-R
336 command line option,
337 by the
338 .I view
339 command line invocation,
340 or by setting the
341 .I readonly
342 option.
343 It can be cleared by setting
344 .I noreadonly .
345 It is possible to write, even while in read only mode, by indicating
346 that you really know what you are doing.
347 You can write to a different file, or can use the ! form of write,
348 even while in read only mode.
349 .NH 1
350 Exceptional Conditions
351 .NH 2
352 Errors and interrupts
353 .PP
354 When errors occur
355 .I ex
356 (optionally) rings the terminal bell and, in any case, prints an error
357 diagnostic.  If the primary input is from a file, editor processing
358 will terminate.  If an interrupt signal is received,
359 .I ex
360 prints ``Interrupt'' and returns to its command level.  If the primary
361 input is a file, then
362 .I ex
363 will exit when this occurs.
364 .NH 2
365 Recovering from hangups and crashes
366 .PP
367 If a hangup signal is received and the buffer has been modified since
368 it was last written out, or if the system crashes, either the editor
369 (in the first case) or the system (after it reboots in the second) will
370 attempt to preserve the buffer.  The next time you log in you should be
371 able to recover the work you were doing, losing at most a few lines of
372 changes from the last point before the hangup or editor crash.  To
373 recover a file you can use the
374 .B \-r
375 option.  If you were editing the file
376 .I resume,
377 then you should change
378 to the directory where you were when the crash occurred, giving the command
379 .DS
380 \fBex \-r\fP\fI resume\fP
381 .DE
382 After checking that the retrieved file is indeed ok, you can
383 .I write
384 it over the previous contents of that file.
385 .PP
386 You will normally get mail from the system telling you when a file has
387 been saved after a crash.  The command
388 .DS
389 \fBex\fP \-\fBr\fP
390 .DE
391 will print a list of the files which have been saved for you.
392 (In the case of a hangup,
393 the file will not appear in the list,
394 although it can be recovered.)
395 .NH 1
396 Editing modes
397 .PP
398 .I Ex
399 has five distinct modes.  The primary mode is
400 .I command
401 mode.  Commands are entered in command mode when a `:' prompt is
402 present, and are executed each time a complete line is sent.  In
403 .I "text input"
404 mode
405 .I ex
406 gathers input lines and places them in the file.  The
407 .I append,
408 .I insert,
409 and
410 .I change
411 commands use text input mode.
412 No prompt is printed when you are in text input mode.
413 This mode is left by typing a `.' alone at the beginning of a line, and
414 .I command
415 mode resumes.
416 .PP
417 The last three modes are
418 .I open
419 and
420 .I visual
421 modes, entered by the commands of the same name, and, within open and
422 visual modes
423 .I "text insertion"
424 mode.
425 .I Open
426 and
427 .I visual
428 modes allow local editing operations to be performed on the text in the
429 file.  The
430 .I open
431 command displays one line at a time on any terminal while
432 .I visual
433 works on \s-2CRT\s0 terminals with random positioning cursors, using the
434 screen as a (single) window for file editing changes.
435 These modes are described (only) in
436 .I "An Introduction to Display Editing with Vi."
437 .NH 
438 Command structure
439 .PP
440 Most command names are English words,
441 and initial prefixes of the words are acceptable abbreviations.
442 The ambiguity of abbreviations is resolved in favor of the more commonly
443 used commands.*
444 .FS
445 * As an example, the command 
446 .I substitute
447 can be abbreviated `s'
448 while the shortest available abbreviation for the 
449 .I set
450 command is `se'.
451 .FE
452 .NH 2
453 Command parameters
454 .PP
455 Most commands accept prefix addresses specifying the lines in the file
456 upon which they are to have effect.
457 The forms of these addresses will be discussed below.
458 A number of commands also may take a trailing
459 .I count
460 specifying the number of lines to be involved in the command.\(dg
461 .FS
462 \(dg Counts are rounded down if necessary.
463 .FE
464 Thus the command ``10p'' will print the tenth line in the buffer while
465 ``delete 5'' will delete five lines from the buffer,
466 starting with the current line.
467 .PP
468 Some commands take other information or parameters,
469 this information always being given after the command name.\(dd
470 .FS
471 \(dd Examples would be option names in a
472 .I set
473 command i.e. ``set number'',
474 a file name in an
475 .I edit
476 command,
477 a regular expression in a
478 .I substitute
479 command,
480 or a target address for a
481 .I copy
482 command, i.e. ``1,5 copy 25''.
483 .FE
484 .NH 2
485 Command variants
486 .PP
487 A number of commands have two distinct variants.
488 The variant form of the command is invoked by placing an
489 `!' immediately after the command name.
490 Some of the default variants may be controlled by options;
491 in this case, the `!' serves to toggle the default.
492 .NH 2
493 Flags after commands
494 .PP
495 The characters `#', `p' and `l' may be placed after many commands.**
496 .FS
497 **
498 A `p' or `l' must be preceded by a blank or tab
499 except in the single special case `dp'.
500 .FE
501 In this case, the command abbreviated by these characters
502 is executed after the command completes.
503 Since
504 .I ex
505 normally prints the new current line after each change, `p' is rarely necessary.
506 Any number of `+' or `\-' characters may also be given with these flags.
507 If they appear, the specified offset is applied to the current line
508 value before the printing command is executed.
509 .NH 2
510 Comments
511 .PP
512 It is possible to give editor commands which are ignored.
513 This is useful when making complex editor scripts
514 for which comments are desired.
515 The comment character is the double quote: ".
516 Any command line beginning with " is ignored.
517 Comments beginning with " may also be placed at the ends
518 of commands, except in cases where they could be confused as part
519 of text (shell escapes and the substitute and map commands).
520 .NH 2
521 Multiple commands per line
522 .PP
523 More than one command may be placed on a line by separating each pair
524 of commands by a `|' character.
525 However the
526 .I global
527 commands,
528 comments,
529 and the shell escape `!'
530 must be the last command on a line, as they are not terminated by a `|'.
531 .NH 2
532 Reporting large changes
533 .PP
534 Most commands which change the contents of the editor buffer give
535 feedback if the scope of the change exceeds a threshold given by the
536 .I report
537 option.
538 This feedback helps to detect undesirably large changes so that they may
539 be quickly and easily reversed with an
540 .I undo.
541 After commands with more global effect such as
542 .I global
543 or
544 .I visual,
545 you will be informed if the net change in the number of lines
546 in the buffer during this command exceeds this threshold.
547 .NH 1
548 Command addressing
549 .NH 2
550 Addressing primitives
551 .IP \fB.\fR 20
552 The current line.
553 Most commands leave the current line as the last line which they affect.
554 The default address for most commands is the current line,
555 thus `\fB.\fR' is rarely used alone as an address.
556 .IP \fIn\fR 20
557 The \fIn\fRth line in the editor's buffer, lines being numbered
558 sequentially from 1.
559 .IP \fB$\fR 20
560 The last line in the buffer.
561 .IP \fB%\fR 20
562 An abbreviation for ``1,$'', the entire buffer.
563 .IP \fI+n\fR\ \fI\-n\fR 20
564 An offset relative to the current buffer line.\(dg
565 .FS
566 \(dg
567 The forms `.+3' `+3' and `+++' are all equivalent;
568 if the current line is line 100 they all address line 103.
569 .FE
570 .IP \fB/\fIpat\fR\fB/\fR\ \fB?\fIpat\fR\fB?\fR 20
571 Scan forward and backward respectively for a line containing \fIpat\fR, a
572 regular expression (as defined below).  The scans normally wrap around the end
573 of the buffer.
574 If all that is desired is to print the next line containing \fIpat\fR, then
575 the trailing \fB/\fR or \fB?\fR may be omitted.
576 If \fIpat\fP is omitted or explicitly empty, then the last
577 regular expression specified is located.\(dd
578 .FS
579 \(dd The forms \fB\e/\fP and \fB\e?\fP scan
580 using the last regular expression used in a scan; after a substitute
581 \fB//\fP and \fB??\fP would scan using the substitute's regular expression.
582 .FE
583 .IP \fB\(aa\(aa\fP\ \fB\(aa\fP\fIx\fP 20
584 Before each non-relative motion of the current line `\fB.\fP',
585 the previous current line is marked with a tag, subsequently referred to as
586 `\(aa\(aa'.
587 This makes it easy to refer or return to this previous context.
588 Marks may also be established by the
589 .I mark
590 command, using single lower case letters
591 .I x
592 and the marked lines referred to as
593 `\(aa\fIx\fR'.
594 .NH 2
595 Combining addressing primitives
596 .PP
597 Addresses to commands consist of a series of addressing primitives,
598 separated by `,' or `;'.
599 Such address lists are evaluated left-to-right.
600 When addresses are separated by `;' the current line `\fB.\fR'
601 is set to the value of the previous addressing expression
602 before the next address is interpreted.
603 If more addresses are given than the command requires,
604 then all but the last one or two are ignored.
605 If the command takes two addresses, the first addressed line must
606 precede the second in the buffer.\(dg
607 .FS
608 \(dg Null address specifications are permitted in a list of addresses,
609 the default in this case is the current line `.';
610 thus `,100' is equivalent to `\fB.\fR,100'.
611 It is an error to give a prefix address to a command which expects none.
612 .FE
613 .NH 1
614 Command descriptions
615 .PP
616 The following form is a prototype for all
617 .I ex
618 commands:
619 .DS
620 \fIaddress\fR \fBcommand\fR \fI! parameters count flags\fR
621 .DE
622 All parts are optional; the degenerate case is the empty command which prints
623 the next line in the file.  For sanity with use from within
624 .I visual
625 mode,
626 .I ex
627 ignores a ``:'' preceding any command.
628 .PP
629 In the following command descriptions, the
630 default addresses are shown in parentheses,
631 which are
632 .I not,
633 however,
634 part of the command.
635 .LC
636 \fBabbreviate\fR \fIword rhs\fP abbr: \fBab\fP
637 .ZP
638 Add the named abbreviation to the current list.
639 When in input mode in visual, if
640 .I word
641 is typed as a complete word, it will be changed to
642 .I rhs .
643 .LC
644 ( \fB.\fR ) \fBappend\fR        abbr: \fBa\fR
645 .br
646 \fItext\fR
647 .br
648 \&\fB.\fR
649 .ZP
650 Reads the input text and places it after the specified line.
651 After the command, `\fB.\fR'
652 addresses the last line input or the
653 specified line if no lines were input.
654 If address `0' is given,
655 text is placed at the beginning of the buffer.
656 .LC
657 \fBa!\fR
658 .br
659 \fItext\fR
660 .br
661 \&\fB.\fR
662 .ZP
663 The variant flag to
664 .I append
665 toggles the setting for the
666 .I autoindent
667 option during the input of
668 .I text.
669 .LC
670 \fBargs\fR
671 .ZP
672 The members of the argument list are printed, with the current argument
673 delimited by `[' and `]'.
674 .ig
675 .PP
676 \fBcd\fR \fIdirectory\fR
677 .ZP
678 The
679 .I cd
680 command is a synonym for
681 .I chdir.
682 ..
683 .LC
684 ( \fB.\fP , \fB.\fP ) \fBchange\fP \fIcount\fP  abbr: \fBc\fP
685 .br
686 \fItext\fP
687 .br
688 \&\fB.\fP
689 .ZP
690 Replaces the specified lines with the input \fItext\fP.
691 The current line becomes the last line input;
692 if no lines were input it is left as for a
693 \fIdelete\fP.
694 .LC
695 \fBc!\fP
696 .br
697 \fItext\fP
698 .br
699 \&\fB.\fP
700 .ZP
701 The variant toggles
702 .I autoindent
703 during the
704 .I change.
705 .ig
706 .LC
707 \fBchdir\fR \fIdirectory\fR
708 .ZP
709 The specified \fIdirectory\fR becomes the current directory.
710 If no directory is specified, the current value of the
711 .I home
712 option is used as the target directory.
713 After a
714 .I chdir
715 the current file is not considered to have been
716 edited so that write restrictions on pre-existing files apply.
717 ..
718 .LC
719 ( \fB.\fP , \fB.\fP )\|\fBcopy\fP \fIaddr\fP \fIflags\fP        abbr: \fBco\fP
720 .ZP
721 A
722 .I copy
723 of the specified lines is placed after
724 .I addr,
725 which may be `0'.
726 The current line
727 `\fB.\fR'
728 addresses the last line of the copy.
729 The command
730 .I t
731 is a synonym for
732 .I copy.
733 .LC
734 ( \fB.\fR , \fB.\fR )\|\fBdelete\fR \fIbuffer\fR \fIcount\fR \fIflags\fR        abbr: \fBd\fR
735 .ZP
736 Removes the specified lines from the buffer.
737 The line after the last line deleted becomes the current line;
738 if the lines deleted were originally at the end,
739 the new last line becomes the current line.
740 If a named
741 .I buffer
742 is specified by giving a letter,
743 then the specified lines are saved in that buffer,
744 or appended to it if an upper case letter is used.
745 .LC
746 \fBedit\fR \fIfile\fR   abbr: \fBe\fR
747 .br
748 \fBex\fR \fIfile\fR
749 .ZP
750 Used to begin an editing session on a new file.
751 The editor
752 first checks to see if the buffer has been modified since the last
753 .I write
754 command was issued.
755 If it has been,
756 a warning is issued and the
757 command is aborted.
758 The
759 command otherwise deletes the entire contents of the editor buffer,
760 makes the named file the current file and prints the new filename.
761 After insuring that this file is sensible\(dg
762 .FS
763 \(dg I.e., that it is not a binary file such as a directory,
764 a block or character special file other than
765 .I /dev/tty,
766 a terminal,
767 or a binary or executable file
768 (as indicated by the first word).
769 .FE
770 the editor reads the file into its buffer.
771 .IP
772 If the read of the file completes without error,
773 the number of lines and characters read is typed.
774 If there were any non-\s-2ASCII\s0 characters
775 in the file they are stripped of their non-\s-2ASCII\s0
776 high bits,
777 and any null characters in the file are discarded.
778 If none of these errors occurred, the file is considered
779 .I edited.
780 If the last line of the input file is missing the trailing
781 newline character, it will be supplied and a complaint will be issued.
782 This command leaves the current line `\fB.\fR' at the last line read.\(dd
783 .FS
784 \(dd If executed from within
785 .I open
786 or
787 .I visual,
788 the current line is initially the first line of the file.
789 .FE
790 .LC
791 \fBe!\fR \fIfile\fR
792 .ZP
793 The variant form suppresses the complaint about modifications having
794 been made and not written from the editor buffer, thus
795 discarding all changes which have been made before editing the new file.
796 .LC
797 \fBe\fR \fB+\fIn\fR \fIfile\fR
798 .ZP
799 Causes the editor to begin at line
800 .I n
801 rather than at the last line;
802 \fIn\fR may also be an editor command containing no spaces, e.g.: ``+/pat''.
803 .LC
804 \fBfile\fR      abbr: \fBf\fR
805 .ZP
806 Prints the current file name,
807 whether it has been `[Modified]' since the last
808 .I write 
809 command,
810 whether it is
811 .I "read only" ,
812 the current line,
813 the number of lines in the buffer,
814 and the percentage of the way through the buffer of the current line.*
815 .FS
816 * In the rare case that the current file is `[Not edited]' this is
817 noted also; in this case you have to use the form \fBw!\fR to write to
818 the file, since the editor is not sure that a \fBwrite\fR will not
819 destroy a file unrelated to the current contents of the buffer.
820 .FE
821 .LC
822 \fBfile\fR \fIfile\fR
823 .ZP
824 The current file name is changed to
825 .I file
826 which is considered 
827 `[Not edited]'.
828 .LC
829 ( 1 , $ ) \fBglobal\fR /\fIpat\|\fR/ \fIcmds\fR abbr: \fBg\fR
830 .ZP
831 First marks each line among those specified which matches
832 the given regular expression.
833 Then the given command list is executed with `\fB.\fR' initially
834 set to each marked line.
835 .IP
836 The command list consists of the remaining commands on the current
837 input line and may continue to multiple lines by ending all but the
838 last such line with a `\e'.
839 If
840 .I cmds
841 (and possibly the trailing \fB/\fR delimiter) is omitted, each line matching
842 .I pat
843 is printed.
844 .I Append,
845 .I insert,
846 and
847 .I change
848 commands and associated input are permitted;
849 the `\fB.\fR' terminating input may be omitted if it would be on the
850 last line of the command list.
851 .I Open
852 and
853 .I visual
854 commands are permitted in the command list and take input from the terminal.
855 .IP
856 The
857 .I global
858 command itself may not appear in
859 .I cmds.
860 The
861 .I undo
862 command is also not permitted there,
863 as
864 .I undo
865 instead can be used to reverse the entire
866 .I global
867 command.
868 The options
869 .I autoprint
870 and
871 .I autoindent
872 are inhibited during a
873 .I global,
874 (and possibly the trailing \fB/\fR delimiter) and the value of the
875 .I report
876 option is temporarily infinite,
877 in deference to a \fIreport\fR for the entire global.
878 Finally, the context mark `\'\'' is set to the value of
879 `.' before the global command begins and is not changed during a global
880 command,
881 except perhaps by an
882 .I open
883 or
884 .I visual
885 within the
886 .I global.
887 .LC
888 \fBg!\fR \fB/\fIpat\fB/\fR \fIcmds\fR   abbr: \fBv\fR
889 .IP
890 The variant form of \fIglobal\fR runs \fIcmds\fR at each line not matching
891 \fIpat\fR.
892 .LC
893 ( \fB.\fR )\|\fBinsert\fR       abbr: \fBi\fR
894 .br
895 \fItext\fR
896 .br
897 \&\fB.\fR
898 .ZP
899 Places the given text before the specified line.
900 The current line is left at the last line input;
901 if there were none input it is left at the line before the addressed line.
902 This command differs from
903 .I append
904 only in the placement of text.
905 .KS
906 .LC
907 \fBi!\fR
908 .br
909 \fItext\fR
910 .br
911 \&\fB.\fR
912 .ZP
913 The variant toggles
914 .I autoindent
915 during the
916 .I insert.
917 .KE
918 .LC
919 ( \fB.\fR , \fB.\fR+1 ) \fBjoin\fR \fIcount\fR \fIflags\fR      abbr: \fBj\fR
920 .ZP
921 Places the text from a specified range of lines
922 together on one line.
923 White space is adjusted at each junction to provide at least
924 one blank character, two if there was a `\fB.\fR' at the end of the line,
925 or none if the first following character is a `)'.
926 If there is already white space at the end of the line,
927 then the white space at the start of the next line will be discarded.
928 .LC
929 \fBj!\fR
930 .ZP
931 The variant causes a simpler
932 .I join
933 with no white space processing; the characters in the lines are simply
934 concatenated.
935 .LC
936 ( \fB.\fR ) \fBk\fR \fIx\fR
937 .ZP
938 The
939 .I k
940 command is a synonym for
941 .I mark.
942 It does not require a blank or tab before the following letter.
943 .LC
944 ( \fB.\fR , \fB.\fR ) \fBlist\fR \fIcount\fR \fIflags\fR
945 .ZP
946 Prints the specified lines in a more unambiguous way:
947 tabs are printed as `^I'
948 and the end of each line is marked with a trailing `$'.
949 The current line is left at the last line printed.
950 .LC
951 \fBmap\fR \fIlhs\fR \fIrhs\fR
952 .ZP
953 The
954 .I map
955 command is used to define macros for use in
956 .I visual
957 mode.
958 .I Lhs
959 should be a single character, or the sequence ``#n'', for n a digit,
960 referring to function key \fIn\fR.  When this character or function key
961 is typed in
962 .I visual
963 mode, it will be as though the corresponding \fIrhs\fR had been typed.
964 On terminals without function keys, you can type ``#n''.
965 See section 6.9 of the ``Introduction to Display Editing with Vi''
966 for more details.
967 .LC
968 ( \fB.\fR ) \fBmark\fR \fIx\fR
969 .ZP
970 Gives the specified line mark
971 .I x,
972 a single lower case letter.
973 The
974 .I x
975 must be preceded by a blank or a tab.
976 The addressing form `\'x' then addresses this line.
977 The current line is not affected by this command.
978 .LC
979 ( \fB.\fR , \fB.\fR ) \fBmove\fR \fIaddr\fR     abbr: \fBm\fR
980 .ZP
981 The
982 .I move
983 command repositions the specified lines to be after
984 .I addr .
985 The first of the moved lines becomes the current line.
986 .LC
987 \fBnext\fR      abbr: \fBn\fR
988 .ZP
989 The next file from the command line argument list is edited.
990 .LC
991 \fBn!\fR
992 .ZP
993 The variant suppresses warnings about the modifications to the buffer not
994 having been written out, discarding (irretrievably) any changes which may
995 have been made.
996 .LC
997 \fBn\fR \fIfilelist\fR
998 .br
999 \fBn\fR \fB+\fIcommand\fR \fIfilelist\fR
1000 .ZP
1001 The specified
1002 .I filelist
1003 is expanded and the resulting list replaces the
1004 current argument list;
1005 the first file in the new list is then edited.
1006 If
1007 .I command
1008 is given (it must contain no spaces), then it is executed after editing the first such file.
1009 .LC
1010 ( \fB.\fR , \fB.\fR ) \fBnumber\fR \fIcount\fR \fIflags\fR      abbr: \fB#\fR or \fBnu\fR
1011 .ZP
1012 Prints each specified line preceded by its buffer line
1013 number.
1014 The current line is left at the last line printed.
1015 .KS
1016 .LC
1017 ( \fB.\fR ) \fBopen\fR \fIflags\fR      abbr: \fBo\fR
1018 .br
1019 ( \fB.\fR ) \fBopen\fR /\fIpat\|\fR/ \fIflags\fR
1020 .ZP
1021 Enters intraline editing \fIopen\fR mode at each addressed line.
1022 If
1023 .I pat
1024 is given,
1025 then the cursor will be placed initially at the beginning of the
1026 string matched by the pattern.
1027 To exit this mode use Q.
1028 See
1029 .I "An Introduction to Display Editing with Vi"
1030 for more details.
1031 .KE
1032 .LC
1033 \fBpreserve\fR
1034 .ZP
1035 The current editor buffer is saved as though the system had just crashed.
1036 This command is for use only in emergencies when a
1037 .I write
1038 command has resulted in an error and you don't know how to save your work.
1039 After a
1040 .I preserve
1041 you should seek help.
1042 .LC
1043 ( \fB.\fR , \fB.\fR )\|\fBprint\fR \fIcount\fR  abbr: \fBp\fR or \fBP\fR
1044 .ZP
1045 Prints the specified lines
1046 with non-printing characters printed as control characters `^\fIx\fR\|';
1047 delete (octal 177) is represented as `^?'.
1048 The current line is left at the last line printed.
1049 .LC
1050 ( \fB.\fR )\|\fBput\fR \fIbuffer\fR     abbr: \fBpu\fR
1051 .ZP
1052 Puts back
1053 previously
1054 .I deleted
1055 or
1056 .I yanked
1057 lines.
1058 Normally used with
1059 .I delete
1060 to effect movement of lines,
1061 or with
1062 .I yank
1063 to effect duplication of lines.
1064 If no
1065 .I buffer
1066 is specified, then the last
1067 .I deleted
1068 or
1069 .I yanked
1070 text is restored.*
1071 .FS
1072 * But no modifying commands may intervene between the
1073 .I delete
1074 or
1075 .I yank
1076 and the
1077 .I put,
1078 nor may lines be moved between files without using a named buffer.
1079 .FE
1080 By using a named buffer, text may be restored that was saved there at any
1081 previous time.
1082 .LC
1083 \fBquit\fR      abbr: \fBq\fR
1084 .ZP
1085 Causes 
1086 .I ex
1087 to terminate.
1088 No automatic write of the editor buffer to a file is performed.
1089 However,
1090 .I ex
1091 issues a warning message if the file has changed
1092 since the last
1093 .I write
1094 command was issued, and does not
1095 .I quit.\(dg
1096 .FS
1097 \(dg \fIEx\fR
1098 will also issue a diagnostic if there are more files in the argument
1099 list.
1100 .FE
1101 Normally, you will wish to save your changes, and you 
1102 should give a \fIwrite\fR command;
1103 if you wish to discard them, use the \fBq!\fR command variant.
1104 .LC
1105 \fBq!\fR
1106 .ZP
1107 Quits from the editor, discarding changes to the buffer without complaint.
1108 .LC
1109 ( \fB.\fR ) \fBread\fR \fIfile\fR       abbr: \fBr\fR
1110 .ZP
1111 Places a copy of the text of the given file in the
1112 editing buffer after the specified line.
1113 If no 
1114 .I file
1115 is given the current file name is used.
1116 The current file name is not changed unless there is none in which
1117 case
1118 .I file
1119 becomes the current name.
1120 The sensibility restrictions for the 
1121 .I edit
1122 command apply here also.
1123 If the file buffer is empty and there is no current name then
1124 .I ex
1125 treats this as an
1126 .I edit
1127 command.
1128 .IP
1129 Address `0' is legal for this command and causes the file to be read at
1130 the beginning of the buffer.
1131 Statistics are given as for the 
1132 .I edit
1133 command when the 
1134 .I read
1135 successfully terminates.
1136 After a
1137 .I read
1138 the current line is the last line read.\(dd
1139 .FS
1140 \(dd Within
1141 .I open
1142 and
1143 .I visual
1144 the current line is set to the first line read rather than the last.
1145 .FE
1146 .LC
1147 ( \fB.\fR ) \fBread\fR  \fB!\fR\fIcommand\fR
1148 .ZP
1149 Reads the output of the command
1150 .I command
1151 into the buffer after the specified line.
1152 This is not a variant form of the command, rather a read
1153 specifying a
1154 .I command
1155 rather than a 
1156 .I filename;
1157 a blank or tab before the \fB!\fR is mandatory.
1158 .LC
1159 \fBrecover \fIfile\fR
1160 .ZP
1161 Recovers
1162 .I file
1163 from the system save area.
1164 Used after a accidental hangup of the phone**
1165 .FS
1166 ** The system saves a copy of the file you were editing only if you
1167 have made changes to the file.
1168 .FE
1169 or a system crash** or
1170 .I preserve
1171 command.
1172 Except when you use
1173 .I preserve
1174 you will be notified by mail when a file is saved.
1175 .LC
1176 \fBrewind\fR    abbr: \fBrew\fR
1177 .ZP
1178 The argument list is rewound, and the first file in the list is edited.
1179 .LC
1180 \fBrew!\fR
1181 .ZP
1182 Rewinds the argument list discarding any changes made to the current buffer.
1183 .LC
1184 \fBset\fR \fIparameter\fR
1185 .ZP
1186 With no arguments, prints those options whose values have been
1187 changed from their defaults;
1188 with parameter
1189 .I all
1190 it prints all of the option values.
1191 .IP
1192 Giving an option name followed by a `?'
1193 causes the current value of that option to be printed.
1194 The `?' is unnecessary unless the option is Boolean valued.
1195 Boolean options are given values either by the form
1196 `set \fIoption\fR' to turn them on or
1197 `set no\fIoption\fR' to turn them off;
1198 string and numeric options are assigned via the form
1199 `set \fIoption\fR=value'.
1200 .IP
1201 More than one parameter may be given to 
1202 .I set \|;
1203 they are interpreted left-to-right.
1204 .LC
1205 \fBshell\fR     abbr: \fBsh\fR
1206 .IP
1207 A new shell is created.
1208 When it terminates, editing resumes.
1209 .LC
1210 \fBsource\fR \fIfile\fR abbr: \fBso\fR
1211 .IP
1212 Reads and executes commands from the specified file.
1213 .I Source
1214 commands may be nested.
1215 .LC
1216 ( \fB.\fR , \fB.\fR ) \fBsubstitute\fR /\fIpat\fR\|/\fIrepl\fR\|/ \fIoptions\fR \fIcount\fR \fIflags\fR abbr: \fBs\fR
1217 .IP
1218 On each specified line, the first instance of pattern
1219 .I pat
1220 is replaced by replacement pattern
1221 .I repl.
1222 If the
1223 .I global
1224 indicator option character `g'
1225 appears, then all instances are substituted;
1226 if the
1227 .I confirm
1228 indication character `c' appears,
1229 then before each substitution the line to be substituted
1230 is typed with the string to be substituted marked
1231 with `\(ua' characters.
1232 By typing an `y' one can cause the substitution to be performed,
1233 any other input causes no change to take place.
1234 After a
1235 .I substitute
1236 the current line is the last line substituted.
1237 .IP
1238 Lines may be split by substituting
1239 new-line characters into them.
1240 The newline in
1241 .I repl
1242 must be escaped by preceding it with a `\e'.
1243 Other metacharacters available in
1244 .I pat
1245 and
1246 .I repl
1247 are described below.
1248 .LC
1249 .B stop
1250 .ZP
1251 Suspends the editor, returning control to the top level shell.
1252 If
1253 .I autowrite
1254 is set and there are unsaved changes,
1255 a write is done first unless the form
1256 .B stop !
1257 is used.
1258 This commands is only available where supported by the teletype driver
1259 and operating system.
1260 .LC
1261 ( \fB.\fR , \fB.\fR ) \fBsubstitute\fR \fIoptions\fR \fIcount\fR \fIflags\fR    abbr: \fBs\fR
1262 .ZP
1263 If
1264 .I pat
1265 and
1266 .I repl
1267 are omitted, then the last substitution is repeated.
1268 This is a synonym for the
1269 .B &
1270 command.
1271 .LC
1272 ( \fB.\fR , \fB.\fR ) \fBt\fR \fIaddr\fR \fIflags\fR
1273 .ZP
1274 The
1275 .I t
1276 command is a synonym for 
1277 .I copy .
1278 .LC
1279 \fBta\fR \fItag\fR
1280 .ZP
1281 The focus of editing switches to the location of
1282 .I tag,
1283 switching to a different line in the current file where it is defined,
1284 or if necessary to another file.\(dd
1285 .FS
1286 \(dd If you have modified the current file before giving a
1287 .I tag
1288 command, you must write it out; giving another
1289 .I tag
1290 command, specifying no
1291 .I tag
1292 will reuse the previous tag.
1293 .FE
1294 .IP
1295 The tags file is normally created by a program such as
1296 .I ctags,
1297 and consists of a number of lines with three fields separated by blanks
1298 or tabs.  The first field gives the name of the tag,
1299 the second the name of the file where the tag resides, and the third
1300 gives an addressing form which can be used by the editor to find the tag;
1301 this field is usually a contextual scan using `/\fIpat\fR/' to be immune
1302 to minor changes in the file.  Such scans are always performed as if
1303 .I nomagic
1304 was set.
1305 .PP
1306 The tag names in the tags file must be sorted alphabetically.
1307 .LC
1308 \fBunabbreviate\fR \fIword\fP   abbr: \fBuna\fP
1309 .ZP
1310 Delete
1311 .I word
1312 from the list of abbreviations.
1313 .LC
1314 \fBundo\fR      abbr: \fBu\fR
1315 .ZP
1316 Reverses the changes made in the buffer by the last
1317 buffer editing command.
1318 Note that
1319 .I global
1320 commands are considered a single command for the purpose of 
1321 .I undo
1322 (as are
1323 .I open
1324 and
1325 .I visual.)
1326 Also, the commands
1327 .I write
1328 and
1329 .I edit
1330 which interact with the
1331 file system cannot be undone.
1332 .I Undo
1333 is its own inverse.
1334 .IP
1335 .I Undo
1336 always marks the previous value of the current line `\fB.\fR'
1337 as `\'\''.
1338 After an
1339 .I undo
1340 the current line is the first line restored
1341 or the line before the first line deleted if no lines were restored.
1342 For commands with more global effect
1343 such as
1344 .I global
1345 and
1346 .I visual
1347 the current line regains it's pre-command value after an
1348 .I undo.
1349 .LC
1350 \fBunmap\fR \fIlhs\fR
1351 .ZP
1352 The macro expansion associated by
1353 .I map
1354 for
1355 .I lhs
1356 is removed.
1357 .LC
1358 ( 1 , $ ) \fBv\fR /\fIpat\fR\|/ \fIcmds\fR
1359 .ZP
1360 A synonym for the
1361 .I global
1362 command variant \fBg!\fR, running the specified \fIcmds\fR on each
1363 line which does not match \fIpat\fR.
1364 .LC
1365 \fBversion\fR   abbr: \fBve\fR
1366 .ZP
1367 Prints the current version number of the editor
1368 as well as the date the editor was last changed.
1369 .LC
1370 ( \fB.\fR ) \fBvisual\fR \fItype\fR \fIcount\fR \fIflags\fR     abbr: \fBvi\fR
1371 .ZP
1372 Enters visual mode at the specified line.
1373 .I Type
1374 is optional and may be `\-' , `\(ua' or `\fB.\fR'
1375 as in the
1376 .I z
1377 command to specify the placement of the specified line on the screen.
1378 By default, if
1379 .I type
1380 is omitted, the specified line is placed as the first on the screen.
1381 A
1382 .I count
1383 specifies an initial window size; the default is the value of the option
1384 .I window.
1385 See the document
1386 .I "An Introduction to Display Editing with Vi"
1387 for more details.
1388 To exit this mode, type Q.
1389 .LC
1390 \fBvisual\fP file
1391 .br
1392 \fBvisual\fP +\fIn\fP file
1393 .ZP
1394 From visual mode,
1395 this command is the same as edit.
1396 .LC
1397 ( 1 , $ ) \fBwrite\fR \fIfile\fR        abbr: \fBw\fR
1398 .ZP
1399 Writes changes made back to \fIfile\fR, printing the number of lines and
1400 characters written.
1401 Normally \fIfile\fR is omitted and the text goes back where it came from.
1402 If a \fIfile\fR is specified, then text will be written to that file.*
1403 .FS
1404 * The editor writes to a file only if it is
1405 the current file and is
1406 .I edited ,
1407 if the file does not exist,
1408 or if the file is actually a teletype,
1409 .I /dev/tty,
1410 .I /dev/null.
1411 Otherwise, you must give the variant form \fBw!\fR to force the write.
1412 .FE
1413 If the file does not exist it is created.
1414 The current file name is changed only if there is no current file
1415 name; the current line is never changed.
1416 .IP
1417 If an error occurs while writing the current and
1418 .I edited
1419 file, the editor
1420 considers that there has been ``No write since last change''
1421 even if the buffer had not previously been modified.
1422 .LC
1423 ( 1 , $ ) \fBwrite>>\fR \fIfile\fR      abbr: \fBw>>\fR
1424 .ZP
1425 Writes the buffer contents at the end of
1426 an existing file.
1427 .IP
1428 .LC
1429 \fBw!\fR \fIname\fR
1430 .ZP
1431 Overrides the checking of the normal \fIwrite\fR command,
1432 and will write to any file which the system permits.
1433 .LC
1434 ( 1 , $ ) \fBw\fR  \fB!\fR\fIcommand\fR
1435 .ZP
1436 Writes the specified lines into 
1437 .I command.
1438 Note the difference between \fBw!\fR which overrides checks and
1439 \fBw\ \ !\fR which writes to a command.
1440 .LC
1441 \fBwq\fR \fIname\fR
1442 .ZP
1443 Like a \fIwrite\fR and then a \fIquit\fR command.
1444 .LC
1445 \fBwq!\fR \fIname\fR
1446 .ZP
1447 The variant overrides checking on the sensibility of the
1448 .I write
1449 command, as \fBw!\fR does.
1450 .LC
1451 \fBxit\fP \fIname\fR
1452 .ZP
1453 If any changes have been made and not written, writes the buffer out.
1454 Then, in any case, quits.
1455 .LC
1456 ( \fB.\fR , \fB.\fR )\|\fByank\fR \fIbuffer\fR \fIcount\fR      abbr: \fBya\fR
1457 .ZP
1458 Places the specified lines in the named
1459 .I buffer,
1460 for later retrieval via
1461 .I put.
1462 If no buffer name is specified, the lines go to a more volatile place;
1463 see the \fIput\fR command description.
1464 .LC
1465 ( \fB.+1\fR ) \fBz\fR \fIcount\fR
1466 .ZP
1467 Print the next \fIcount\fR lines, default \fIwindow\fR.
1468 .LC
1469 ( \fB.\fR ) \fBz\fR \fItype\fR \fIcount\fR
1470 .ZP
1471 Prints a window of text with the specified line at the top.
1472 If \fItype\fR is `\-' the line is placed at the bottom; a `\fB.\fR' causes
1473 the line to be placed in the center.*
1474 A count gives the number of lines to be displayed rather than
1475 double the number specified by the \fIscroll\fR option.
1476 On a \s-2CRT\s0 the screen is cleared before display begins unless a
1477 count which is less than the screen size is given.
1478 The current line is left at the last line printed.
1479 .FS
1480 * Forms `z=' and `z\(ua' also exist; `z=' places the current line in the
1481 center, surrounds it with lines of `\-' characters and leaves the current
1482 line at this line.  The form `z\(ua' prints the window before `z\-'
1483 would.  The characters `+', `\(ua' and `\-' may be repeated for cumulative
1484 effect.
1485 On some v2 editors, no
1486 .I type
1487 may be given.
1488 .FE
1489 .LC
1490 \fB!\fR \fIcommand\fR\fR
1491 .ZP
1492 The remainder of the line after the `!' character is sent to a shell
1493 to be executed.
1494 Within the text of
1495 .I command
1496 the characters 
1497 `%' and `#' are expanded as in filenames and the character
1498 `!' is replaced with the text of the previous command.
1499 Thus, in particular,
1500 `!!' repeats the last such shell escape.
1501 If any such expansion is performed, the expanded line will be echoed.
1502 The current line is unchanged by this command.
1503 .IP
1504 If there has been ``[No\ write]'' of the buffer contents since the last
1505 change to the editing buffer, then a diagnostic will be printed
1506 before the command is executed as a warning.
1507 A single `!' is printed when the command completes.
1508 .LC
1509 ( \fIaddr\fR , \fIaddr\fR ) \fB!\fR \fIcommand\fR\fR
1510 .ZP
1511 Takes the specified address range and supplies it as
1512 standard input to
1513 .I command;
1514 the resulting output then replaces the input lines.
1515 .LC
1516 ( $ ) \fB=\fR
1517 .ZP
1518 Prints the line number of the
1519 addressed line.
1520 The current line is unchanged.
1521 .KS
1522 .LC
1523 ( \fB.\fR , \fB.\fR ) \fB>\fR \fIcount\fR \fIflags\fR
1524 .br
1525 ( \fB.\fR , \fB.\fR ) \fB<\fR \fIcount\fR \fIflags\fR
1526 .IP
1527 Perform intelligent shifting on the specified lines;
1528 \fB<\fR shifts left and \fB>\fR shift right.
1529 The quantity of shift is determined by the
1530 .I shiftwidth
1531 option and the repetition of the specification character.
1532 Only white space (blanks and tabs) is shifted;
1533 no non-white characters are discarded in a left-shift.
1534 The current line becomes the last line which changed due to the
1535 shifting.
1536 .KE
1537 .LC
1538 \fB^D\fR
1539 .ZP
1540 An end-of-file from a terminal input scrolls through the file.
1541 The
1542 .I scroll
1543 option specifies the size of the scroll, normally a half screen of text.
1544 .LC
1545 ( \fB.\fR+1 , \fB.\fR+1 )
1546 .br
1547 ( \fB.\fR+1 , \fB.\fR+1 ) |
1548 .ZP
1549 An address alone causes the addressed lines to be printed.
1550 A blank line prints the next line in the file.
1551 .LC
1552 ( \fB.\fR , \fB.\fR ) \fB&\fR \fIoptions\fR \fIcount\fR \fIflags\fR
1553 .ZP
1554 Repeats the previous
1555 .I substitute
1556 command.
1557 .LC
1558 ( \fB.\fR , \fB.\fR ) \fB\s+2~\s0\fR \fIoptions\fR \fIcount\fR \fIflags\fR
1559 .ZP
1560 Replaces the previous regular expression with the previous
1561 replacement pattern from a substitution.
1562 .NH 1
1563 Regular expressions and substitute replacement patterns
1564 .NH 2
1565 Regular expressions
1566 .PP
1567 A regular expression specifies a set of strings of characters.
1568 A member of this set of strings is said to be
1569 .I matched
1570 by the regular expression.
1571 .I Ex
1572 remembers two previous regular expressions:
1573 the previous regular expression used in a
1574 .I substitute
1575 command
1576 and the previous regular expression used elsewhere
1577 (referred to as the previous \fIscanning\fR regular expression.)
1578 The previous regular expression
1579 can always be referred to by a null \fIre\fR, e.g. `//' or `??'.
1580 .NH 2
1581 Magic and nomagic
1582 .PP
1583 The regular expressions allowed by
1584 .I ex 
1585 are constructed in one of two ways depending on the setting of
1586 the
1587 .I magic
1588 option.
1589 The
1590 .I ex
1591 and
1592 .I vi
1593 default setting of
1594 .I magic
1595 gives quick access to a powerful set of regular expression
1596 metacharacters.
1597 The disadvantage of
1598 .I magic
1599 is that the user must remember that these metacharacters are
1600 .I magic
1601 and precede them with the character `\e'
1602 to use them as ``ordinary'' characters.
1603 With
1604 .I nomagic,
1605 the default for
1606 .I edit,
1607 regular expressions are much simpler,
1608 there being only two metacharacters.
1609 The power of the other metacharacters is still available by preceding
1610 the (now) ordinary character with a `\e'.
1611 Note that `\e' is thus always a metacharacter.
1612 .PP
1613 The remainder of the discussion of regular expressions assumes
1614 that
1615 that the setting of this option is
1616 .I magic.\(dg
1617 .FS
1618 \(dg To discern what is true with
1619 .I nomagic
1620 it suffices to remember that the only
1621 special characters in this case will be `\(ua' at the beginning
1622 of a regular expression,
1623 `$' at the end of a regular expression,
1624 and `\e'.
1625 With
1626 .I nomagic
1627 the characters `\s+2~\s0' and `&' also lose their special meanings
1628 related to the replacement pattern of a substitute.
1629 .FE
1630 .NH 2
1631 Basic regular expression summary
1632 .PP
1633 The following basic constructs are used to construct
1634 .I magic
1635 mode regular expressions.
1636 .IP \fIchar\fR 15
1637 An ordinary character matches itself.
1638 The characters `\(ua' at the beginning of a line,
1639 `$' at the end of line,
1640 `*' as any character other than the first,
1641 `.', `\e', `[', and `\s+2~\s0' are not ordinary characters and
1642 must be escaped (preceded) by `\e' to be treated as such.
1643 .IP \fB\(ua\fR
1644 At the beginning of a pattern
1645 forces the match to succeed only at the beginning of a line.
1646 .IP \fB$\fR
1647 At the end of a regular expression forces the match to
1648 succeed only at the end of the line.
1649 .IP \&\fB.\fR
1650 Matches any single character except
1651 the new-line character.
1652 .IP \fB\e<\fR
1653 Forces the match
1654 to occur only at the beginning of a ``variable'' or ``word'';
1655 that is, either at the beginning of a line, or just before
1656 a letter, digit, or underline and after a character not one of
1657 these.
1658 .IP \fB\e>\fR
1659 Similar to `\e<', but matching the end of a ``variable''
1660 or ``word'', i.e. either the end of the line or before character
1661 which is neither a letter, nor a digit, nor the underline character.
1662 .IP \fB[\fIstring\fR]\fR
1663 Matches any (single) character in the class defined by
1664 .I string.
1665 Most characters in
1666 .I string
1667 define themselves.
1668 A pair of characters separated by `\-' in
1669 .I string
1670 defines the set of characters collating between the specified lower and upper
1671 bounds, thus `[a\-z]' as a regular expression matches
1672 any (single) lower-case letter.
1673 If the first character of
1674 .I string
1675 is an `\(ua' then the construct
1676 matches those characters which it otherwise would not;
1677 thus `[\(uaa\-z]' matches anything but a lower-case letter (and of course a
1678 newline).
1679 To place any of the characters
1680 `\(ua', `[', or `\-' in
1681 .I string
1682 you must escape them with a preceding `\e'.
1683 .NH 2
1684 Combining regular expression primitives
1685 .PP
1686 The concatenation of two regular expressions matches the leftmost and
1687 then longest string
1688 which can be divided with the first piece matching the first regular
1689 expression and the second piece matching the second.
1690 Any of the (single character matching) regular expressions mentioned
1691 above may be followed by the character `*' to form a regular expression
1692 which matches any number of adjacent occurrences (including 0) of characters
1693 matched by the regular expression it follows.
1694 .PP
1695 The character `\s+2~\s0' may be used in a regular expression,
1696 and matches the text which defined the replacement part
1697 of the last
1698 .I substitute
1699 command.
1700 A regular expression may be enclosed between the sequences
1701 `\e(' and `\e)' with side effects in the
1702 .I substitute
1703 replacement patterns.
1704 .NH 2
1705 Substitute replacement patterns
1706 .PP
1707 The basic metacharacters for the replacement pattern are
1708 `&' and `~'; these are
1709 given as `\e&' and `\e~' when
1710 .I nomagic
1711 is set.
1712 Each instance of `&' is replaced by the characters
1713 which the regular expression matched.
1714 The metacharacter `~' stands, in the replacement pattern,
1715 for the defining text of the previous replacement pattern.
1716 .PP
1717 Other metasequences possible in the replacement pattern
1718 are always introduced by the escaping character `\e'.
1719 The sequence `\e\fIn\fR' is replaced by the text matched
1720 by the \fIn\fR-th regular subexpression enclosed between
1721 `\e(' and `\e)'.\(dg
1722 .FS
1723 \(dg When nested, parenthesized subexpressions are present,
1724 \fIn\fR is determined by counting occurrences of `\e(' starting from the left.
1725 .FE
1726 The sequences `\eu' and `\el' cause the immediately following character in
1727 the replacement to be converted to upper- or lower-case respectively
1728 if this character is a letter.
1729 The sequences `\eU' and `\eL' turn such conversion on, either until
1730 `\eE' or `\ee' is encountered, or until the end of the replacement pattern.
1731 .de LC
1732 .br
1733 .sp .1i
1734 .ne 4
1735 .LP
1736 .ta 3i
1737 ..
1738 .NH 1
1739 Option descriptions
1740 .PP
1741 .LC
1742 \fBautoindent\fR, \fBai\fR      default: noai
1743 .ZP
1744 Can be used to ease the preparation of structured program text.
1745 At the beginning of each
1746 .I append ,
1747 .I change
1748 or
1749 .I insert
1750 command
1751 or when a new line is
1752 .I opened
1753 or created by an
1754 .I append ,
1755 .I change ,
1756 .I insert ,
1757 or
1758 .I substitute
1759 operation within
1760 .I open
1761 or
1762 .I visual
1763 mode,
1764 .I ex
1765 looks at the line being appended after,
1766 the first line changed
1767 or the line inserted before and calculates the amount of white space
1768 at the start of the line.
1769 It then aligns the cursor at the level of indentation so determined.
1770 .IP
1771 If the user then types lines of text in,
1772 they will continue to be justified at the displayed indenting level.
1773 If more white space is typed at the beginning of a line,
1774 the following line will start aligned with the first non-white character
1775 of the previous line.
1776 To back the cursor up to the preceding tab stop one can hit
1777 \fB^D\fR.
1778 The tab stops going backwards are defined at multiples of the
1779 .I shiftwidth
1780 option.
1781 You
1782 .I cannot
1783 backspace over the indent,
1784 except by sending an end-of-file with a \fB^D\fR.
1785 .IP
1786 Specially processed in this mode is a line with no characters added
1787 to it, which turns into a completely blank line (the white
1788 space provided for the
1789 .I autoindent
1790 is discarded.)
1791 Also specially processed in this mode are lines beginning with
1792 an `\(ua' and immediately followed by a \fB^D\fR.
1793 This causes the input to be repositioned at the beginning of the line,
1794 but retaining the previous indent for the next line.
1795 Similarly, a `0' followed by a \fB^D\fR
1796 repositions at the beginning but without
1797 retaining the previous indent.
1798 .IP
1799 .I Autoindent
1800 doesn't happen in
1801 .I global
1802 commands or when the input is not a terminal.
1803 .LC
1804 \fBautoprint\fR, \fBap\fR       default: ap
1805 .ZP
1806 Causes the current line to be printed after each
1807 .I delete ,
1808 .I copy ,
1809 .I join ,
1810 .I move ,
1811 .I substitute ,
1812 .I t ,
1813 .I undo
1814 or
1815 shift command.
1816 This has the same effect as supplying a trailing `p'
1817 to each such command.
1818 .I Autoprint
1819 is suppressed in globals,
1820 and only applies to the last of many commands on a line.
1821 .LC
1822 \fBautowrite\fR, \fBaw\fR       default: noaw
1823 .ZP
1824 Causes the contents of the buffer to be written to the current file
1825 if you have modified it and give a
1826 .I next,
1827 .I rewind,
1828 .I stop,
1829 .I tag,
1830 or
1831 .I !
1832 command, or a \fB^\(ua\fR (switch files) or \fB^]\fR (tag goto) command
1833 in
1834 .I visual.
1835 Note, that the
1836 .I edit
1837 and
1838 .I ex
1839 commands do
1840 .B not
1841 autowrite.
1842 In each case, there is an equivalent way of switching when autowrite
1843 is set to avoid the
1844 .I autowrite
1845 (\fIedit\fR
1846 for
1847 .I next ,
1848 .I rewind!
1849 for .I rewind ,
1850 .I stop!
1851 for
1852 .I stop ,
1853 .I tag!
1854 for
1855 .I tag ,
1856 .I shell
1857 for
1858 .I ! ,
1859 and
1860 \fB:e\ #\fR and a \fB:ta!\fR command from within
1861 .I visual).
1862 .LC
1863 \fBbeautify\fR, \fBbf\fR        default: nobeautify
1864 .ZP
1865 Causes all control characters except tab, newline and form-feed
1866 to be discarded from the input.
1867 A complaint is registered the first time a
1868 backspace character is discarded.
1869 .I Beautify
1870 does not apply to command input.
1871 .LC
1872 \fBdirectory\fR, \fBdir\fR      default: dir=/tmp
1873 .ZP
1874 Specifies the directory in which
1875 .I ex
1876 places its buffer file.
1877 If this directory in not
1878 writable, then the editor will exit abruptly when it fails to be
1879 able to create its buffer there.
1880 .LC
1881 \fBedcompatible\fR      default: noedcompatible
1882 .ZP
1883 Causes the presence of absence of
1884 .B g
1885 and
1886 .B c
1887 suffixes on substitute commands to be remembered, and to be toggled
1888 by repeating the suffices.  The suffix
1889 .B r
1890 makes the substitution be as in the
1891 .I ~
1892 command, instead of like
1893 .I &.
1894 .LC
1895 \fBerrorbells\fR, \fBeb\fR      default: noeb
1896 .ZP
1897 Error messages are preceded by a bell.*
1898 .FS
1899 * Bell ringing in
1900 .I open
1901 and
1902 .I visual
1903 on errors is not suppressed by setting
1904 .I noeb.
1905 .FE
1906 If possible the editor always places the error message in a standout mode of the
1907 terminal (such as inverse video) instead of ringing the bell.
1908 .LC
1909 \fBhardtabs\fR, \fBht\fR        default: ht=8
1910 .ZP
1911 Gives the boundaries on which terminal hardware tabs are set (or
1912 on which the system expands tabs).
1913 .LC
1914 \fBignorecase\fR, \fBic\fR      default: noic
1915 .ZP
1916 All upper case characters in the text are mapped to lower case in regular
1917 expression matching.
1918 In addition, all upper case characters in regular expressions are mapped
1919 to lower case except in character class specifications.
1920 .LC
1921 \fBlisp\fR      default: nolisp
1922 .ZP
1923 \fIAutoindent\fR indents appropriately for
1924 .I lisp
1925 code, and the \fB( ) { } [[\fR and \fB]]\fR commands in
1926 .I open
1927 and
1928 .I visual
1929 are modified to have meaning for \fIlisp\fR.
1930 .LC
1931 \fBlist\fR      default: nolist
1932 .ZP
1933 All printed lines will be displayed (more) unambiguously,
1934 showing tabs and end-of-lines as in the
1935 .I list
1936 command.
1937 .LC
1938 \fBmagic\fR     default: magic for \fIex\fR and \fIvi\fR\(dg
1939 .FS
1940 \(dg \fINomagic\fR for \fIedit\fR.
1941 .FE
1942 .ZP
1943 If
1944 .I nomagic
1945 is set, the number of regular expression metacharacters is greatly reduced,
1946 with only `\(ua' and `$' having special effects.
1947 In addition the metacharacters
1948 `~'
1949 and
1950 `&'
1951 of the replacement pattern are treated as normal characters.
1952 All the normal metacharacters may be made
1953 .I magic
1954 when
1955 .I nomagic
1956 is set by preceding them with a `\e'.
1957 .LC
1958 \fBmesg\fR      default: mesg
1959 .ZP
1960 Causes write permission to be turned off to the terminal
1961 while you are in visual mode, if
1962 .I nomesg
1963 is set.
1964 .LC
1965 \fBmodeline\fR  default: nomodeline
1966 .ZP
1967 If
1968 .I modeline
1969 is set, then the first 5 lines and the last five lines of the file
1970 will be checked for ex command lines and the comands issued.
1971 To be recognized as a command line, the line must have the string
1972 .B ex:
1973 or
1974 .B vi:
1975 preceeded by a tab or a space.  This string may be anywhere in the
1976 line and anything after the 
1977 .I :
1978 is interpeted as editor commands.  This option defaults to off because
1979 of unexpected behavior when editting files such as
1980 .I /etc/passwd.
1981 .LC
1982 \fBnumber, nu\fR        default: nonumber
1983 .ZP
1984 Causes all output lines to be printed with their
1985 line numbers.
1986 In addition each input line will be prompted for by supplying the line number
1987 it will have.
1988 .LC
1989 \fBopen\fR      default: open
1990 .ZP
1991 If \fInoopen\fR, the commands
1992 .I open
1993 and
1994 .I visual
1995 are not permitted.
1996 This is set for
1997 .I edit
1998 to prevent confusion resulting from accidental entry to 
1999 open or visual mode.
2000 .LC
2001 \fBoptimize, opt\fR     default: optimize
2002 .ZP
2003 Throughput of text is expedited by setting the terminal
2004 to not do automatic carriage returns
2005 when printing more than one (logical) line of output,
2006 greatly speeding output on terminals without addressable
2007 cursors when text with leading white space is printed.
2008 .LC
2009 \fBparagraphs,\ para\fR default: para=IPLPPPQPP\0LIbp
2010 .ZP
2011 Specifies the paragraphs for the \fB{\fR and \fB}\fR operations in
2012 .I open
2013 and 
2014 .I visual.
2015 The pairs of characters in the option's value are the names
2016 of the macros which start paragraphs.
2017 .LC
2018 \fBprompt\fR    default: prompt
2019 .ZP
2020 Command mode input is prompted for with a `:'.
2021 .LC
2022 \fBredraw\fR    default: noredraw
2023 .ZP
2024 The editor simulates (using great amounts of output), an intelligent
2025 terminal on a dumb terminal (e.g. during insertions in
2026 .I visual
2027 the characters to the right of the cursor position are refreshed
2028 as each input character is typed.)
2029 Useful only at very high speed.
2030 .LC
2031 \fBremap\fP     default: remap
2032 .ZP
2033 If on, macros are repeatedly tried until they are unchanged.
2034 For example, if
2035 .B o
2036 is mapped to
2037 .B O ,
2038 and
2039 .B O
2040 is mapped to
2041 .B I ,
2042 then if
2043 .I remap
2044 is set,
2045 .B o
2046 will map to
2047 .B I ,
2048 but if
2049 .I noremap
2050 is set, it will map to
2051 .B O .
2052 .LC
2053 \fBreport\fR    default: report=5\(dg
2054 .FS
2055 \(dg 2 for \fIedit\fR.
2056 .FE
2057 .ZP
2058 Specifies a threshold for feedback from commands.
2059 Any command which modifies more than the specified number of lines
2060 will provide feedback as to the scope of its changes.
2061 For commands such as
2062 .I global ,
2063 .I open ,
2064 .I undo ,
2065 and
2066 .I visual
2067 which have potentially more far reaching scope,
2068 the net change in the number of lines in the buffer is
2069 presented at the end of the command, subject to this same threshold.
2070 Thus notification is suppressed during a
2071 .I global
2072 command on the individual commands performed.
2073 .LC
2074 \fBscroll\fR    default: scroll=\(12 window
2075 .ZP
2076 Determines the number of logical lines scrolled when an end-of-file
2077 is received from a terminal input in command mode,
2078 and the number of lines printed by a command mode
2079 .I z
2080 command (double the value of
2081 .I scroll ).
2082 .LC
2083 \fBsections\fR  default: sections=SHNHH\0HU
2084 .ZP
2085 Specifies the section macros for the \fB[[\fR and \fB]]\fR operations
2086 in
2087 .I open
2088 and
2089 .I visual.
2090 The pairs of characters in the options's value are the names
2091 of the macros which start paragraphs.
2092 .LC
2093 \fBshell\fR, \fBsh\fR   default: sh=/bin/sh
2094 .ZP
2095 Gives the path name of the shell forked for 
2096 the shell escape command `!', and by the
2097 .I shell
2098 command.
2099 The default is taken from SHELL in the environment, if present.
2100 .LC
2101 \fBshiftwidth\fR, \fBsw\fR      default: sw=8
2102 .ZP
2103 Gives the width a software tab stop,
2104 used in reverse tabbing with \fB^D\fR when using
2105 .I autoindent
2106 to append text,
2107 and by the shift commands.
2108 .LC
2109 \fBshowmatch, sm\fR     default: nosm
2110 .ZP
2111 In
2112 .I open
2113 and
2114 .I visual
2115 mode, when a \fB)\fR or \fB}\fR is typed, move the cursor to the matching
2116 \fB(\fR or \fB{\fR for one second if this matching character is on the
2117 screen.  Extremely useful with
2118 .I lisp.
2119 .LC
2120 \fBslowopen, slow\fR    terminal dependent
2121 .ZP
2122 Affects the display algorithm used in
2123 .I visual
2124 mode, holding off display updating during input of new text to improve
2125 throughput when the terminal in use is both slow and unintelligent.
2126 See
2127 .I "An Introduction to Display Editing with Vi"
2128 for more details.
2129 .LC
2130 \fBtabstop,\ ts\fR      default: ts=8
2131 .ZP
2132 The editor expands tabs in the input file to be on
2133 .I tabstop
2134 boundaries for the purposes of display.
2135 .LC
2136 \fBtaglength,\ tl\fR    default: tl=0
2137 .ZP
2138 Tags are not significant beyond this many characters.
2139 A value of zero (the default) means that all characters are significant.
2140 .LC
2141 \fBtags\fR      default: tags=tags /usr/lib/tags
2142 .ZP
2143 A path of files to be used as tag files for the
2144 .I tag
2145 command.
2146 A requested tag is searched for in the specified files, sequentially.
2147 By default, files called
2148 .B tags
2149 are searched for in the current directory and in /usr/lib
2150 (a master file for the entire system).
2151 .LC
2152 \fBterm\fR      from environment TERM
2153 .ZP
2154 The terminal type of the output device.
2155 .LC
2156 \fBterse\fR     default: noterse
2157 .ZP
2158 Shorter error diagnostics are produced for the experienced user.
2159 .LC
2160 \fBwarn\fR      default: warn
2161 .ZP
2162 Warn if there has been `[No write since last change]' before a `!'
2163 command escape.
2164 .LC
2165 \fBwindow\fR    default: window=speed dependent
2166 .ZP
2167 The number of lines in a text window in the
2168 .I visual
2169 command.
2170 The default is 8 at slow speeds (600 baud or less),
2171 16 at medium speed (1200 baud),
2172 and the full screen (minus one line) at higher speeds.
2173 .LC
2174 \fBw300,\ w1200\, w9600\fR
2175 .ZP
2176 These are not true options but set
2177 .B window
2178 only if the speed is slow (300), medium (1200), or high (9600),
2179 respectively.
2180 They are suitable for an EXINIT
2181 and make it easy to change the 8/16/full screen rule.
2182 .LC
2183 \fBwrapscan\fR, \fBws\fR        default: ws
2184 .ZP
2185 Searches using the regular expressions in addressing
2186 will wrap around past the end of the file.
2187 .LC
2188 \fBwrapmargin\fR, \fBwm\fR      default: wm=0
2189 .ZP
2190 Defines a margin for automatic wrapover of text during input in
2191 .I open
2192 and
2193 .I visual
2194 modes.  See
2195 .I "An Introduction to Text Editing with Vi"
2196 for details.
2197 .LC
2198 \fBwriteany\fR, \fBwa\fR        default: nowa
2199 .IP
2200 Inhibit the checks normally made before
2201 .I write
2202 commands, allowing a write to any file which the system protection
2203 mechanism will allow.
2204 .NH 1
2205 Acknowledgements
2206 .PP
2207 Chuck Haley contributed greatly to the early development of
2208 .I ex.
2209 Bruce Englar encouraged the redesign which led to
2210 .I ex
2211 version 1.
2212 Bill Joy wrote versions 1 and 2.0 through 2.7,
2213 and created the framework that users see in the present editor.
2214 Mark Horton added macros and other features and made the
2215 editor work on a large number of terminals and Unix systems.