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