xref: /openbsd/usr.bin/vi/docs/USD.doc/vi.man/vi.1 (revision a6445c1d)
1.\"	$OpenBSD: vi.1,v 1.56 2012/01/17 08:18:36 jmc Exp $
2.\"
3.\" Copyright (c) 1994
4.\"     The Regents of the University of California.  All rights reserved.
5.\" Copyright (c) 1994, 1995, 1996
6.\"	Keith Bostic.  All rights reserved.
7.\"
8.\" The vi program is freely redistributable.
9.\" You are welcome to copy, modify and share it with others
10.\" under the conditions listed in the LICENSE file.
11.\" If any company (not individual!) finds vi sufficiently useful
12.\" that you would have purchased it, or if any company wishes to
13.\" redistribute it, contributions to the authors would be appreciated.
14.\"
15.\"     @(#)vi.1	8.51 (Berkeley) 10/10/96
16.\"
17.Dd $Mdocdate: January 17 2012 $
18.Dt VI 1
19.Os
20.Sh NAME
21.Nm ex , vi , view
22.Nd text editors
23.Sh SYNOPSIS
24.Nm ex
25.Op Fl FRrSsv
26.Op Fl c Ar cmd
27.Op Fl t Ar tag
28.Op Fl w Ar size
29.Op Ar
30.Nm vi\ \&
31.Op Fl eFRrS
32.Op Fl c Ar cmd
33.Op Fl t Ar tag
34.Op Fl w Ar size
35.Op Ar
36.Nm view
37.Op Fl eFrS
38.Op Fl c Ar cmd
39.Op Fl t Ar tag
40.Op Fl w Ar size
41.Op Ar
42.Sh DESCRIPTION
43.Nm ex
44is a line-oriented text editor;
45.Nm vi
46is a screen-oriented text editor.
47.Nm ex
48and
49.Nm vi
50are different interfaces to the same program,
51and it is possible to switch back and forth during an edit session.
52.Nm view
53is the equivalent of using the
54.Fl R
55.Pq read-only
56option of
57.Nm vi .
58.Pp
59This manual page is the one provided with the
60.Nm nex Ns / Ns Nm nvi
61versions of the
62.Nm ex Ns / Ns Nm vi
63text editors.
64.Nm nex Ns / Ns Nm nvi
65are intended as bug-for-bug compatible replacements for the original
66Fourth Berkeley Software Distribution
67.Pq 4BSD
68.Nm ex
69and
70.Nm vi
71programs.
72For the rest of this manual page,
73.Nm nex Ns / Ns Nm nvi
74is used only when it's necessary to distinguish it from the historic
75implementations of
76.Nm ex Ns / Ns Nm vi .
77.Pp
78This manual page is intended for users already familiar with
79.Nm ex Ns / Ns Nm vi .
80Anyone else should almost certainly read a good tutorial on the
81editor before this manual page.
82If you're in an unfamiliar environment,
83and you absolutely have to get work done immediately,
84read the section after the options description, entitled
85.Sx FAST STARTUP .
86It's probably enough to get you going.
87.Pp
88The following options are available:
89.Bl -tag -width "-w size "
90.It Fl c Ar cmd
91Execute
92.Ar cmd
93on the first file loaded.
94Particularly useful for initial positioning in the file, although
95.Ar cmd
96is not limited to positioning commands.
97This is the POSIX 1003.2 interface for the historic
98.Dq +cmd
99syntax.
100.Nm nex Ns / Ns Nm nvi
101supports both the old and new syntax.
102.It Fl e
103Start editing in ex mode, as if the command name were
104.Nm ex .
105.It Fl F
106Don't copy the entire file when first starting to edit.
107(The default is to make a copy in case someone else modifies
108the file during your edit session.)
109.\" .It Fl l
110.\" Start editing with the lisp and showmatch options set.
111.It Fl R
112Start editing in read-only mode, as if the command name was
113.Nm view ,
114or the
115.Cm readonly
116option was set.
117.It Fl r
118Recover the specified files, or, if no files are specified,
119list the files that could be recovered.
120If no recoverable files by the specified name exist,
121the file is edited as if the
122.Fl r
123option had not been specified.
124.It Fl S
125Run with the
126.Cm secure
127edit option set, disallowing all access to external programs.
128.It Fl s
129Enter batch mode; applicable only to
130.Nm ex
131edit sessions.
132Batch mode is useful when running
133.Nm ex
134scripts.
135Prompts, informative messages and other user oriented messages are turned off,
136and no startup files or environment variables are read.
137This is the POSIX 1003.2 interface for the historic
138.Dq -
139argument.
140.Nm nex Ns / Ns Nm nvi
141supports both the old and new syntax.
142.It Fl t Ar tag
143Start editing at the specified
144.Ar tag
145(see
146.Xr ctags 1 ) .
147.It Fl v
148Start editing in vi mode, as if the command name was
149.Nm vi .
150.It Fl w Ar size
151Set the initial window size to the specified number of lines.
152.El
153.Pp
154Command input for
155.Nm ex Ns / Ns Nm vi
156is read from the standard input.
157In the
158.Nm vi
159interface, it is an error if standard input is not a terminal.
160In the
161.Nm ex
162interface, if standard input is not a terminal,
163.Nm ex
164will read commands from it regardless; however, the session will be a
165batch mode session, exactly as if the
166.Fl s
167option had been specified.
168.Sh FAST STARTUP
169This section will tell you the minimum amount that you need to
170do simple editing tasks using
171.Nm vi .
172If you've never used any screen editor before,
173you're likely to have problems even with this simple introduction.
174In that case you should find someone that already knows
175.Nm vi
176and have them walk you through this section.
177.Pp
178.Nm vi
179is a screen editor.
180This means that it takes up almost the entire screen,
181displaying part of the file on each screen line,
182except for the last line of the screen.
183The last line of the screen is used for you to give commands to
184.Nm vi ,
185and for
186.Nm vi
187to give information to you.
188.Pp
189The other fact that you need to understand is that
190.Nm vi
191is a modeful editor,
192i.e. you are either entering text or you are executing commands,
193and you have to be in the right mode to do one or the other.
194You will be in command mode when you first start editing a file.
195There are commands that switch you into input mode.
196There is only one key that takes you out of input mode,
197and that is the
198.Aq escape
199key.
200.Pp
201Key names are written using less-than and greater-than signs, e.g.\&
202.Aq escape
203means the
204.Dq escape
205key, usually labeled
206.Dq Esc
207on your
208terminal's keyboard.
209If you're ever confused as to which mode you're in,
210keep entering the
211.Aq escape
212key until
213.Nm vi
214beeps at you.
215Generally,
216.Nm vi
217will beep at you if you try and do something that's not allowed.
218It will also display error messages.
219.Pp
220To start editing a file, enter the following command:
221.Pp
222.Dl $ vi file
223.Pp
224The command you should enter as soon as you start editing is:
225.Pp
226.Dl :set verbose showmode
227.Pp
228This will make the editor give you verbose error messages and display
229the current mode at the bottom of the screen.
230.Pp
231The commands to move around the file are:
232.Bl -tag -width Ds
233.It Cm h
234Move the cursor left one character.
235.It Cm j
236Move the cursor down one line.
237.It Cm k
238Move the cursor up one line.
239.It Cm l
240Move the cursor right one character.
241.It Aq Cm cursor-arrows
242The cursor arrow keys should work, too.
243.It Cm / Ns text
244Search for the string
245.Dq text
246in the file,
247and move the cursor to its first character.
248.El
249.Pp
250The commands to enter new text are:
251.Bl -tag -width "<escape>"
252.It Cm a
253Append new text, after the cursor.
254.It Cm i
255Insert new text, before the cursor.
256.It Cm O
257Open a new line above the line the cursor is on, and start entering text.
258.It Cm o
259Open a new line below the line the cursor is on, and start entering text.
260.It Aq Cm escape
261Once you've entered input mode using one of the
262.Cm a ,
263.Cm i ,
264.Cm O
265or
266.Cm o
267commands, use
268.Aq Cm escape
269to quit entering text and return to command mode.
270.El
271.Pp
272The commands to copy text are:
273.Bl -tag -width Ds
274.It Cm p
275Append the copied line after the line the cursor is on.
276.It Cm yy
277Copy the line the cursor is on.
278.El
279.Pp
280The commands to delete text are:
281.Bl -tag -width Ds
282.It Cm dd
283Delete the line the cursor is on.
284.It Cm x
285Delete the character the cursor is on.
286.El
287.Pp
288The commands to write the file are:
289.Bl -tag -width Ds
290.It Cm :w
291Write the file back to the file with the name that you originally used
292as an argument on the
293.Nm vi
294command line.
295.It Cm :w Ar file_name
296Write the file back to the file with the name
297.Ar file_name .
298.El
299.Pp
300The commands to quit editing and exit the editor are:
301.Bl -tag -width Ds
302.It Cm :q
303Quit editing and leave
304.Nm vi
305(if you've modified the file, but not saved your changes,
306.Nm vi
307will refuse to quit).
308.It Cm :q!
309Quit, discarding any modifications that you may have made.
310.El
311.Pp
312One final caution:
313Unusual characters can take up more than one column on the screen,
314and long lines can take up more than a single screen line.
315The above commands work on
316.Dq physical
317characters and lines,
318i.e. they affect the entire line no matter how many screen lines it takes up
319and the entire character no matter how many screen columns it takes up.
320.Sh REGULAR EXPRESSIONS
321.Nm ex Ns / Ns Nm vi
322supports regular expressions
323.Pq REs ,
324as documented in
325.Xr re_format 7 ,
326for line addresses, as the first part of the
327.Nm ex Cm substitute ,
328.Cm global
329and
330.Cm v
331commands, and in search patterns.
332Basic regular expressions
333.Pq BREs
334are enabled by default;
335extended regular expressions
336.Pq EREs
337are used if the
338.Cm extended
339option is enabled.
340The use of regular expressions can be largely disabled using the
341.Cm magic
342option.
343.Pp
344The following strings have special meanings in the
345.Nm ex Ns / Ns Nm vi
346version of regular expressions:
347.Bl -bullet -offset 6u
348.It
349An empty regular expression is equivalent to the last regular expression used.
350.It
351.Sq \e\(la
352matches the beginning of the word.
353.It
354.Sq \e\(ra
355matches the end of the word.
356.It
357.Sq \(a~
358matches the replacement part of the last
359.Cm substitute
360command.
361.El
362.Sh BUFFERS
363A buffer is an area where commands can save changed or deleted text
364for later use.
365.Nm vi
366buffers are named with a single character preceded by a double quote,
367for example
368.Pf \&" Ns Aq c ;
369.Nm ex
370buffers are the same,
371but without the double quote.
372.Nm nex Ns / Ns Nm nvi
373permits the use of any character without another meaning in the position where
374a buffer name is expected.
375.Pp
376All buffers are either in
377.Em line mode
378or
379.Em character mode .
380Inserting a buffer in line mode into the text creates new lines for each of the
381lines it contains, while a buffer in character mode creates new lines for any
382lines
383.Em other
384than the first and last lines it contains.
385The first and last lines are inserted at the current cursor position, becoming
386part of the current line.
387If there is more than one line in the buffer,
388the current line itself will be split.
389All
390.Nm ex
391commands which store text into buffers do so in line mode.
392The behaviour of
393.Nm vi
394commands depend on their associated motion command:
395.Bl -bullet -offset 6u
396.It
397.Aq Cm control-A ,
398.Cm h ,
399.Cm l ,
400.Cm ,\& ,
401.Cm 0 ,
402.Cm B ,
403.Cm E ,
404.Cm F ,
405.Cm T ,
406.Cm W ,
407.Cm ^ ,
408.Cm b ,
409.Cm e ,
410.Cm f
411and
412.Cm t
413make the destination buffer character-oriented.
414.It
415.Cm j ,
416.Aq Cm control-M ,
417.Cm k ,
418.Cm ' ,
419.Cm - ,
420.Cm G ,
421.Cm H ,
422.Cm L ,
423.Cm M ,
424.Cm _
425and
426.Cm |\&
427make the destination buffer line-oriented.
428.It
429.Cm $ ,
430.Cm % ,
431.Cm ` ,
432.Cm (\& ,
433.Cm )\& ,
434.Cm / ,
435.Cm ?\& ,
436.Cm [[ ,
437.Cm ]] ,
438.Cm {
439and
440.Cm }
441make the destination buffer character-oriented, unless the starting and
442end positions are the first and last characters on a line.
443In that case, the buffer is line-oriented.
444.El
445.Pp
446The
447.Nm ex
448command
449.Cm display buffers
450displays the current mode for each buffer.
451.Pp
452Buffers named
453.Sq a
454through
455.Sq z
456may be referred to using their uppercase equivalent, in which case new content
457will be appended to the buffer, instead of replacing it.
458.Pp
459Buffers named
460.Sq 1
461through
462.Sq 9
463are special.
464A region of text modified using the
465.Cm c
466.Pq change
467or
468.Cm d
469.Pq delete
470commands is placed into the numeric buffer
471.Sq 1
472if no other buffer is specified and if it meets one of the following conditions:
473.Bl -bullet -offset 6u
474.It
475It includes characters from more than one line.
476.It
477It is specified using a line-oriented motion.
478.It
479It is specified using one of the following motion commands:
480.Aq Cm control-A ,
481.Cm ` Ns Aq Cm character ,
482.Cm n ,
483.Cm N ,
484.Cm % ,
485.Cm / ,
486.Cm { ,
487.Cm } ,
488.Cm \&( ,
489.Cm \&) ,
490and
491.Cm \&? .
492.El
493.Pp
494Before this copy is done, the previous contents of buffer
495.Sq 1
496are moved into buffer
497.Sq 2 ,
498.Sq 2
499into buffer
500.Sq 3 ,
501and so on.
502The contents of buffer
503.Sq 9
504are discarded.
505Note that this rotation occurs
506.Em regardless
507of the user specifying another buffer.
508In
509.Nm vi ,
510text may be explicitly stored into the numeric buffers.
511In this case, the buffer rotation occurs before the replacement of the buffer's
512contents.
513The numeric buffers are only available in
514.Nm vi
515mode.
516.Sh VI COMMANDS
517The following section describes the commands available in the command
518mode of the
519.Nm vi
520editor.
521The following words have a special meaning in the commands
522description:
523.Pp
524.Bl -tag -width bigword -compact -offset 3u
525.It Ar bigword
526A set of non-whitespace characters.
527.It Ar buffer
528Temporary area where commands may place text.
529If not specified, the default buffer is used.
530See also
531.Sx BUFFERS ,
532above.
533.It Ar count
534A positive number used to specify the desired number of iterations
535of a command.
536It defaults to 1 if not specified.
537.It Ar motion
538A cursor movement command which indicates the other end of the affected region
539of text, the first being the current cursor position.
540Repeating the command character makes it affect the whole
541current line.
542.It Ar word
543A sequence of letters, digits or underscores.
544.El
545.Pp
546.Ar buffer
547and
548.Ar count ,
549if both present, may be specified in any order.
550.Ar motion
551and
552.Ar count ,
553if both present, are effectively multiplied together
554and considered part of the motion.
555.Pp
556.Bl -tag -width Ds -compact
557.It Xo
558.Aq Cm control-A
559.Xc
560Search forward
561for the word starting at the cursor position.
562.Pp
563.It Xo
564.Op Ar count
565.Aq Cm control-B
566.Xc
567Page backwards
568.Ar count
569screens.
570Two lines of overlap are maintained, if possible.
571.Pp
572.It Xo
573.Op Ar count
574.Aq Cm control-D
575.Xc
576Scroll forward
577.Ar count
578lines.
579If
580.Ar count
581is not given, scroll forward the number of lines specified by the last
582.Aq Cm control-D
583or
584.Aq Cm control-U
585command.
586If this is the first
587.Aq Cm control-D
588command, scroll half the number of lines in the current screen.
589.Pp
590.It Xo
591.Op Ar count
592.Aq Cm control-E
593.Xc
594Scroll forward
595.Ar count
596lines, leaving the current line and column as is, if possible.
597.Pp
598.It Xo
599.Op Ar count
600.Aq Cm control-F
601.Xc
602Page forward
603.Ar count
604screens.
605Two lines of overlap are maintained, if possible.
606.Pp
607.It Aq Cm control-G
608Display the following file information:
609the file name (as given to
610.Nm vi ) ;
611whether the file has been modified since it was last written;
612if the file is readonly;
613the current line number;
614the total number of lines in the file;
615and the current line number as a percentage of the total lines in the file.
616.Pp
617.It Xo
618.Op Ar count
619.Aq Cm control-H
620.Xc
621.It Xo
622.Op Ar count
623.Cm h
624.Xc
625Move the cursor back
626.Ar count
627characters in the current line.
628.Pp
629.It Xo
630.Op Ar count
631.Aq Cm control-J
632.Xc
633.It Xo
634.Op Ar count
635.Aq Cm control-N
636.Xc
637.It Xo
638.Op Ar count
639.Cm j
640.Xc
641Move the cursor down
642.Ar count
643lines without changing the current column.
644.Pp
645.It Aq Cm control-L
646.It Aq Cm control-R
647Repaint the screen.
648.Pp
649.It Xo
650.Op Ar count
651.Aq Cm control-M
652.Xc
653.It Xo
654.Op Ar count
655.Cm +
656.Xc
657Move the cursor down
658.Ar count
659lines to the first non-blank character of that line.
660.Pp
661.It Xo
662.Op Ar count
663.Aq Cm control-P
664.Xc
665.It Xo
666.Op Ar count
667.Cm k
668.Xc
669Move the cursor up
670.Ar count
671lines, without changing the current column.
672.Pp
673.It Aq Cm control-T
674Return to the most recent tag context.
675.Pp
676.It Xo
677.Op Ar count
678.Aq Cm control-U
679.Xc
680Scroll backwards
681.Ar count
682lines.
683If
684.Ar count
685is not given, scroll backwards the number of lines specified by the last
686.Aq Cm control-D
687or
688.Aq Cm control-U
689command.
690If this is the first
691.Aq Cm control-U
692command, scroll half the number of lines in the current screen.
693.Pp
694.It Aq Cm control-W
695Switch to the next lower screen in the window,
696or to the first screen if there are no lower screens in the window.
697.Pp
698.It Xo
699.Op Ar count
700.Aq Cm control-Y
701.Xc
702Scroll backwards
703.Ar count
704lines, leaving the current line and column as is, if possible.
705.Pp
706.It Aq Cm control-Z
707Suspend the current editor session.
708.Pp
709.It Aq Cm escape
710Execute the
711.Nm ex
712command being entered, or cancel it if it is only partial.
713.Pp
714.It Aq Cm control-]
715Push a tag reference onto the tag stack.
716.Pp
717.It Aq Cm control-^
718Switch to the most recently edited file.
719.Pp
720.It Xo
721.Op Ar count
722.Aq Cm space
723.Xc
724.It Xo
725.Op Ar count
726.Cm l
727.Xc
728Move the cursor forward
729.Ar count
730characters without changing the current line.
731.Pp
732.It Xo
733.Op Ar count
734.Cm !\&
735.Ar motion shell-argument(s)
736.Aq Li carriage-return
737.Xc
738Replace the lines spanned by
739.Ar count
740and
741.Ar motion
742with the output
743.Pq standard output and standard error
744of the program named by the
745.Cm shell
746option, called with a
747.Fl c
748flag followed by the
749.Ar shell-argument(s)
750.Pq bundled into a single argument .
751Within
752.Ar shell-argument(s) ,
753the
754.Sq % ,
755.Sq #
756and
757.Sq !\&
758characters are expanded to the current file name,
759the previous current file name,
760and the command text of the previous
761.Cm !\&
762or
763.Cm :!
764commands, respectively.
765The special meaning of
766.Sq % ,
767.Sq #
768and
769.Sq !\&
770can be overridden by escaping them with a backslash.
771.Pp
772.It Xo
773.Op Ar count
774.Cm #
775.Sm off
776.Cm # | + | -
777.Sm on
778.Xc
779Increment
780.Pq trailing So # Sc or So + Sc
781or decrement
782.Pq trailing Sq -
783the number under the cursor by
784.Ar count ,
785starting at the cursor position or at the first non-blank
786character following it.
787Numbers with a leading
788.Sq 0x
789or
790.Sq 0X
791are interpreted as hexadecimal numbers.
792Numbers with a leading
793.Sq 0
794are interpreted as octal numbers unless they contain a non-octal digit.
795Other numbers may be prefixed with a
796.Sq +
797or
798.Sq -
799sign.
800.Pp
801.It Xo
802.Op Ar count
803.Cm $
804.Xc
805Move the cursor to the end of a line.
806If
807.Ar count
808is specified, additionally move the cursor down
809.Ar count
810\- 1 lines.
811.Pp
812.It Cm %
813Move to the parenthesis, square bracket or curly brace matching
814the one found at the cursor position or the closest to the right of it.
815.Pp
816.It Cm &
817Repeat the previous substitution command on the current line.
818.Pp
819.It Xo
820.Cm ' Ns Aq Ar character
821.Xc
822.It Xo
823.Cm ` Ns Aq Ar character
824.Xc
825Return to the cursor position marked by the character
826.Ar character ,
827or, if
828.Ar character
829is
830.Sq '
831or
832.Sq ` ,
833to the position of the cursor before the last of the following commands:
834.Aq Cm control-A ,
835.Aq Cm control-T ,
836.Aq Cm control-] ,
837.Cm % ,
838.Cm ' ,
839.Cm ` ,
840.Cm (\& ,
841.Cm )\& ,
842.Cm / ,
843.Cm ?\& ,
844.Cm G ,
845.Cm H ,
846.Cm L ,
847.Cm [[ ,
848.Cm ]] ,
849.Cm { ,
850.Cm } .
851The first form returns to the first non-blank character of the line marked by
852.Ar character .
853The second form returns to the line and column marked by
854.Ar character .
855.Pp
856.It Xo
857.Op Ar count
858.Cm \&(
859.Xc
860.It Xo
861.Op Ar count
862.Cm \&)
863.Xc
864Move
865.Ar count
866sentences backward or forward, respectively.
867A sentence is an area of text that begins with the first nonblank character
868following the previous sentence, paragraph, or section
869boundary and continues until the next period, exclamation mark,
870or question mark character, followed by any number of closing parentheses,
871brackets, double or single quote characters, followed by
872either an end-of-line or two whitespace characters.
873Groups of empty lines
874.Pq or lines containing only whitespace characters
875are treated as a single sentence.
876.Pp
877.It Xo
878.Op Ar count
879.Cm ,\&
880.Xc
881Reverse find character
882(i.e. the last
883.Cm F ,
884.Cm f ,
885.Cm T
886or
887.Cm t
888command)
889.Ar count
890times.
891.Pp
892.It Xo
893.Op Ar count
894.Cm -
895.Xc
896Move to the first non-blank character of the previous line,
897.Ar count
898times.
899.Pp
900.It Xo
901.Op Ar count
902.Cm .\&
903.Xc
904Repeat the last
905.Nm vi
906command that modified text.
907.Ar count
908replaces both the
909.Ar count
910argument of the repeated command and that of the associated
911.Ar motion .
912If the
913.Cm .\&
914command repeats the
915.Cm u
916command, the change log is rolled forward or backward, depending on the action
917of the
918.Cm u
919command.
920.Pp
921.It Xo
922.Pf / Ns Ar RE
923.Aq Li carriage-return
924.Xc
925.It Xo
926.Pf / Ns Ar RE Ns /
927.Op Ar offset
928.Op Cm z
929.Aq Li carriage-return
930.Xc
931.It Xo
932.Pf ?\& Ns Ar RE
933.Aq Li carriage-return
934.Xc
935.It Xo
936.Pf ?\& Ns Ar RE Ns ?\&
937.Op Ar offset
938.Op Cm z
939.Aq Li carriage-return
940.Xc
941.It Cm N
942.It Cm n
943Search forward
944.Pq Sq /
945or backward
946.Pq Sq ?\&
947for a regular expression.
948.Cm n
949and
950.Cm N
951repeat the last search in the same or opposite directions, respectively.
952If
953.Ar RE
954is empty, the last search regular expression is used.
955If
956.Ar offset
957is specified, the cursor is placed
958.Ar offset
959lines before or after the matched regular expression.
960If either
961.Cm n
962or
963.Cm N
964commands are used as motion components for the
965.Cm !\&
966command, there will be no prompt for the text of the command and the previous
967.Cm !\&
968will be executed.
969Multiple search patterns may be grouped together by delimiting them with
970semicolons and zero or more whitespace characters.
971These patterns are evaluated from left to right with the final cursor position
972determined by the last search pattern.
973A
974.Cm z
975command may be appended to the closed search expressions to reposition the
976result line.
977.Pp
978.It Cm 0
979Move to the first character in the current line.
980.Pp
981.It Cm :\&
982Execute an
983.Nm ex
984command.
985.Pp
986.It Xo
987.Op Ar count
988.Cm ;\&
989.Xc
990Repeat the last character find
991(i.e. the last
992.Cm F ,
993.Cm f ,
994.Cm T
995or
996.Cm t
997command)
998.Ar count
999times.
1000.Pp
1001.It Xo
1002.Op Ar count
1003.Cm <
1004.Ar motion
1005.Xc
1006.It Xo
1007.Op Ar count
1008.Cm >
1009.Ar motion
1010.Xc
1011Shift
1012.Ar count
1013lines left or right, respectively, by an amount of
1014.Cm shiftwidth .
1015.Pp
1016.It Cm @ Ar buffer
1017Execute a named
1018.Ar buffer
1019as
1020.Nm vi
1021commands.
1022The buffer may include
1023.Nm ex
1024commands too, but they must be expressed as a
1025.Cm \&:
1026command.
1027If
1028.Ar buffer
1029is
1030.Sq @
1031or
1032.Sq * ,
1033then the last buffer executed shall be used.
1034.Pp
1035.It Xo
1036.Op Ar count
1037.Cm A
1038.Xc
1039Enter input mode, appending the text after the end of the line.
1040If a
1041.Ar count
1042argument is given,
1043the characters input are repeated
1044.Ar count
1045\- 1 times after input mode is exited.
1046.Pp
1047.It Xo
1048.Op Ar count
1049.Cm B
1050.Xc
1051Move backwards
1052.Ar count
1053bigwords.
1054.Pp
1055.It Xo
1056.Op Ar buffer
1057.Cm C
1058.Xc
1059Change text from the current position to the end-of-line.
1060If
1061.Ar buffer
1062is specified,
1063.Dq yank
1064the deleted text into
1065.Ar buffer .
1066.Pp
1067.It Xo
1068.Op Ar buffer
1069.Cm D
1070.Xc
1071Delete text from the current position to the end-of-line.
1072If
1073.Ar buffer
1074is specified,
1075.Dq yank
1076the deleted text into
1077.Ar buffer .
1078.Pp
1079.It Xo
1080.Op Ar count
1081.Cm E
1082.Xc
1083Move forward
1084.Ar count
1085end-of-bigwords.
1086.Pp
1087.It Xo
1088.Op Ar count
1089.Cm F Aq Ar character
1090.Xc
1091Search
1092.Ar count
1093times backward through the current line for
1094.Ar character .
1095.Pp
1096.It Xo
1097.Op Ar count
1098.Cm G
1099.Xc
1100Move to line
1101.Ar count ,
1102or the last line of the file if
1103.Ar count
1104is not specified.
1105.Pp
1106.It Xo
1107.Op Ar count
1108.Cm H
1109.Xc
1110Move to the screen line
1111.Ar count
1112\- 1 lines below the top of the screen.
1113.Pp
1114.It Xo
1115.Op Ar count
1116.Cm I
1117.Xc
1118Enter input mode, inserting the text at the beginning of the line.
1119If a
1120.Ar count
1121argument is given,
1122the characters input are repeated
1123.Ar count
1124\- 1 more times.
1125.Pp
1126.It Xo
1127.Op Ar count
1128.Cm J
1129.Xc
1130Join
1131.Ar count
1132lines with the current line.
1133The spacing between two joined lines is set to two whitespace characters if the
1134former ends with a question mark, a period or an exclamation mark.
1135It is set to one whitespace character otherwise.
1136.Pp
1137.It Xo
1138.Op Ar count
1139.Cm L
1140.Xc
1141Move to the screen line
1142.Ar count
1143\- 1 lines above the bottom of the screen.
1144.Pp
1145.It Cm M
1146Move to the screen line in the middle of the screen.
1147.Pp
1148.It Xo
1149.Op Ar count
1150.Cm O
1151.Xc
1152Enter input mode, appending text in a new line above the current line.
1153If a
1154.Ar count
1155argument is given,
1156the characters input are repeated
1157.Ar count
1158\- 1 more times.
1159.Pp
1160.It Xo
1161.Op Ar buffer
1162.Cm P
1163.Xc
1164Insert text from
1165.Ar buffer
1166before the current column if
1167.Ar buffer
1168is character-oriented or before the current line if it is line-oriented.
1169.Pp
1170.It Cm Q
1171Exit
1172.Nm vi
1173.Pq or visual
1174mode and switch to
1175.Nm ex
1176mode.
1177.Pp
1178.It Xo
1179.Op Ar count
1180.Cm R
1181.Xc
1182Enter input mode, replacing the characters in the current line.
1183If a
1184.Ar count
1185argument is given,
1186the characters input are repeated
1187.Ar count
1188\- 1 more times upon exit from insert mode.
1189.Pp
1190.It Xo
1191.Op Ar buffer
1192.Op Ar count
1193.Cm S
1194.Xc
1195Substitute
1196.Ar count
1197lines.
1198If
1199.Ar buffer
1200is specified,
1201.Dq yank
1202the deleted text into
1203.Ar buffer .
1204.Pp
1205.It Xo
1206.Op Ar count
1207.Cm T
1208.Aq Ar character
1209.Xc
1210Search backwards,
1211.Ar count
1212times, through the current line for the character after the specified
1213.Ar character .
1214.Pp
1215.It Cm U
1216Restore the current line to its state before the cursor last moved to it.
1217.Pp
1218.It Xo
1219.Op Ar count
1220.Cm W
1221.Xc
1222Move forward
1223.Ar count
1224bigwords.
1225.Pp
1226.It Xo
1227.Op Ar buffer
1228.Op Ar count
1229.Cm X
1230.Xc
1231Delete
1232.Ar count
1233characters before the cursor, on the current line.
1234If
1235.Ar buffer
1236is specified,
1237.Dq yank
1238the deleted text into
1239.Ar buffer .
1240.Pp
1241.It Xo
1242.Op Ar buffer
1243.Op Ar count
1244.Cm Y
1245.Xc
1246Copy (or
1247.Dq yank )
1248.Ar count
1249lines into
1250.Ar buffer .
1251.Pp
1252.It Cm ZZ
1253Write the file and exit
1254.Nm vi
1255if there are no more files to edit.
1256Entering two
1257.Dq quit
1258commands in a row ignores any remaining file to edit.
1259.Pp
1260.It Xo
1261.Op Ar count
1262.Cm [[
1263.Xc
1264Back up
1265.Ar count
1266section boundaries.
1267.Pp
1268.It Xo
1269.Op Ar count
1270.Cm ]]
1271.Xc
1272Move forward
1273.Ar count
1274section boundaries.
1275.Pp
1276.It Cm ^
1277Move to the first non-blank character on the current line.
1278.Pp
1279.It Xo
1280.Op Ar count
1281.Cm _
1282.Xc
1283Move down
1284.Ar count
1285\- 1 lines, to the first non-blank character.
1286.Pp
1287.It Xo
1288.Op Ar count
1289.Cm a
1290.Xc
1291Enter input mode, appending the text after the cursor.
1292If a
1293.Ar count
1294argument is given,
1295the characters input are repeated
1296.Ar count
1297\-1 more times.
1298.Pp
1299.It Xo
1300.Op Ar count
1301.Cm b
1302.Xc
1303Move backwards
1304.Ar count
1305words.
1306.Pp
1307.It Xo
1308.Op Ar buffer
1309.Op Ar count
1310.Cm c
1311.Ar motion
1312.Xc
1313Change the region of text described by
1314.Ar count
1315and
1316.Ar motion .
1317If
1318.Ar buffer
1319is specified,
1320.Dq yank
1321the changed text into
1322.Ar buffer .
1323.Pp
1324.It Xo
1325.Op Ar buffer
1326.Op Ar count
1327.Cm d
1328.Ar motion
1329.Xc
1330Delete the region of text described by
1331.Ar count
1332and
1333.Ar motion .
1334If
1335.Ar buffer
1336is specified,
1337.Dq yank
1338the deleted text into
1339.Ar buffer .
1340.Pp
1341.It Xo
1342.Op Ar count
1343.Cm e
1344.Xc
1345Move forward
1346.Ar count
1347end-of-words.
1348.Pp
1349.It Xo
1350.Op Ar count
1351.Cm f Aq Ar character
1352.Xc
1353Search forward,
1354.Ar count
1355times, through the rest of the current line for
1356.Aq Ar character .
1357.Pp
1358.It Xo
1359.Op Ar count
1360.Cm i
1361.Xc
1362Enter input mode, inserting the text before the cursor.
1363If a
1364.Ar count
1365argument is given,
1366the characters input are repeated
1367.Ar count
1368\-1 more times.
1369.Pp
1370.It Xo
1371.Cm m
1372.Aq Ar character
1373.Xc
1374Save the current context
1375.Pq line and column
1376as
1377.Aq Ar character .
1378.Pp
1379.It Xo
1380.Op Ar count
1381.Cm o
1382.Xc
1383Enter input mode, appending text in a new line under the current line.
1384If a
1385.Ar count
1386argument is given,
1387the characters input are repeated
1388.Ar count
1389\- 1 more times.
1390.Pp
1391.It Xo
1392.Op Ar buffer
1393.Cm p
1394.Xc
1395Append text from
1396.Ar buffer .
1397Text is appended after the current column if
1398.Ar buffer
1399is character oriented, or the after current line otherwise.
1400.Pp
1401.It Xo
1402.Op Ar count
1403.Cm r
1404.Aq Ar character
1405.Xc
1406Replace
1407.Ar count
1408characters by
1409.Ar character .
1410.Pp
1411.It Xo
1412.Op Ar buffer
1413.Op Ar count
1414.Cm s
1415.Xc
1416Substitute
1417.Ar count
1418characters in the current line starting with the current character.
1419If
1420.Ar buffer
1421is specified,
1422.Dq yank
1423the substituted text into
1424.Ar buffer .
1425.Pp
1426.It Xo
1427.Op Ar count
1428.Cm t
1429.Aq Ar character
1430.Xc
1431Search forward,
1432.Ar count
1433times, through the current line for the character immediately before
1434.Aq Ar character .
1435.Pp
1436.It Cm u
1437Undo the last change made to the file.
1438If repeated, the
1439.Cm u
1440command alternates between these two states.
1441The
1442.Cm .\&
1443command, when used immediately after
1444.Cm u ,
1445causes the change log to be rolled forward or backward, depending on the action
1446of the
1447.Cm u
1448command.
1449.Pp
1450.It Xo
1451.Op Ar count
1452.Cm w
1453.Xc
1454Move forward
1455.Ar count
1456words.
1457.Pp
1458.It Xo
1459.Op Ar buffer
1460.Op Ar count
1461.Cm x
1462.Xc
1463Delete
1464.Ar count
1465characters at the current cursor position, but no more than there are till the
1466end of the line.
1467.Pp
1468.It Xo
1469.Op Ar buffer
1470.Op Ar count
1471.Cm y
1472.Ar motion
1473.Xc
1474Copy (or
1475.Dq yank )
1476a text region specified by
1477.Ar count
1478and
1479.Ar motion
1480into a buffer.
1481.Pp
1482.It Xo
1483.Op Ar count1
1484.Cm z
1485.Op Ar count2
1486.Cm type
1487.Xc
1488Redraw, optionally repositioning and resizing the screen.
1489If
1490.Ar count2
1491is specified, limit the screen size to
1492.Ar count2
1493lines.
1494The following
1495.Cm type
1496characters may be used:
1497.Bl -tag -width Ds
1498.It Cm +
1499If
1500.Ar count1
1501is specified, place the line
1502.Ar count1
1503at the top of the screen.
1504Otherwise, display the screen after the current screen.
1505.It Aq Cm carriage-return
1506Place the line
1507.Ar count1
1508at the top of the screen.
1509.It Cm .\&
1510Place the line
1511.Ar count1
1512in the center of the screen.
1513.It Cm -
1514Place the line
1515.Ar count1
1516at the bottom of the screen.
1517.It Cm ^
1518If
1519.Ar count1
1520is given,
1521display the screen before the screen before
1522.Ar count1
1523.Pq i.e. 2 screens before .
1524Otherwise, display the screen before the current screen.
1525.El
1526.Pp
1527.It Xo
1528.Op Ar count
1529.Cm {\&
1530.Xc
1531Move backward
1532.Ar count
1533paragraphs.
1534.Pp
1535.It Xo
1536.Op Ar column
1537.Cm |\&
1538.Xc
1539Move to a specific
1540.Ar column
1541position on the current line.
1542If
1543.Ar column
1544is omitted,
1545move to the start of the current line.
1546.Pp
1547.It Xo
1548.Op Ar count
1549.Cm }\&
1550.Xc
1551Move forward
1552.Ar count
1553paragraphs.
1554.Pp
1555.It Xo
1556.Op Ar count
1557.Cm ~
1558.Ar motion
1559.Xc
1560If the
1561.Cm tildeop
1562option is not set, reverse the case of the next
1563.Ar count
1564character(s) and no
1565.Ar motion
1566can be specified.
1567Otherwise
1568.Ar motion
1569is mandatory and
1570.Cm ~
1571reverses the case of the characters in a text region specified by the
1572.Ar count
1573and
1574.Ar motion .
1575.Pp
1576.It Aq Cm interrupt
1577Interrupt the current operation.
1578The
1579.Aq interrupt
1580character is usually
1581.Aq control-C .
1582.El
1583.Sh VI TEXT INPUT COMMANDS
1584The following section describes the commands available in the text input mode
1585of the
1586.Nm vi
1587editor.
1588.Pp
1589.Bl -tag -width Ds -compact
1590.It Aq Cm nul
1591Replay the previous input.
1592.Pp
1593.It Aq Cm control-D
1594Erase to the previous
1595.Ar shiftwidth
1596column boundary.
1597.Pp
1598.It Cm ^ Ns Aq Cm control-D
1599Erase all of the autoindent characters, and reset the autoindent level.
1600.Pp
1601.It Cm 0 Ns Aq Cm control-D
1602Erase all of the autoindent characters.
1603.Pp
1604.It Aq Cm control-T
1605Insert sufficient
1606.Aq tab
1607and
1608.Aq space
1609characters to move forward to the next
1610.Ar shiftwidth
1611column boundary.
1612.Pp
1613.It Aq Cm erase
1614.It Aq Cm control-H
1615Erase the last character.
1616.Pp
1617.It Aq Cm literal next
1618Escape the next character from any special meaning.
1619The
1620.Aq literal\ \&next
1621character is usually
1622.Aq control-V .
1623.Pp
1624.It Aq Cm escape
1625Resolve all text input into the file, and return to command mode.
1626.Pp
1627.It Aq Cm line erase
1628Erase the current line.
1629.Pp
1630.It Aq Cm control-W
1631.It Aq Cm word erase
1632Erase the last word.
1633The definition of word is dependent on the
1634.Cm altwerase
1635and
1636.Cm ttywerase
1637options.
1638.Pp
1639.Sm off
1640.It Xo
1641.Aq Cm control-X
1642.Bq Cm 0-9A-Fa-f
1643.Cm +
1644.Xc
1645.Sm on
1646Insert a character with the specified hexadecimal value into the text.
1647.Pp
1648.It Aq Cm interrupt
1649Interrupt text input mode, returning to command mode.
1650The
1651.Aq interrupt
1652character is usually
1653.Aq control-C .
1654.El
1655.Sh EX COMMANDS
1656The following section describes the commands available in the
1657.Nm ex
1658editor.
1659In each entry below, the tag line is a usage synopsis for the command.
1660.Pp
1661.Bl -tag -width Ds -compact
1662.It Aq Cm end-of-file
1663Scroll the screen.
1664.Pp
1665.It Cm !\& Ar argument(s)
1666.It Xo
1667.Op Ar range
1668.Cm !\&
1669.Ar argument(s)
1670.Xc
1671Execute a shell command, or filter lines through a shell command.
1672.Pp
1673.It Cm \&"
1674A comment.
1675.Pp
1676.It Xo
1677.Op Ar range
1678.Cm nu Ns Op Cm mber
1679.Op Ar count
1680.Op Ar flags
1681.Xc
1682.It Xo
1683.Op Ar range
1684.Cm #
1685.Op Ar count
1686.Op Ar flags
1687.Xc
1688Display the selected lines, each preceded with its line number.
1689.Pp
1690.It Cm @ Ar buffer
1691.It Cm * Ar buffer
1692Execute a buffer.
1693.Pp
1694.It Xo
1695.Op Ar range
1696.Cm < Ns Op Cm < ...
1697.Op Ar count
1698.Op Ar flags
1699.Xc
1700Shift lines left.
1701.Pp
1702.It Xo
1703.Op Ar line
1704.Cm =
1705.Op Ar flags
1706.Xc
1707Display the line number of
1708.Ar line .
1709If
1710.Ar line
1711is not specified, display the line number of the last line in the file.
1712.Pp
1713.It Xo
1714.Op Ar range
1715.Cm > Ns Op Cm > ...
1716.Op Ar count
1717.Op Ar flags
1718.Xc
1719Shift lines right.
1720.Pp
1721.It Xo
1722.Cm ab Ns Op Cm breviate
1723.Ar lhs rhs
1724.Xc
1725.Nm vi
1726only.
1727Add
1728.Ar lhs
1729as an abbreviation for
1730.Ar rhs
1731to the abbreviation list.
1732.Pp
1733.It Xo
1734.Op Ar line
1735.Cm a Ns Op Cm ppend Ns
1736.Op Cm !\&
1737.Xc
1738The input text is appended after the specified line.
1739.Pp
1740.It Cm ar Ns Op Cm gs
1741Display the argument list.
1742.Pp
1743.It Cm bg
1744.Nm vi
1745only.
1746Background the current screen.
1747.Pp
1748.It Xo
1749.Op Ar range
1750.Cm c Ns Op Cm hange Ns
1751.Op Cm !\&
1752.Op Ar count
1753.Xc
1754The input text replaces the specified range.
1755.Pp
1756.It Xo
1757.Cm chd Ns Op Cm ir Ns
1758.Op Cm !\&
1759.Op Ar directory
1760.Xc
1761.It Xo
1762.Cm cd Ns Op Cm !\&
1763.Op Ar directory
1764.Xc
1765Change the current working directory.
1766.Pp
1767.It Xo
1768.Op Ar range
1769.Cm co Ns Op Cm py
1770.Ar line
1771.Op Ar flags
1772.Xc
1773.It Xo
1774.Op Ar range
1775.Cm t
1776.Ar line
1777.Op Ar flags
1778.Xc
1779Copy the specified lines after the destination
1780.Ar line .
1781.Pp
1782.It Xo
1783.Cm cs Ns Op Cm cope
1784.Cm add | find | help | kill | reset
1785.Xc
1786Execute a Cscope command.
1787.Pp
1788.It Xo
1789.Op Ar range
1790.Cm d Ns Op Cm elete
1791.Op Ar buffer
1792.Op Ar count
1793.Op Ar flags
1794.Xc
1795Delete the lines from the file.
1796.Pp
1797.It Xo
1798.Cm di Ns Op Cm splay
1799.Cm b Ns Oo Cm uffers Oc |
1800.Cm c Ns Oo Cm onnections Oc |
1801.Cm s Ns Oo Cm creens Oc |
1802.Cm t Ns Op Cm ags
1803.Xc
1804Display buffers, Cscope connections, screens or tags.
1805.Pp
1806.It Xo
1807.Op Cm Ee Ns
1808.Op Cm dit Ns
1809.Op Cm !\&
1810.Op Ar +cmd
1811.Op Ar file
1812.Xc
1813.It Xo
1814.Op Cm Ee Ns
1815.Cm x Ns Op Cm !\&
1816.Op Ar +cmd
1817.Op Ar file
1818.Xc
1819Edit a different file.
1820.Pp
1821.It Xo
1822.Cm exu Ns Op Cm sage
1823.Op Ar command
1824.Xc
1825Display usage for an
1826.Nm ex
1827command.
1828.Pp
1829.It Xo
1830.Cm f Ns Op Cm ile
1831.Op Ar file
1832.Xc
1833Display and optionally change the file name.
1834.Pp
1835.It Xo
1836.Op Cm Ff Ns
1837.Cm g
1838.Op Ar name
1839.Xc
1840.Nm vi
1841mode only.
1842Foreground the specified screen.
1843.Pp
1844.It Xo
1845.Op Ar range
1846.Cm g Ns Op Cm lobal
1847.No / Ns Ar pattern Ns /
1848.Op Ar commands
1849.Xc
1850.It Xo
1851.Op Ar range
1852.Cm v
1853.No / Ns Ar pattern Ns /
1854.Op Ar commands
1855.Xc
1856Apply commands to lines matching
1857.Pq Sq global
1858or not matching
1859.Pq Sq v
1860a pattern.
1861.Pp
1862.It Cm he Ns Op Cm lp
1863Display a help message.
1864.Pp
1865.It Xo
1866.Op Ar line
1867.Cm i Ns Op Cm nsert Ns
1868.Op Cm !\&
1869.Xc
1870The input text is inserted before the specified line.
1871.Pp
1872.It Xo
1873.Op Ar range
1874.Cm j Ns Op Cm oin Ns
1875.Op Cm !\&
1876.Op Ar count
1877.Op Ar flags
1878.Xc
1879Join lines of text together.
1880.Pp
1881.It Xo
1882.Op Ar range
1883.Cm l Ns Op Cm ist
1884.Op Ar count
1885.Op Ar flags
1886.Xc
1887Display the lines unambiguously.
1888.Pp
1889.It Xo
1890.Cm map Ns Op Cm !\&
1891.Op Ar lhs rhs
1892.Xc
1893Define or display maps (for
1894.Nm vi
1895only).
1896.Pp
1897.It Xo
1898.Op Ar line
1899.Cm ma Ns Op Cm rk
1900.Aq Ar character
1901.Xc
1902.It Xo
1903.Op Ar line
1904.Cm k Aq Ar character
1905.Xc
1906Mark the line with the mark
1907.Aq Ar character .
1908.Pp
1909.It Xo
1910.Op Ar range
1911.Cm m Ns Op Cm ove
1912.Ar line
1913.Xc
1914Move the specified lines after the target line.
1915.Pp
1916.It Xo
1917.Cm mk Ns Op Cm exrc Ns
1918.Op Cm !\&
1919.Ar file
1920.Xc
1921Write the abbreviations, editor options and maps to the specified
1922.Ar file .
1923.Pp
1924.It Xo
1925.Op Cm Nn Ns
1926.Op Cm ext Ns
1927.Op Cm !\&
1928.Op Ar file ...
1929.Xc
1930Edit the next file from the argument list.
1931.\" .Pp
1932.\" .It Xo
1933.\" .Op Ar line
1934.\" .Cm o Ns Op Cm pen
1935.\" .No / Ns Ar pattern Ns /
1936.\" .Op Ar flags
1937.\" .Xc
1938.\" Enter open mode.
1939.Pp
1940.It Cm pre Ns Op Cm serve
1941Save the file in a form that can later be recovered using the
1942.Nm ex
1943.Fl r
1944option.
1945.Pp
1946.It Xo
1947.Op Cm \&Pp Ns
1948.Cm rev Ns Op Cm ious Ns
1949.Op Cm !\&
1950.Xc
1951Edit the previous file from the argument list.
1952.Pp
1953.It Xo
1954.Op Ar range
1955.Cm p Ns Op Cm rint
1956.Op Ar count
1957.Op Ar flags
1958.Xc
1959Display the specified lines.
1960.Pp
1961.It Xo
1962.Op Ar line
1963.Cm pu Ns Op Cm t
1964.Op Ar buffer
1965.Xc
1966Append buffer contents to the current line.
1967.Pp
1968.It Xo
1969.Cm q Ns Op Cm uit Ns
1970.Op Cm !\&
1971.Xc
1972End the editing session.
1973.Pp
1974.It Xo
1975.Op Ar line
1976.Cm r Ns Op Cm ead Ns
1977.Op Cm !\&
1978.Op Ar file
1979.Xc
1980Read a file.
1981.Pp
1982.It Xo
1983.Cm rec Ns Op Cm over
1984.Ar file
1985.Xc
1986Recover
1987.Ar file
1988if it was previously saved.
1989.Pp
1990.It Xo
1991.Cm res Ns Op Cm ize
1992.Op Cm + Ns | Ns Cm - Ns
1993.Ar size
1994.Xc
1995.Nm vi
1996mode only.
1997Grow or shrink the current screen.
1998.Pp
1999.It Xo
2000.Cm rew Ns Op Cm ind Ns
2001.Op Cm !\&
2002.Xc
2003Rewind the argument list.
2004.Pp
2005.It Xo
2006.Cm se Ns Op Cm t
2007.Sm off
2008.Op option Oo = Oo value Oc Oc \ \&...
2009.Sm on
2010.Pf \ \& Op nooption ...
2011.Op option? ...
2012.Op Ar all
2013.Xc
2014Display or set editor options.
2015.Pp
2016.It Cm sh Ns Op Cm ell
2017Run a shell program.
2018.Pp
2019.It Xo
2020.Cm so Ns Op Cm urce
2021.Ar file
2022.Xc
2023Read and execute
2024.Nm ex
2025commands from a file.
2026.Pp
2027.It Xo
2028.Op Ar range
2029.Cm s Ns Op Cm ubstitute
2030.Sm off
2031.Op / Ar pattern No / Ar replace  No /
2032.Sm on
2033.Pf \ \& Op Ar options
2034.Op Ar count
2035.Op Ar flags
2036.Xc
2037.It Xo
2038.Op Ar range
2039.Cm &
2040.Op Ar options
2041.Op Ar count
2042.Op Ar flags
2043.Xc
2044.It Xo
2045.Op Ar range
2046.Cm ~
2047.Op Ar options
2048.Op Ar count
2049.Op Ar flags
2050.Xc
2051Make substitutions.
2052The
2053.Ar replace
2054field may contain any of the following sequences:
2055.Bl -tag -width Ds
2056.It Sq \*(Am
2057The text matched by
2058.Ar pattern .
2059.It Sq \(a~
2060The replacement part of the previous
2061.Cm substitute
2062command.
2063.It Sq %
2064If this is the entire
2065.Ar replace
2066pattern, the replacement part of the previous
2067.Cm substitute
2068command.
2069.It Sq \e\(sh
2070Where
2071.Sq \(sh
2072is an integer from 1 to 9, the text matched by the #'th subexpression in
2073.Ar pattern .
2074.It Sq \eL
2075Causes the characters up to the end of the line of the next occurrence of
2076.Sq \eE
2077or
2078.Sq \ee
2079to be converted to lowercase.
2080.It Sq \el
2081Causes the next character to be converted to lowercase.
2082.It Sq \eU
2083Causes the characters up to the end of the line of the next occurrence of
2084.Sq \eE
2085or
2086.Sq \ee
2087to be converted to uppercase.
2088.It Sq \eu
2089Causes the next character to be converted to uppercase.
2090.El
2091.Pp
2092.It Xo
2093.Cm su Ns Op Cm spend Ns
2094.Op Cm !\&
2095.Xc
2096.It Xo
2097.Cm st Ns Op Cm op Ns
2098.Op Cm !\&
2099.Xc
2100.It Aq Cm suspend
2101Suspend the edit session.
2102The
2103.Aq suspend
2104character is usually
2105.Aq control-Z .
2106.Pp
2107.It Xo
2108.Op Cm Tt Ns
2109.Cm a Ns Op Cm g Ns
2110.Op Cm !\&
2111.Ar tagstring
2112.Xc
2113Edit the file containing the specified tag.
2114.Pp
2115.It Xo
2116.Cm tagn Ns Op Cm ext Ns
2117.Op Cm !\&
2118.Xc
2119Edit the file containing the next context for the current tag.
2120.Pp
2121.It Xo
2122.Cm tagp Ns Op Cm op Ns
2123.Op Cm !\&
2124.Op Ar file | number
2125.Xc
2126Pop to the specified tag in the tags stack.
2127.Pp
2128.It Xo
2129.Cm tagpr Ns Op Cm ev Ns
2130.Op Cm !\&
2131.Xc
2132Edit the file containing the previous context for the current tag.
2133.Pp
2134.It Xo
2135.Cm tagt Ns Op Cm op Ns
2136.Op Cm !\&
2137.Xc
2138Pop to the least recent tag on the tags stack, clearing the stack.
2139.Pp
2140.It Xo
2141.Cm una Ns Op Cm bbreviate
2142.Ar lhs
2143.Xc
2144.Nm vi
2145only.
2146Delete an abbreviation.
2147.Pp
2148.It Cm u Ns Op Cm ndo
2149Undo the last change made to the file.
2150.Pp
2151.It Xo
2152.Cm unm Ns Op Cm ap Ns
2153.Op Cm !\&
2154.Ar lhs
2155.Xc
2156Unmap a mapped string.
2157.Pp
2158.It Cm ve Ns Op Cm rsion
2159Display the version of the
2160.Nm ex Ns / Ns Nm vi
2161editor.
2162.Pp
2163.It Xo
2164.Op Ar line
2165.Cm vi Ns Op Cm sual
2166.Op Ar type
2167.Op Ar count
2168.Op Ar flags
2169.Xc
2170.Nm ex
2171mode only.
2172Enter
2173.Nm vi .
2174.Pp
2175.It Xo
2176.Op Cm Vi Ns
2177.Cm i Ns Op Cm sual Ns
2178.Op Cm !\&
2179.Op Ar +cmd
2180.Op Ar file
2181.Xc
2182.Nm vi
2183mode only.
2184Edit a new file.
2185.Pp
2186.It Xo
2187.Cm viu Ns Op Cm sage
2188.Op Ar command
2189.Xc
2190Display usage for a
2191.Nm vi
2192command.
2193.Pp
2194.It Xo
2195.Op Ar range
2196.Cm w Ns Op Cm rite Ns
2197.Op Cm !\&
2198.Op >>
2199.Op Ar file
2200.Xc
2201.It Xo
2202.Op Ar range
2203.Cm w Ns Op Cm rite
2204.Op Cm !\&
2205.Op Ar file
2206.Xc
2207.It Xo
2208.Op Ar range
2209.Cm wn Ns Op Cm !\&
2210.Op >>
2211.Op Ar file
2212.Xc
2213.It Xo
2214.Op Ar range
2215.Cm wq Ns Op Cm !\&
2216.Op >>
2217.Op Ar file
2218.Xc
2219Write the file.
2220.Pp
2221.It Xo
2222.Op Ar range
2223.Cm x Ns Op Cm it Ns
2224.Op Cm !\&
2225.Op Ar file
2226.Xc
2227Exit the editor,
2228writing the file if it has been modified.
2229.Pp
2230.It Xo
2231.Op Ar range
2232.Cm ya Ns Op Cm nk
2233.Op Ar buffer
2234.Op Ar count
2235.Xc
2236Copy the specified lines to a buffer.
2237.Pp
2238.It Xo
2239.Op Ar line
2240.Cm z
2241.Op Ar type
2242.Op Ar count
2243.Op Ar flags
2244.Xc
2245Adjust the window.
2246.El
2247.Sh SET OPTIONS
2248There are a large number of options that may be set
2249.Pq or unset
2250to change the editor's behavior.
2251This section describes the options, their abbreviations and their
2252default values.
2253.Pp
2254In each entry below, the first part of the tag line is the full name
2255of the option, followed by any equivalent abbreviations.
2256The part in square brackets is the default value of the option.
2257Most of the options are boolean, i.e. they are either on or off,
2258and do not have an associated value.
2259.Pp
2260Options apply to both
2261.Nm ex
2262and
2263.Nm vi
2264modes, unless otherwise specified.
2265.Bl -tag -width Ds
2266.It Cm altwerase Bq off
2267.Nm vi
2268only.
2269Select an alternate word erase algorithm.
2270.It Cm autoindent , ai Bq off
2271Automatically indent new lines.
2272.It Cm autoprint , ap Bq on
2273.Nm ex
2274only.
2275Display the current line automatically.
2276.It Cm autowrite , aw Bq off
2277Write modified files automatically when changing files or suspending the editor
2278session.
2279.It Cm backup Bq \&"\&"
2280Back up files before they are overwritten.
2281.It Cm beautify , bf Bq off
2282Discard control characters.
2283.It Cm cdpath Bq "environment variable CDPATH, or current directory"
2284The directory paths used as path prefixes for the
2285.Cm cd
2286command.
2287.It Cm cedit Bq no default
2288Set the character to edit the colon command-line history.
2289.It Cm columns , co Bq 80
2290Set the number of columns in the screen.
2291.It Cm comment Bq off
2292.Nm vi
2293only.
2294Skip leading comments in shell, C and C++ language files.
2295.It Cm directory , dir Bq "environment variable TMPDIR, or /tmp"
2296The directory where temporary files are created.
2297.It Cm edcompatible , ed Bq off
2298Remember the values of the
2299.Sq c
2300and
2301.Sq g
2302suffixes to the
2303.Cm substitute
2304commands, instead of initializing them as unset for each new command.
2305.It Cm escapetime Bq 1
2306The 10th's of a second
2307.Nm ex Ns / Ns Nm vi
2308waits for a subsequent key to complete an
2309.Aq escape
2310key mapping.
2311.It Cm errorbells , eb Bq off
2312.Nm ex
2313only.
2314Announce error messages with a bell.
2315.It Cm exrc , ex Bq off
2316Read the startup files in the local directory.
2317.It Cm extended Bq off
2318Use extended regular expressions
2319.Pq EREs
2320rather than basic regular expressions
2321.Pq BREs .
2322See
2323.Xr re_format 7
2324for more information on regular expressions.
2325.It Cm filec Bq no default
2326Set the character to perform file path completion on the colon command line.
2327.It Cm flash Bq off
2328Flash the screen instead of beeping the keyboard on error.
2329.It Cm hardtabs , ht Bq 0
2330Set the spacing between hardware tab settings.
2331This option currently has no effect.
2332.It Cm iclower Bq off
2333Makes all regular expressions case-insensitive,
2334as long as an upper-case letter does not appear in the search string.
2335.It Cm ignorecase , ic Bq off
2336Ignore case differences in regular expressions.
2337.It Cm keytime Bq 6
2338The 10th's of a second
2339.Nm ex Ns / Ns Nm vi
2340waits for a subsequent key to complete a key mapping.
2341.It Cm leftright Bq off
2342.Nm vi
2343only.
2344Do left-right scrolling.
2345.It Cm lines , li Bq 24
2346.Nm vi
2347only.
2348Set the number of lines in the screen.
2349.It Cm lisp Bq off
2350.Nm vi
2351only.
2352Modify various search commands and options to work with Lisp.
2353This option is not yet implemented.
2354.It Cm list Bq off
2355Display lines in an unambiguous fashion.
2356.It Cm lock Bq on
2357Attempt to get an exclusive lock on any file being edited, read or written.
2358.It Cm magic Bq on
2359When turned off, all regular expression characters except for
2360.Sq \(ha
2361and
2362.Sq \(Do
2363are treated as ordinary characters.
2364Preceding individual characters by
2365.Sq \e
2366re-enables them.
2367.It Cm matchtime Bq 7
2368.Nm vi
2369only.
2370The 10th's of a second
2371.Nm ex Ns / Ns Nm vi
2372pauses on the matching character when the
2373.Cm showmatch
2374option is set.
2375.It Cm mesg Bq on
2376Permit messages from other users.
2377.It Cm msgcat Bq /usr/share/vi/catalog/
2378Selects a message catalog to be used to display error and informational
2379messages in a specified language.
2380.It Cm modelines , modeline Bq off
2381Read the first and last few lines of each file for
2382.Nm ex
2383commands.
2384This option will never be implemented.
2385.It Cm noprint Bq \&"\&"
2386Characters that are never handled as printable characters.
2387.It Cm number, nu Bq off
2388Precede each line displayed with its current line number.
2389.It Cm octal Bq off
2390Display unknown characters as octal numbers, instead of the default
2391hexadecimal.
2392.It Cm open Bq on
2393.Nm ex
2394only.
2395If this option is not set, the
2396.Cm open
2397and
2398.Cm visual
2399commands are disallowed.
2400.It Cm optimize , opt Bq on
2401.Nm vi
2402only.
2403Optimize text throughput to dumb terminals.
2404This option is not yet implemented
2405.It Cm paragraphs , para Bq "IPLPPPQPP LIpplpipbp"
2406.Nm vi
2407only.
2408Define additional paragraph boundaries for the
2409.Cm {\&
2410and
2411.Cm }\&
2412commands.
2413.It Cm path Bq \&"\&"
2414Define additional directories to search for files being edited.
2415.It Cm print Bq \&"\&"
2416Characters that are always handled as printable characters.
2417.It Cm prompt Bq on
2418.Nm ex
2419only.
2420Display a command prompt.
2421.It Cm readonly , ro Bq off
2422Mark the file and session as read-only.
2423.It Cm recdir Bq /var/tmp/vi.recover
2424The directory where recovery files are stored.
2425.It Cm redraw , re Bq off
2426.Nm vi
2427only.
2428Simulate an intelligent terminal on a dumb one.
2429This option is not yet implemented.
2430.It Cm remap Bq on
2431Remap keys until resolved.
2432.It Cm report Bq 5
2433Set the number of lines about which the editor reports changes or yanks.
2434.It Cm ruler Bq off
2435.Nm vi
2436only.
2437Display a row/column ruler on the colon command line.
2438.It Cm scroll , scr Bq "($LINES \- 1) / 2"
2439Set the number of lines scrolled.
2440.It Cm searchincr Bq off
2441Makes the
2442.Cm /
2443and
2444.Cm ?\&
2445commands incremental.
2446.It Cm sections , sect Bq "NHSHH HUnhsh"
2447.Nm vi
2448only.
2449Define additional section boundaries for the
2450.Cm [[
2451and
2452.Cm ]]
2453commands.
2454.It Cm secure Bq off
2455Turns off all access to external programs.
2456.It Cm shell , sh Bq "environment variable SHELL, or /bin/sh"
2457Select the shell used by the editor.
2458.It Cm shellmeta Bq ~{[*?$`'\&"\e
2459Set the meta characters checked to determine if file name expansion
2460is necessary.
2461.It Cm shiftwidth , sw Bq 8
2462Set the autoindent and shift command indentation width.
2463.It Cm showmatch , sm Bq off
2464.Nm vi
2465only.
2466Note matching
2467.Sq {
2468and
2469.Sq \&(
2470for
2471.Sq }
2472and
2473.Sq )\&
2474characters.
2475.It Cm showmode , smd Bq off
2476.Nm vi
2477only.
2478Display the current editor mode and a
2479.Dq modified
2480flag.
2481.It Cm sidescroll Bq 16
2482.Nm vi
2483only.
2484Set the amount a left-right scroll will shift.
2485.It Cm slowopen , slow Bq off
2486Delay display updating during text input.
2487This option is not yet implemented.
2488.It Cm sourceany Bq off
2489Read startup files not owned by the current user.
2490This option will never be implemented.
2491.It Cm tabstop , ts Bq 8
2492This option sets tab widths for the editor display.
2493.It Cm taglength , tl Bq 0
2494Set the number of significant characters in tag names.
2495.It Cm tags, tag Bq tags
2496Set the list of tags files.
2497.It Xo
2498.Cm term , ttytype , tty
2499.Bq "environment variable TERM"
2500.Xc
2501Set the terminal type.
2502.It Cm terse Bq off
2503This option has historically made editor messages less verbose.
2504It has no effect in this implementation.
2505.It Cm tildeop Bq off
2506Modify the
2507.Cm ~
2508command to take an associated motion.
2509.It Cm timeout , to Bq on
2510Time out on keys which may be mapped.
2511.It Cm ttywerase Bq off
2512.Nm vi
2513only.
2514Select an alternate erase algorithm.
2515.It Cm verbose Bq off
2516.Nm vi
2517only.
2518Display an error message for every error.
2519.It Cm w300 Bq no default
2520.Nm vi
2521only.
2522Set the window size if the baud rate is less than 1200 baud.
2523.It Cm w1200 Bq no default
2524.Nm vi
2525only.
2526Set the window size if the baud rate is equal to 1200 baud.
2527.It Cm w9600 Bq no default
2528.Nm vi
2529only.
2530Set the window size if the baud rate is greater than 1200 baud.
2531.It Cm warn Bq on
2532.Nm ex
2533only.
2534This option causes a warning message to be printed on the terminal
2535if the file has been modified since it was last written, before a
2536.Cm !\&
2537command.
2538.It Xo
2539.Cm window , w , wi
2540.Bq "environment variable LINES \- 1"
2541.Xc
2542Set the window size for the screen.
2543.It Cm windowname Bq off
2544Change the icon/window name to the current file name even if it can't
2545be restored on editor exit.
2546.It Cm wraplen , wl Bq 0
2547.Nm vi
2548only.
2549Break lines automatically,
2550the specified number of columns from the left-hand margin.
2551If both the
2552.Cm wraplen
2553and
2554.Cm wrapmargin
2555edit options are set, the
2556.Cm wrapmargin
2557value is used.
2558.It Cm wrapmargin , wm Bq 0
2559.Nm vi
2560only.
2561Break lines automatically,
2562the specified number of columns from the right-hand margin.
2563If both the
2564.Cm wraplen
2565and
2566.Cm wrapmargin
2567edit options are set, the
2568.Cm wrapmargin
2569value is used.
2570.It Cm wrapscan , ws Bq on
2571Set searches to wrap around the end or beginning of the file.
2572.It Cm writeany , wa Bq off
2573Turn off file-overwriting checks.
2574.El
2575.Sh ENVIRONMENT
2576.Bl -tag -width "COLUMNS"
2577.It Ev COLUMNS
2578The number of columns on the screen.
2579This value overrides any system or terminal specific values.
2580If the
2581.Ev COLUMNS
2582environment variable is not set when
2583.Nm ex Ns / Ns Nm vi
2584runs, or the
2585.Cm columns
2586option is explicitly reset by the user,
2587.Nm ex Ns / Ns Nm vi
2588enters the value into the environment.
2589.It Ev EXINIT
2590A list of
2591.Nm ex
2592startup commands, read after
2593.Pa /etc/vi.exrc
2594unless the variable
2595.Ev NEXINIT
2596is also set.
2597.It Ev HOME
2598The user's home directory, used as the initial directory path for the startup
2599.Pa $HOME/.nexrc
2600and
2601.Pa $HOME/.exrc
2602files.
2603This value is also used as the default directory for the
2604.Nm vi
2605.Cm cd
2606command.
2607.It Ev LINES
2608The number of rows on the screen.
2609This value overrides any system or terminal specific values.
2610If the
2611.Ev LINES
2612environment variable is not set when
2613.Nm ex Ns / Ns Nm vi
2614runs, or the
2615.Cm lines
2616option is explicitly reset by the user,
2617.Nm ex Ns / Ns Nm vi
2618enters the value into the environment.
2619.It Ev NEXINIT
2620A list of
2621.Nm ex
2622startup commands, read after
2623.Pa /etc/vi.exrc .
2624.It Ev SHELL
2625The user's shell of choice (see also the
2626.Cm shell
2627option).
2628.It Ev TERM
2629The user's terminal type.
2630The default is the type
2631.Dq unknown .
2632If the
2633.Ev TERM
2634environment variable is not set when
2635.Nm ex Ns / Ns Nm vi
2636runs, or the
2637.Cm term
2638option is explicitly reset by the user,
2639.Nm ex Ns / Ns Nm vi
2640enters the value into the environment.
2641.It Ev TMPDIR
2642The location used to stored temporary files (see also the
2643.Cm directory
2644edit option).
2645.El
2646.Sh ASYNCHRONOUS EVENTS
2647.Bl -tag -width "SIGWINCH" -compact
2648.It Dv SIGALRM
2649.Nm vi Ns / Ns Nm ex
2650uses this signal for periodic backups of file modifications and to display
2651.Dq busy
2652messages when operations are likely to take a long time.
2653.Pp
2654.It Dv SIGHUP
2655.It Dv SIGTERM
2656If the current buffer has changed since it was last written in its entirety,
2657the editor attempts to save the modified file so it can be later recovered.
2658See the
2659.Nm vi Ns / Ns Nm ex
2660reference manual section
2661.Sx Recovery
2662for more information.
2663.Pp
2664.It Dv SIGINT
2665When an interrupt occurs, the current operation is halted
2666and the editor returns to the command level.
2667If interrupted during text input,
2668the text already input is resolved into the file as if the text
2669input had been normally terminated.
2670.Pp
2671.It Dv SIGWINCH
2672The screen is resized.
2673See the
2674.Nm vi Ns / Ns Nm ex
2675reference manual section
2676.Sx Sizing the Screen
2677for more information.
2678.\" .Pp
2679.\" .It Dv SIGCONT
2680.\" .It Dv SIGTSTP
2681.\" .Nm vi Ns / Ns Nm ex
2682.\" ignores these signals.
2683.El
2684.Sh FILES
2685.Bl -tag -width "/var/tmp/vi.recover"
2686.It Pa /bin/sh
2687The default user shell.
2688.It Pa /etc/vi.exrc
2689System-wide
2690.Nm vi
2691startup file.
2692It is read for
2693.Nm ex
2694commands first in the startup sequence.
2695Must be owned by root or the user,
2696and writable only by the owner.
2697.It Pa /tmp
2698Temporary file directory.
2699.It Pa /var/tmp/vi.recover
2700The default recovery file directory.
2701.It Pa $HOME/.nexrc
2702First choice for user's home directory startup file, read for
2703.Nm ex
2704commands right after
2705.Pa /etc/vi.exrc
2706unless either
2707.Ev NEXINIT
2708or
2709.Ev EXINIT
2710are set.
2711Must be owned by root or the user,
2712and writable only by the owner.
2713.It Pa $HOME/.exrc
2714Second choice for user's home directory startup file, read for
2715.Nm ex
2716commands under the same conditions as
2717.Pa $HOME/.nexrc .
2718.It Pa .nexrc
2719First choice for local directory startup file, read for
2720.Nm ex
2721commands at the end of the startup sequence if the
2722.Cm exrc
2723option was turned on earlier.
2724Must be owned by the user
2725and writable only by the owner.
2726.It Pa .exrc
2727Second choice for local directory startup file, read for
2728.Nm ex
2729commands under the same conditions as
2730.Pa .nexrc .
2731.El
2732.Sh EXIT STATUS
2733The
2734.Nm ex
2735and
2736.Nm vi
2737utilities exit 0 on success,
2738and \*(Gt0 if an error occurs.
2739.Sh SEE ALSO
2740.Xr ctags 1 ,
2741.Xr re_format 7
2742.Sh STANDARDS
2743.Nm nex Ns / Ns Nm nvi
2744is close to
2745.St -p1003.1-2008 .
2746That document differs from historical
2747.Nm ex Ns / Ns Nm vi
2748practice in several places; there are changes to be made on both sides.
2749.Sh HISTORY
2750The
2751.Nm ex
2752editor first appeared in
2753.Bx 1 .
2754The
2755.Nm nex Ns / Ns Nm nvi
2756replacements for the
2757.Nm ex Ns / Ns Nm vi
2758editor first appeared in
2759.Bx 4.4 .
2760.Sh AUTHORS
2761.An Bill Joy
2762wrote the original version of
2763.Nm ex
2764in 1977.
2765