1 .\" Copyright (c) 1980 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" %sccs.include.redist.roff%
6 .\" $Id: ex.rm,v 6.2 1991/04/17 12:42:52 bostic Exp $ (Berkeley) $Date: 1991/04/17 12:42:52 $
8 .EH 'USD:16-%''Ex Reference Manual'
9 .OH 'Ex Reference Manual''USD:16-%'
14 .if \\n(.$=1 .IP "\\$1"
15 .if \\n(.$>=2 .IP "\\$1" "\\$2"
37 Computer Science Division
38 Department of Electrical Engineering and Computer Science
39 University of California, Berkeley
43 a line oriented text editor, which supports both command and display
45 This reference manual describes the command oriented part of
47 the display editing features of
50 .I "An Introduction to Display Editing with Vi."
51 Other documents about the editor include the introduction
52 .I "Edit: A tutorial",
54 .I "Ex/edit Command Summary",
56 .I "Vi Quick Reference"
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
67 Each instance of the editor has a set of options,
68 which can be set to tailor it to your liking.
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.
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,
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
91 in your \s-2HOME\s0 directory
93 reads commands from that file, simulating a
96 Option setting commands placed in
99 will be executed before each editor session.
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.:
117 option suppresses all interactive-user feedback
118 and is useful in processing editor scripts in command files.
121 option is equivalent to using
127 option is equivalent to an initial
129 command, editing the file containing the
131 and positioning the editor at its definition.
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.
140 option sets up for editing \s-2LISP\s0, setting the
147 option sets the default window size to
149 and is useful on dialups to start in small windows.
156 which is used to encrypt and decrypt the contents of the file,
157 which should already be encrypted using the same key,
166 arguments indicate files to be edited.
167 An argument of the form
169 indicates that the editor should begin by executing the specified 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
182 is normally editing the contents of a single file,
183 whose name is recorded in the
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
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
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,
207 is a reasonable action.
208 If the current file is not
212 will not normally write on it if it already exists.*
216 command will say ``[Not edited]'' if the current file is not considered
222 Each time a new value is given to the current file name,
223 the previous current file name is saved as the
226 Similarly if a file is mentioned but does not become the current file,
227 it is saved as the alternate file name.
231 Filenames within the editor may be specified using the normal
232 shell expansion conventions.
234 the character `%' in filenames is replaced by the
236 file name and the character
241 \(dg This makes it easy to deal alternately with
242 two files and eliminates the need for retyping the
246 .I "No write since last change"
247 diagnostic is received.
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
256 The current argument list may be displayed with the
259 The next file in the argument list may be edited with the
262 The argument list may also be respecified by specifying
263 a list of names to the
266 These names are expanded,
267 the resulting list of names becomes the new argument list,
270 edits the first file on the list.
272 For saving blocks of text while editing, and especially when editing
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
283 \(dd It is also possible to refer to
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.
294 It is possible to use
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
303 It can be turned on with the
308 command line invocation,
312 It can be cleared by setting
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.
319 Exceptional Conditions
321 Errors and interrupts
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,
329 prints ``Interrupt'' and returns to its command level. If the primary
330 input is a file, then
332 will exit when this occurs.
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
344 option. If you were editing the file
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
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
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.)
368 has five distinct modes. The primary mode is
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
375 gathers input lines and places them in the file. The
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
386 The last three modes are
390 modes, entered by the commands of the same name, and, within open and
397 modes allow local editing operations to be performed on the text in the
400 command displays one line at a time on any terminal while
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."
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
414 * As an example, the command
416 can be abbreviated `s'
417 while the shortest available abbreviation for the
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
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
442 command i.e. ``set number'',
446 a regular expression in a
449 or a target address for a
451 command, i.e. ``1,5 copy 25''.
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.
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.
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.
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).
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.
498 and the shell escape `!'
499 must be the last command on a line, as they are not terminated by a `|'.
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
507 This feedback helps to detect undesirably large changes so that they may
508 be quickly and easily reversed with an
510 After commands with more global effect such as
514 you will be informed if the net change in the number of lines
515 in the buffer during this command exceeds this threshold.
519 Addressing primitives
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.
526 The \fIn\fRth line in the editor's buffer, lines being numbered
529 The last line in the buffer.
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
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
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
556 This makes it easy to refer or return to this previous context.
557 Marks may also be established by the
559 command, using single lower case letters
561 and the marked lines referred to as
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.
585 The following form is a prototype for all
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
596 ignores a ``:'' preceding any command.
598 In the following command descriptions, the
599 default addresses are shown in parentheses,
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
610 is typed as a complete word, it will be changed to
613 ( \fB.\fR ) \fBappend\fR abbr: \fBa\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.
634 toggles the setting for the
636 option during the input of
641 The members of the argument list are printed, with the current argument
642 delimited by `[' and `]'.
645 \fBcd\fR \fIdirectory\fR
649 command is a synonym for
653 ( \fB.\fP , \fB.\fP ) \fBchange\fP \fIcount\fP abbr: \fBc\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
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
681 option is used as the target directory.
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
692 of the specified lines is placed after
697 addresses the last line of the 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.
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
719 Used to begin an editing session on a new file.
721 first checks to see if the buffer has been modified since the last
725 a warning is issued and the
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
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
746 and any null characters in the file are discarded.
747 If none of these errors occurred, the file is considered
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
757 the current line is initially the first line of the file.
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
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
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
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'.
810 (and possibly the trailing \fB/\fR delimiter) is omitted, each line matching
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.
823 commands are permitted in the command list and take input from the terminal.
827 command itself may not appear in
831 command is also not permitted there,
834 instead can be used to reverse the entire
841 are inhibited during a
843 (and possibly the trailing \fB/\fR delimiter) and the value of the
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
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
862 ( \fB.\fR )\|\fBinsert\fR abbr: \fBi\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
873 only in the placement of text.
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.
900 The variant causes a simpler
902 with no white space processing; the characters in the lines are simply
905 ( \fB.\fR ) \fBk\fR \fIx\fR
909 command is a synonym for
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
924 command is used to define macros for use in
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
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''
937 ( \fB.\fR ) \fBmark\fR \fIx\fR
939 Gives the specified line mark
941 a single lower case letter.
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
952 command repositions the specified lines to be after
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.
962 The variant suppresses warnings about the modifications to the buffer not
963 having been written out, discarding (irretrievably) any changes which may
966 \fBn\fR \fIfilelist\fR
968 \fBn\fR \fB+\fIcommand\fR \fIfilelist\fR
972 is expanded and the resulting list replaces the
973 current argument list;
974 the first file in the new list is then edited.
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
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.
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"
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
1007 command has resulted in an error and you don't know how to save your work.
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
1029 to effect movement of lines,
1032 to effect duplication of lines.
1035 is specified, then the last
1041 * But no modifying commands may intervene between the
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
1052 \fBquit\fR abbr: \fBq\fR
1057 No automatic write of the editor buffer to a file is performed.
1060 issues a warning message if the file has changed
1063 command was issued, and does not
1067 will also issue a diagnostic if there are more files in the argument
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.
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.
1084 is given the current file name is used.
1085 The current file name is not changed unless there is none in which
1088 becomes the current name.
1089 The sensibility restrictions for the
1091 command apply here also.
1092 If the file buffer is empty and there is no current name then
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
1104 successfully terminates.
1107 the current line is the last line read.\(dd
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
1120 into the buffer after the specified line.
1121 This is not a variant form of the command, rather a read
1126 a blank or tab before the \fB!\fR is mandatory.
1128 \fBrecover \fIfile\fR
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
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.
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;
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
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.
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
1189 is replaced by replacement pattern
1193 indicator option character `g'
1194 appears, then all instances are substituted;
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.
1205 the current line is the last line substituted.
1207 Lines may be split by substituting
1208 new-line characters into them.
1211 must be escaped by preceding it with a `\e'.
1212 Other metacharacters available in
1216 are described below.
1220 Suspends the editor, returning control to the top level shell.
1223 is set and there are unsaved changes,
1224 a write is done first unless the form
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
1236 are omitted, then the last substitution is repeated.
1237 This is a synonym for the
1241 ( \fB.\fR , \fB.\fR ) \fBt\fR \fIaddr\fR \fIflags\fR
1245 command is a synonym for
1250 The focus of editing switches to the location of
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
1257 command, you must write it out; giving another
1259 command, specifying no
1261 will reuse the previous tag.
1264 The tags file is normally created by a program such as
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
1275 The tag names in the tags file must be sorted alphabetically.
1277 \fBunabbreviate\fR \fIword\fP abbr: \fBuna\fP
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.
1289 commands are considered a single command for the purpose of
1299 which interact with the
1300 file system cannot be undone.
1305 always marks the previous value of the current line `\fB.\fR'
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
1316 the current line regains it's pre-command value after an
1319 \fBunmap\fR \fIlhs\fR
1321 The macro expansion associated by
1327 ( 1 , $ ) \fBv\fR /\fIpat\fR\|/ \fIcmds\fR
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.
1343 is optional and may be `\-' , `\(ua' or `\fB.\fR'
1346 command to specify the placement of the specified line on the screen.
1349 is omitted, the specified line is placed as the first on the screen.
1352 specifies an initial window size; the default is the value of the option
1355 .I "An Introduction to Display Editing with Vi"
1357 To exit this mode, type Q.
1361 \fBvisual\fP +\fIn\fP file
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
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
1376 if the file does not exist,
1377 or if the file is actually a teletype,
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
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
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
1407 Note the difference between \fBw!\fR which overrides checks and
1408 \fBw\ \ !\fR which writes to a command.
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
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
1429 for later retrieval via
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
1454 On some v2 editors, no
1459 \fB!\fR \fIcommand\fR\fR
1461 The remainder of the line after the `!' character is sent to a shell
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
1483 the resulting output then replaces the input lines.
1487 Prints the line number of the
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
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
1509 An end-of-file from a terminal input scrolls through the file.
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
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.
1532 Regular expressions and substitute replacement patterns
1536 A regular expression specifies a set of strings of characters.
1537 A member of this set of strings is said to be
1539 by the regular expression.
1541 remembers two previous regular expressions:
1542 the previous regular expression used in a
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 `??'.
1552 The regular expressions allowed by
1554 are constructed in one of two ways depending on the setting of
1564 gives quick access to a powerful set of regular expression
1568 is that the user must remember that these metacharacters are
1570 and precede them with the character `\e'
1571 to use them as ``ordinary'' characters.
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
1584 that the setting of this option is
1587 \(dg To discern what is true with
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,
1596 the characters `\s+2~\s0' and `&' also lose their special meanings
1597 related to the replacement pattern of a substitute.
1600 Basic regular expression summary
1602 The following basic constructs are used to construct
1604 mode regular expressions.
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.
1613 At the beginning of a pattern
1614 forces the match to succeed only at the beginning of a line.
1616 At the end of a regular expression forces the match to
1617 succeed only at the end of the line.
1619 Matches any single character except
1620 the new-line character.
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
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
1637 A pair of characters separated by `\-' in
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
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
1648 To place any of the characters
1649 `\(ua', `[', or `\-' in
1651 you must escape them with a preceding `\e'.
1653 Combining regular expression primitives
1655 The concatenation of two regular expressions matches the leftmost and
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
1669 A regular expression may be enclosed between the sequences
1670 `\e(' and `\e)' with side effects in the
1672 replacement patterns.
1674 Substitute replacement patterns
1676 The basic metacharacters for the replacement pattern are
1677 `&' and `~'; these are
1678 given as `\e&' and `\e~' when
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.
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
1720 or when a new line is
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
1747 The tab stops going backwards are defined at multiples of the
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
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.
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
1785 This has the same effect as supplying a trailing `p'
1786 to each such command.
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
1801 command, or a \fB^\(ua\fR (switch files) or \fB^]\fR (tag goto) command
1811 In each case, there is an equivalent way of switching when autowrite
1829 \fB:e\ #\fR and a \fB:ta!\fR command from within
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.
1839 does not apply to command input.
1841 \fBdirectory\fR, \fBdir\fR default: dir=/tmp
1843 Specifies the directory in which
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
1856 suffixes on substitute commands to be remembered, and to be toggled
1857 by repeating the suffices. The suffix
1859 makes the substitution be as in the
1861 command, instead of like
1864 \fBerrorbells\fR, \fBeb\fR default: noeb
1866 Error messages are preceded by a bell.*
1872 on errors is not suppressed by setting
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
1894 code, and the \fB( ) { } [[\fR and \fB]]\fR commands in
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
1907 \fBmagic\fR default: magic for \fIex\fR and \fIvi\fR\(dg
1909 \(dg \fINomagic\fR for \fIedit\fR.
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
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
1934 \fBmodeline\fR default: nomodeline
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
1944 preceeded by a tab or a space. This string may be anywhere in the
1945 line and anything after the
1947 is interpeted as editor commands. This option defaults to off because
1948 of unexpected behavior when editting files such as
1951 \fBnumber, nu\fR default: nonumber
1953 Causes all output lines to be printed with their
1955 In addition each input line will be prompted for by supplying the line number
1958 \fBopen\fR default: open
1960 If \fInoopen\fR, the commands
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
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
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.
2019 is set, it will map to
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
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
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
2049 command (double the value of
2052 \fBsections\fR default: sections=SHNHH\0HU
2054 Specifies the section macros for the \fB[[\fR and \fB]]\fR operations
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
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
2076 and by the shift commands.
2078 \fBshowmatch, sm\fR default: nosm
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
2089 \fBslowopen, slow\fR terminal dependent
2091 Affects the display algorithm used in
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"
2099 \fBtabstop,\ ts\fR default: ts=8
2101 The editor expands tabs in the input file to be on
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
2115 A requested tag is searched for in the specified files, sequentially.
2116 By default, files called
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 `!'
2134 \fBwindow\fR default: window=speed dependent
2136 The number of lines in a text window in the
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
2147 only if the speed is slow (300), medium (1200), or high (9600),
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
2164 .I "An Introduction to Text Editing with Vi"
2167 \fBwriteany\fR, \fBwa\fR default: nowa
2169 Inhibit the checks normally made before
2171 commands, allowing a write to any file which the system protection
2172 mechanism will allow.
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
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.
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.
2196 Chuck Haley contributed greatly to the early development of
2198 Bruce Englar encouraged the redesign which led to
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.