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