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