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