xref: /openbsd/usr.bin/vi/docs/USD.doc/vi.man/vi.1 (revision 891d7ab6)
1.\"	$OpenBSD: vi.1,v 1.53 2011/05/16 16:41:58 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: May 16 2011 $
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 BUFFERS
321A buffer is an area where commands can save changed or deleted text
322for later use.
323.Nm vi
324buffers are named with a single character preceded by a double quote,
325for example
326.Pf \&" Ns Aq c ;
327.Nm ex
328buffers are the same,
329but without the double quote.
330.Nm nex Ns / Ns Nm nvi
331permits the use of any character without another meaning in the position where
332a buffer name is expected.
333.Pp
334All buffers are either in
335.Em line mode
336or
337.Em character mode .
338Inserting a buffer in line mode into the text creates new lines for each of the
339lines it contains, while a buffer in character mode creates new lines for any
340lines
341.Em other
342than the first and last lines it contains.
343The first and last lines are inserted at the current cursor position, becoming
344part of the current line.
345If there is more than one line in the buffer,
346the current line itself will be split.
347All
348.Nm ex
349commands which store text into buffers do so in line mode.
350The
351.Nm ex
352command
353.Cm display buffers
354displays the current mode for each buffer.
355.Pp
356Buffers named
357.Sq a
358through
359.Sq z
360may be referred to using their uppercase equivalent, in which case new content
361will be appended to the buffer, instead of replacing it.
362.Pp
363Buffers named
364.Sq 1
365through
366.Sq 9
367are special.
368A region of text modified using the
369.Cm c
370.Pq change
371or
372.Cm d
373.Pq delete
374commands is placed into the numeric buffer
375.Sq 1
376if no other buffer is specified and if it meets one of the following conditions:
377.Bl -bullet -offset 6u
378.It
379It includes characters from more than one line.
380.It
381It is specified using a line-oriented motion.
382.It
383It is specified using one of the following motion commands:
384.Aq Cm control-A ,
385.Cm ` Ns Aq Cm character ,
386.Cm n ,
387.Cm N ,
388.Cm % ,
389.Cm / ,
390.Cm { ,
391.Cm } ,
392.Cm \&( ,
393.Cm \&) ,
394and
395.Cm \&? .
396.El
397.Pp
398Before this copy is done, the previous contents of buffer
399.Sq 1
400are moved into buffer
401.Sq 2 ,
402.Sq 2
403into buffer
404.Sq 3 ,
405and so on.
406The contents of buffer
407.Sq 9
408are discarded.
409Note that this rotation occurs
410.Em regardless
411of the user specifying another buffer.
412In
413.Nm vi ,
414text may be explicitly stored into the numeric buffers.
415In this case, the buffer rotation occurs before the replacement of the buffer's
416contents.
417The numeric buffers are only available in
418.Nm vi
419mode.
420.Sh VI COMMANDS
421The following section describes the commands available in the command
422mode of the
423.Nm vi
424editor.
425In each command synopsis below, the following notation is used:
426.Pp
427.Bl -tag -width buffer -compact -offset 3u
428.It Ar buffer
429Temporary area where commands may place text.
430If not specified, the default buffer is used.
431See also
432.Sx BUFFERS ,
433above.
434.It Ar motion
435A cursor movement command which indicates the other end of the affected region
436of text, the first being the current cursor position.
437Repeating the command character makes it affect the whole
438current line.
439.It Ar count
440A positive number used to specify the desired number of iterations
441of a command.
442It defaults to 1 if not specified.
443.El
444.Pp
445.Ar buffer
446and
447.Ar count ,
448if both present, may be specified in any order.
449.Ar motion
450and
451.Ar count ,
452if both present, are effectively multiplied together
453and considered part of the motion.
454.Pp
455.Bl -tag -width Ds -compact
456.It Xo
457.\" .Op Ar count
458.Aq Cm control-A
459.Xc
460Search forward
461.\" .Ar count
462.\" times
463for the current word.
464.Pp
465.It Xo
466.Op Ar count
467.Aq Cm control-B
468.Xc
469Page backwards
470.Ar count
471screens.
472.Pp
473.It Xo
474.Op Ar count
475.Aq Cm control-D
476.Xc
477Scroll forward
478.Ar count
479lines.
480If
481.Ar count
482is not given, scroll forward half the number of lines in the current screen.
483.Pp
484.It Xo
485.Op Ar count
486.Aq Cm control-E
487.Xc
488Scroll forward
489.Ar count
490lines, leaving the current line and column as is, if possible.
491.Pp
492.It Xo
493.Op Ar count
494.Aq Cm control-F
495.Xc
496Page forward
497.Ar count
498screens.
499.Pp
500.It Aq Cm control-G
501Display the file information.
502.Pp
503.It Xo
504.Op Ar count
505.Aq Cm control-H
506.Xc
507.It Xo
508.Op Ar count
509.Cm h
510.Xc
511Move the cursor back
512.Ar count
513characters in the current line.
514.Pp
515.It Xo
516.Op Ar count
517.Aq Cm control-J
518.Xc
519.It Xo
520.Op Ar count
521.Aq Cm control-N
522.Xc
523.It Xo
524.Op Ar count
525.Cm j
526.Xc
527Move the cursor down
528.Ar count
529lines without changing the current column.
530.Pp
531.It Aq Cm control-L
532.It Aq Cm control-R
533Repaint the screen.
534.Pp
535.It Xo
536.Op Ar count
537.Aq Cm control-M
538.Xc
539.It Xo
540.Op Ar count
541.Cm +
542.Xc
543Move the cursor down
544.Ar count
545lines to the first non-blank character of that line.
546.Pp
547.It Xo
548.Op Ar count
549.Aq Cm control-P
550.Xc
551.It Xo
552.Op Ar count
553.Cm k
554.Xc
555Move the cursor up
556.Ar count
557lines, without changing the current column.
558.Pp
559.It Aq Cm control-T
560Return to the most recent tag context.
561.Pp
562.It Xo
563.Op Ar count
564.Aq Cm control-U
565.Xc
566Scroll backwards
567.Ar count
568lines.
569If
570.Ar count
571is not given, scroll backwards half the number of lines in the current screen.
572.Pp
573.It Aq Cm control-W
574Switch to the next lower screen in the window,
575or to the first screen if there are no lower screens in the window.
576.Pp
577.It Xo
578.Op Ar count
579.Aq Cm control-Y
580.Xc
581Scroll backwards
582.Ar count
583lines, leaving the current line and column as is, if possible.
584.Pp
585.It Aq Cm control-Z
586Suspend the current editor session.
587.Pp
588.It Aq Cm escape
589Execute
590.Nm ex
591commands or cancel partial commands.
592.Pp
593.It Aq Cm control-]
594Push a tag reference onto the tag stack.
595.Pp
596.It Aq Cm control-^
597Switch to the most recently edited file.
598.Pp
599.It Xo
600.Op Ar count
601.Aq Cm space
602.Xc
603.It Xo
604.Op Ar count
605.Cm l
606.Xc
607Move the cursor forward
608.Ar count
609characters without changing the current line.
610.Pp
611.It Xo
612.Op Ar count
613.Cm !\&
614.Ar motion shell-argument(s)
615.Aq Li carriage-return
616.Xc
617Replace text with results from a shell command.
618.Pp
619.It Xo
620.Op Ar count
621.Cm #
622.Sm off
623.Cm # | + | -
624.Sm on
625.Xc
626Increment or decrement the number under the cursor.
627If the trailing character is a
628.Sq #
629or
630.Sq + ,
631the number is incremented.
632If the trailing character is a
633.Sq - ,
634the number is decremented.
635.Pp
636.It Xo
637.Op Ar count
638.Cm $
639.Xc
640Move the cursor to the end of a line.
641.Pp
642.It Cm %
643Move to the matching character.
644.Pp
645.It Cm &
646Repeat the previous substitution command on the current line.
647.Pp
648.It Xo
649.Cm ' Ns Aq Ar character
650.Xc
651.It Xo
652.Cm ` Ns Aq Ar character
653.Xc
654Return to a context marked by the character
655.Ar character .
656The first form returns to the beginning of the line marked by
657.Ar character .
658The second form returns to the first character of the context marked by
659.Ar character .
660.Pp
661.It Xo
662.Op Ar count
663.Cm \&(
664.Xc
665.It Xo
666.Op Ar count
667.Cm \&)
668.Xc
669Move
670.Ar count
671sentences backward or forward, respectively.
672A sentence is an area of text that begins with the first nonblank character
673following the previous sentence, paragraph, or section
674boundary and continues until the next period, exclamation mark,
675or question mark character, followed by any number of closing parentheses,
676brackets, double or single quote characters, followed by
677either an end-of-line or two whitespace characters.
678Groups of empty lines
679.Pq or lines containing only whitespace characters
680are treated as a single sentence.
681.Pp
682.It Xo
683.Op Ar count
684.Cm ,\&
685.Xc
686Reverse find character
687.Ar count
688times.
689.Pp
690.It Xo
691.Op Ar count
692.Cm -
693.Xc
694Move to the first non-blank of the previous line,
695.Ar count
696times.
697.Pp
698.It Xo
699.Op Ar count
700.Cm .\&
701.Xc
702Repeat the last
703.Nm vi
704command that modified text.
705.Pp
706.It Xo
707.Pf / Ns Ar RE
708.Aq Li carriage-return
709.Xc
710.It Xo
711.Pf / Ns Ar RE Ns /
712.Op Ar offset
713.Aq Li carriage-return
714.Xc
715.It Xo
716.Pf ?\& Ns Ar RE
717.Aq Li carriage-return
718.Xc
719.It Xo
720.Pf ?\& Ns Ar RE Ns ?\&
721.Op Ar offset
722.Aq Li carriage-return
723.Xc
724.It Cm N
725.It Cm n
726Search forward
727.Pq Sq /
728or backward
729.Pq Sq ?\&
730for a regular expression.
731.Cm n
732and
733.Cm N
734repeat the last search in the same or opposite directions, respectively.
735If
736.Ar offset
737is specified, the cursor is placed
738.Ar offset
739lines before or after the matched regular expression.
740.Pp
741.It Cm 0
742Move to the first character in the current line.
743.Pp
744.It Cm :\&
745Execute an
746.Nm ex
747command.
748.Pp
749.It Xo
750.Op Ar count
751.Cm ;\&
752.Xc
753Repeat the last character find
754.Ar count
755times.
756.Pp
757.It Xo
758.Op Ar count
759.Cm <
760.Ar motion
761.Xc
762.It Xo
763.Op Ar count
764.Cm >
765.Ar motion
766.Xc
767Shift lines left or right, respectively, by an amount of
768.Cm shiftwidth .
769.Pp
770.It Cm @ Ar buffer
771Execute a named
772.Ar buffer .
773.Pp
774.It Xo
775.Op Ar count
776.Cm A
777.Xc
778Enter input mode, appending the text after the end of the line.
779If a
780.Ar count
781argument is given,
782the characters input are repeated
783.Ar count
784\- 1 number of times.
785.Pp
786.It Xo
787.Op Ar count
788.Cm B
789.Xc
790Move backwards
791.Ar count
792bigwords.
793.Pp
794.It Xo
795.Op Ar buffer
796.Op Ar count
797.Cm C
798.Xc
799Change text from the current position to the end-of-line.
800If
801.Ar buffer
802is specified,
803.Dq yank
804the deleted text into
805.Ar buffer .
806.Pp
807.It Xo
808.Op Ar buffer
809.Cm D
810.Xc
811Delete text from the current position to the end-of-line.
812If
813.Ar buffer
814is specified,
815.Dq yank
816the deleted text into
817.Ar buffer .
818.Pp
819.It Xo
820.Op Ar count
821.Cm E
822.Xc
823Move forward
824.Ar count
825end-of-bigwords.
826.Pp
827.It Xo
828.Op Ar count
829.Cm F Aq Ar character
830.Xc
831Search
832.Ar count
833times backward through the current line for
834.Ar character .
835.Pp
836.It Xo
837.Op Ar count
838.Cm G
839.Xc
840Move to line
841.Ar count ,
842or the last line of the file if
843.Ar count
844is not specified.
845.Pp
846.It Xo
847.Op Ar count
848.Cm H
849.Xc
850Move to the screen line
851.Ar count
852\- 1 lines below the top of the screen.
853.Pp
854.It Xo
855.Op Ar count
856.Cm I
857.Xc
858Enter input mode, inserting the text at the beginning of the line.
859If a
860.Ar count
861argument is given,
862the characters input are repeated
863.Ar count
864\- 1 number of times.
865.Pp
866.It Xo
867.Op Ar count
868.Cm J
869.Xc
870Join lines.
871.Pp
872.It Xo
873.Op Ar count
874.Cm L
875.Xc
876Move to the screen line
877.Ar count
878\- 1 lines above the bottom of the screen.
879.Pp
880.It Cm M
881Move to the screen line in the middle of the screen.
882.Pp
883.It Xo
884.Op Ar count
885.Cm O
886.Xc
887Enter input mode, appending text in a new line above the current line.
888If a
889.Ar count
890argument is given,
891the characters input are repeated
892.Ar count
893\- 1 number of times.
894.Pp
895.It Xo
896.Op Ar buffer
897.Cm P
898.Xc
899Insert text from a buffer.
900.Pp
901.It Cm Q
902Exit
903.Nm vi
904.Pq or visual
905mode and switch to
906.Nm ex
907mode.
908.Pp
909.It Xo
910.Op Ar count
911.Cm R
912.Xc
913Enter input mode, replacing the characters in the current line.
914If a
915.Ar count
916argument is given,
917the characters input are repeated
918.Ar count
919\- 1 number of times.
920.Pp
921.It Xo
922.Op Ar buffer
923.Op Ar count
924.Cm S
925.Xc
926Substitute
927.Ar count
928lines.
929If
930.Ar buffer
931is specified,
932.Dq yank
933the deleted text into
934.Ar buffer .
935.Pp
936.It Xo
937.Op Ar count
938.Cm T
939.Aq Ar character
940.Xc
941Search backwards,
942.Ar count
943times, through the current line for the character after the specified
944.Ar character .
945.Pp
946.It Cm U
947Restore the current line to its state before the cursor last moved to it.
948.Pp
949.It Xo
950.Op Ar count
951.Cm W
952.Xc
953Move forward
954.Ar count
955bigwords.
956.Pp
957.It Xo
958.Op Ar buffer
959.Op Ar count
960.Cm X
961.Xc
962Delete
963.Ar count
964characters before the cursor.
965If
966.Ar buffer
967is specified,
968.Dq yank
969the deleted text into
970.Ar buffer .
971.Pp
972.It Xo
973.Op Ar buffer
974.Op Ar count
975.Cm Y
976.Xc
977Copy (or
978.Dq yank )
979.Ar count
980lines into the specified
981.Ar buffer ,
982or the default buffer if none is specified.
983.Pp
984.It Cm ZZ
985Write the file and exit
986.Nm vi .
987.Pp
988.It Xo
989.Op Ar count
990.Cm [[
991.Xc
992Back up
993.Ar count
994section boundaries.
995.Pp
996.It Xo
997.Op Ar count
998.Cm ]]
999.Xc
1000Move forward
1001.Ar count
1002section boundaries.
1003.Pp
1004.It Cm ^
1005Move to the first non-blank character on the current line.
1006.Pp
1007.It Xo
1008.Op Ar count
1009.Cm _
1010.Xc
1011Move down
1012.Ar count
1013\- 1 lines, to the first non-blank character.
1014.Pp
1015.It Xo
1016.Op Ar count
1017.Cm a
1018.Xc
1019Enter input mode, appending the text after the cursor.
1020If a
1021.Ar count
1022argument is given,
1023the characters input are repeated
1024.Ar count
1025\-1 number of times.
1026.Pp
1027.It Xo
1028.Op Ar count
1029.Cm b
1030.Xc
1031Move backwards
1032.Ar count
1033words.
1034.Pp
1035.It Xo
1036.Op Ar buffer
1037.Op Ar count
1038.Cm c
1039.Ar motion
1040.Xc
1041Change a region of text.
1042.Pp
1043.It Xo
1044.Op Ar buffer
1045.Op Ar count
1046.Cm d
1047.Ar motion
1048.Xc
1049Delete a region of text.
1050.Pp
1051.It Xo
1052.Op Ar count
1053.Cm e
1054.Xc
1055Move forward
1056.Ar count
1057end-of-words.
1058.Pp
1059.It Xo
1060.Op Ar count
1061.Cm f Aq Ar character
1062.Xc
1063Search forward,
1064.Ar count
1065times, through the rest of the current line for
1066.Aq Ar character .
1067.Pp
1068.It Xo
1069.Op Ar count
1070.Cm i
1071.Xc
1072Enter input mode, inserting the text before the cursor.
1073If a
1074.Ar count
1075argument is given,
1076the characters input are repeated
1077.Ar count
1078\-1 number of times.
1079.Pp
1080.It Xo
1081.Cm m
1082.Aq Ar character
1083.Xc
1084Save the current context
1085.Pq line and column
1086as
1087.Aq Ar character .
1088.Pp
1089.It Xo
1090.Op Ar count
1091.Cm o
1092.Xc
1093Enter input mode, appending text in a new line under the current line.
1094If a
1095.Ar count
1096argument is given,
1097the characters input are repeated
1098.Ar count
1099\- 1 number of times.
1100.Pp
1101.It Xo
1102.Op Ar buffer
1103.Cm p
1104.Xc
1105Append text from a buffer.
1106.Pp
1107.It Xo
1108.Op Ar count
1109.Cm r
1110.Aq Ar character
1111.Xc
1112Replace
1113.Ar count
1114characters.
1115.Pp
1116.It Xo
1117.Op Ar buffer
1118.Op Ar count
1119.Cm s
1120.Xc
1121Substitute
1122.Ar count
1123characters in the current line starting with the current character.
1124.Pp
1125.It Xo
1126.Op Ar count
1127.Cm t
1128.Aq Ar character
1129.Xc
1130Search forward,
1131.Ar count
1132times, through the current line for the character immediately before
1133.Aq Ar character .
1134.Pp
1135.It Cm u
1136Undo the last change made to the file.
1137.Pp
1138.It Xo
1139.Op Ar count
1140.Cm w
1141.Xc
1142Move forward
1143.Ar count
1144words.
1145.Pp
1146.It Xo
1147.Op Ar buffer
1148.Op Ar count
1149.Cm x
1150.Xc
1151Delete
1152.Ar count
1153characters.
1154.Pp
1155.It Xo
1156.Op Ar buffer
1157.Op Ar count
1158.Cm y
1159.Ar motion
1160.Xc
1161Copy (or
1162.Dq yank )
1163a text region specified by
1164.Ar count
1165and
1166.Ar motion
1167into a buffer.
1168.Pp
1169.It Xo
1170.Op Ar count1
1171.Cm z
1172.Op Ar count2
1173.Cm type
1174.Xc
1175Redraw, optionally repositioning and resizing the screen.
1176If
1177.Ar count2
1178is specified, limit the screen size to
1179.Ar count2
1180lines.
1181The following
1182.Cm type
1183characters may be used:
1184.Bl -tag -width Ds
1185.It Cm +
1186If
1187.Ar count1
1188is specified, place the line
1189.Ar count1
1190at the top of the screen.
1191Otherwise, display the screen after the current screen.
1192.It Aq Cm carriage-return
1193Place the line
1194.Ar count1
1195at the top of the screen.
1196.It Cm .\&
1197Place the line
1198.Ar count1
1199in the center of the screen.
1200.It Cm -
1201Place the line
1202.Ar count1
1203at the bottom of the screen.
1204.It Cm ^
1205If
1206.Ar count1
1207is given,
1208display the screen before the screen before
1209.Ar count1
1210.Pq i.e. 2 screens before .
1211Otherwise, display the screen before the current screen.
1212.El
1213.Pp
1214.It Xo
1215.Op Ar count
1216.Cm {\&
1217.Xc
1218Move backward
1219.Ar count
1220paragraphs.
1221.Pp
1222.It Xo
1223.Op Ar column
1224.Cm |\&
1225.Xc
1226Move to a specific
1227.Ar column
1228position on the current line.
1229If
1230.Ar column
1231is omitted,
1232move to the start of the current line.
1233.Pp
1234.It Xo
1235.Op Ar count
1236.Cm }\&
1237.Xc
1238Move forward
1239.Ar count
1240paragraphs.
1241.Pp
1242.It Xo
1243.Op Ar count
1244.Cm ~
1245.Xc
1246Reverse the case of the next
1247.Ar count
1248character(s).
1249.Pp
1250.It Xo
1251.Op Ar count
1252.Cm ~
1253.Ar motion
1254.Xc
1255Reverse the case of the characters in a text region specified by the
1256.Ar count
1257and
1258.Ar motion .
1259Only in effect if the
1260.Cm tildeop
1261option is set.
1262.Pp
1263.It Aq Cm interrupt
1264Interrupt the current operation.
1265The
1266.Aq interrupt
1267character is usually
1268.Aq control-C .
1269.El
1270.Sh VI TEXT INPUT COMMANDS
1271The following section describes the commands available in the text input mode
1272of the
1273.Nm vi
1274editor.
1275.Pp
1276.Bl -tag -width Ds -compact
1277.It Aq Cm nul
1278Replay the previous input.
1279.Pp
1280.It Aq Cm control-D
1281Erase to the previous
1282.Ar shiftwidth
1283column boundary.
1284.Pp
1285.It Cm ^ Ns Aq Cm control-D
1286Erase all of the autoindent characters, and reset the autoindent level.
1287.Pp
1288.It Cm 0 Ns Aq Cm control-D
1289Erase all of the autoindent characters.
1290.Pp
1291.It Aq Cm control-T
1292Insert sufficient
1293.Aq tab
1294and
1295.Aq space
1296characters to move forward to the next
1297.Ar shiftwidth
1298column boundary.
1299.Pp
1300.It Aq Cm erase
1301.It Aq Cm control-H
1302Erase the last character.
1303.Pp
1304.It Aq Cm literal next
1305Escape the next character from any special meaning.
1306The
1307.Aq literal\ \&next
1308character is usually
1309.Aq control-V .
1310.Pp
1311.It Aq Cm escape
1312Resolve all text input into the file, and return to command mode.
1313.Pp
1314.It Aq Cm line erase
1315Erase the current line.
1316.Pp
1317.It Aq Cm control-W
1318.It Aq Cm word erase
1319Erase the last word.
1320The definition of word is dependent on the
1321.Cm altwerase
1322and
1323.Cm ttywerase
1324options.
1325.Pp
1326.Sm off
1327.It Xo
1328.Aq Cm control-X
1329.Bq Cm 0-9A-Fa-f
1330.Cm +
1331.Xc
1332.Sm on
1333Insert a character with the specified hexadecimal value into the text.
1334.Pp
1335.It Aq Cm interrupt
1336Interrupt text input mode, returning to command mode.
1337The
1338.Aq interrupt
1339character is usually
1340.Aq control-C .
1341.El
1342.Sh EX COMMANDS
1343The following section describes the commands available in the
1344.Nm ex
1345editor.
1346In each entry below, the tag line is a usage synopsis for the command.
1347.Pp
1348.Bl -tag -width Ds -compact
1349.It Aq Cm end-of-file
1350Scroll the screen.
1351.Pp
1352.It Cm !\& Ar argument(s)
1353.It Xo
1354.Op Ar range
1355.Cm !\&
1356.Ar argument(s)
1357.Xc
1358Execute a shell command, or filter lines through a shell command.
1359.Pp
1360.It Cm \&"
1361A comment.
1362.Pp
1363.It Xo
1364.Op Ar range
1365.Cm nu Ns Op Cm mber
1366.Op Ar count
1367.Op Ar flags
1368.Xc
1369.It Xo
1370.Op Ar range
1371.Cm #
1372.Op Ar count
1373.Op Ar flags
1374.Xc
1375Display the selected lines, each preceded with its line number.
1376.Pp
1377.It Cm @ Ar buffer
1378.It Cm * Ar buffer
1379Execute a buffer.
1380.Pp
1381.It Xo
1382.Op Ar range
1383.Cm < Ns Op Cm < ...
1384.Op Ar count
1385.Op Ar flags
1386.Xc
1387Shift lines left.
1388.Pp
1389.It Xo
1390.Op Ar line
1391.Cm =
1392.Op Ar flags
1393.Xc
1394Display the line number of
1395.Ar line .
1396If
1397.Ar line
1398is not specified, display the line number of the last line in the file.
1399.Pp
1400.It Xo
1401.Op Ar range
1402.Cm > Ns Op Cm > ...
1403.Op Ar count
1404.Op Ar flags
1405.Xc
1406Shift lines right.
1407.Pp
1408.It Xo
1409.Cm ab Ns Op Cm breviate
1410.Ar lhs rhs
1411.Xc
1412.Nm vi
1413only.
1414Add
1415.Ar lhs
1416as an abbreviation for
1417.Ar rhs
1418to the abbreviation list.
1419.Pp
1420.It Xo
1421.Op Ar line
1422.Cm a Ns Op Cm ppend Ns
1423.Op Cm !\&
1424.Xc
1425The input text is appended after the specified line.
1426.Pp
1427.It Cm ar Ns Op Cm gs
1428Display the argument list.
1429.Pp
1430.It Cm bg
1431.Nm vi
1432only.
1433Background the current screen.
1434.Pp
1435.It Xo
1436.Op Ar range
1437.Cm c Ns Op Cm hange Ns
1438.Op Cm !\&
1439.Op Ar count
1440.Xc
1441The input text replaces the specified range.
1442.Pp
1443.It Xo
1444.Cm chd Ns Op Cm ir Ns
1445.Op Cm !\&
1446.Op Ar directory
1447.Xc
1448.It Xo
1449.Cm cd Ns Op Cm !\&
1450.Op Ar directory
1451.Xc
1452Change the current working directory.
1453.Pp
1454.It Xo
1455.Op Ar range
1456.Cm co Ns Op Cm py
1457.Ar line
1458.Op Ar flags
1459.Xc
1460.It Xo
1461.Op Ar range
1462.Cm t
1463.Ar line
1464.Op Ar flags
1465.Xc
1466Copy the specified lines after the destination
1467.Ar line .
1468.Pp
1469.It Xo
1470.Cm cs Ns Op Cm cope
1471.Cm add | find | help | kill | reset
1472.Xc
1473Execute a Cscope command.
1474.Pp
1475.It Xo
1476.Op Ar range
1477.Cm d Ns Op Cm elete
1478.Op Ar buffer
1479.Op Ar count
1480.Op Ar flags
1481.Xc
1482Delete the lines from the file.
1483.Pp
1484.It Xo
1485.Cm di Ns Op Cm splay
1486.Cm b Ns Oo Cm uffers Oc |
1487.Cm c Ns Oo Cm onnections Oc |
1488.Cm s Ns Oo Cm creens Oc |
1489.Cm t Ns Op Cm ags
1490.Xc
1491Display buffers, Cscope connections, screens or tags.
1492.Pp
1493.It Xo
1494.Op Cm Ee Ns
1495.Op Cm dit Ns
1496.Op Cm !\&
1497.Op Ar +cmd
1498.Op Ar file
1499.Xc
1500.It Xo
1501.Op Cm Ee Ns
1502.Cm x Ns Op Cm !\&
1503.Op Ar +cmd
1504.Op Ar file
1505.Xc
1506Edit a different file.
1507.Pp
1508.It Xo
1509.Cm exu Ns Op Cm sage
1510.Op Ar command
1511.Xc
1512Display usage for an
1513.Nm ex
1514command.
1515.Pp
1516.It Xo
1517.Cm f Ns Op Cm ile
1518.Op Ar file
1519.Xc
1520Display and optionally change the file name.
1521.Pp
1522.It Xo
1523.Op Cm Ff Ns
1524.Cm g
1525.Op Ar name
1526.Xc
1527.Nm vi
1528mode only.
1529Foreground the specified screen.
1530.Pp
1531.It Xo
1532.Op Ar range
1533.Cm g Ns Op Cm lobal
1534.No / Ns Ar pattern Ns /
1535.Op Ar commands
1536.Xc
1537.It Xo
1538.Op Ar range
1539.Cm v
1540.No / Ns Ar pattern Ns /
1541.Op Ar commands
1542.Xc
1543Apply commands to lines matching
1544.Pq Sq global
1545or not matching
1546.Pq Sq v
1547a pattern.
1548.Pp
1549.It Cm he Ns Op Cm lp
1550Display a help message.
1551.Pp
1552.It Xo
1553.Op Ar line
1554.Cm i Ns Op Cm nsert Ns
1555.Op Cm !\&
1556.Xc
1557The input text is inserted before the specified line.
1558.Pp
1559.It Xo
1560.Op Ar range
1561.Cm j Ns Op Cm oin Ns
1562.Op Cm !\&
1563.Op Ar count
1564.Op Ar flags
1565.Xc
1566Join lines of text together.
1567.Pp
1568.It Xo
1569.Op Ar range
1570.Cm l Ns Op Cm ist
1571.Op Ar count
1572.Op Ar flags
1573.Xc
1574Display the lines unambiguously.
1575.Pp
1576.It Xo
1577.Cm map Ns Op Cm !\&
1578.Op Ar lhs rhs
1579.Xc
1580Define or display maps (for
1581.Nm vi
1582only).
1583.Pp
1584.It Xo
1585.Op Ar line
1586.Cm ma Ns Op Cm rk
1587.Aq Ar character
1588.Xc
1589.It Xo
1590.Op Ar line
1591.Cm k Aq Ar character
1592.Xc
1593Mark the line with the mark
1594.Aq Ar character .
1595.Pp
1596.It Xo
1597.Op Ar range
1598.Cm m Ns Op Cm ove
1599.Ar line
1600.Xc
1601Move the specified lines after the target line.
1602.Pp
1603.It Xo
1604.Cm mk Ns Op Cm exrc Ns
1605.Op Cm !\&
1606.Ar file
1607.Xc
1608Write the abbreviations, editor options and maps to the specified
1609.Ar file .
1610.Pp
1611.It Xo
1612.Op Cm Nn Ns
1613.Op Cm ext Ns
1614.Op Cm !\&
1615.Op Ar file ...
1616.Xc
1617Edit the next file from the argument list.
1618.\" .Pp
1619.\" .It Xo
1620.\" .Op Ar line
1621.\" .Cm o Ns Op Cm pen
1622.\" .No / Ns Ar pattern Ns /
1623.\" .Op Ar flags
1624.\" .Xc
1625.\" Enter open mode.
1626.Pp
1627.It Cm pre Ns Op Cm serve
1628Save the file in a form that can later be recovered using the
1629.Nm ex
1630.Fl r
1631option.
1632.Pp
1633.It Xo
1634.Op Cm \&Pp Ns
1635.Cm rev Ns Op Cm ious Ns
1636.Op Cm !\&
1637.Xc
1638Edit the previous file from the argument list.
1639.Pp
1640.It Xo
1641.Op Ar range
1642.Cm p Ns Op Cm rint
1643.Op Ar count
1644.Op Ar flags
1645.Xc
1646Display the specified lines.
1647.Pp
1648.It Xo
1649.Op Ar line
1650.Cm pu Ns Op Cm t
1651.Op Ar buffer
1652.Xc
1653Append buffer contents to the current line.
1654.Pp
1655.It Xo
1656.Cm q Ns Op Cm uit Ns
1657.Op Cm !\&
1658.Xc
1659End the editing session.
1660.Pp
1661.It Xo
1662.Op Ar line
1663.Cm r Ns Op Cm ead Ns
1664.Op Cm !\&
1665.Op Ar file
1666.Xc
1667Read a file.
1668.Pp
1669.It Xo
1670.Cm rec Ns Op Cm over
1671.Ar file
1672.Xc
1673Recover
1674.Ar file
1675if it was previously saved.
1676.Pp
1677.It Xo
1678.Cm res Ns Op Cm ize
1679.Op Cm + Ns | Ns Cm - Ns
1680.Ar size
1681.Xc
1682.Nm vi
1683mode only.
1684Grow or shrink the current screen.
1685.Pp
1686.It Xo
1687.Cm rew Ns Op Cm ind Ns
1688.Op Cm !\&
1689.Xc
1690Rewind the argument list.
1691.Pp
1692.It Xo
1693.Cm se Ns Op Cm t
1694.Sm off
1695.Op option Oo = Oo value Oc Oc \ \&...
1696.Sm on
1697.Pf \ \& Op nooption ...
1698.Op option? ...
1699.Op Ar all
1700.Xc
1701Display or set editor options.
1702.Pp
1703.It Cm sh Ns Op Cm ell
1704Run a shell program.
1705.Pp
1706.It Xo
1707.Cm so Ns Op Cm urce
1708.Ar file
1709.Xc
1710Read and execute
1711.Nm ex
1712commands from a file.
1713.Pp
1714.It Xo
1715.Op Ar range
1716.Cm s Ns Op Cm ubstitute
1717.Sm off
1718.Op / Ar pattern No / Ar replace  No /
1719.Sm on
1720.Pf \ \& Op Ar options
1721.Op Ar count
1722.Op Ar flags
1723.Xc
1724.It Xo
1725.Op Ar range
1726.Cm &
1727.Op Ar options
1728.Op Ar count
1729.Op Ar flags
1730.Xc
1731.It Xo
1732.Op Ar range
1733.Cm ~
1734.Op Ar options
1735.Op Ar count
1736.Op Ar flags
1737.Xc
1738Make substitutions.
1739.Pp
1740.It Xo
1741.Cm su Ns Op Cm spend Ns
1742.Op Cm !\&
1743.Xc
1744.It Xo
1745.Cm st Ns Op Cm op Ns
1746.Op Cm !\&
1747.Xc
1748.It Aq Cm suspend
1749Suspend the edit session.
1750The
1751.Aq suspend
1752character is usually
1753.Aq control-Z .
1754.Pp
1755.It Xo
1756.Op Cm Tt Ns
1757.Cm a Ns Op Cm g Ns
1758.Op Cm !\&
1759.Ar tagstring
1760.Xc
1761Edit the file containing the specified tag.
1762.Pp
1763.It Xo
1764.Cm tagn Ns Op Cm ext Ns
1765.Op Cm !\&
1766.Xc
1767Edit the file containing the next context for the current tag.
1768.Pp
1769.It Xo
1770.Cm tagp Ns Op Cm op Ns
1771.Op Cm !\&
1772.Op Ar file | number
1773.Xc
1774Pop to the specified tag in the tags stack.
1775.Pp
1776.It Xo
1777.Cm tagpr Ns Op Cm ev Ns
1778.Op Cm !\&
1779.Xc
1780Edit the file containing the previous context for the current tag.
1781.Pp
1782.It Xo
1783.Cm tagt Ns Op Cm op Ns
1784.Op Cm !\&
1785.Xc
1786Pop to the least recent tag on the tags stack, clearing the stack.
1787.Pp
1788.It Xo
1789.Cm una Ns Op Cm bbreviate
1790.Ar lhs
1791.Xc
1792.Nm vi
1793only.
1794Delete an abbreviation.
1795.Pp
1796.It Cm u Ns Op Cm ndo
1797Undo the last change made to the file.
1798.Pp
1799.It Xo
1800.Cm unm Ns Op Cm ap Ns
1801.Op Cm !\&
1802.Ar lhs
1803.Xc
1804Unmap a mapped string.
1805.Pp
1806.It Cm ve Ns Op Cm rsion
1807Display the version of the
1808.Nm ex Ns / Ns Nm vi
1809editor.
1810.Pp
1811.It Xo
1812.Op Ar line
1813.Cm vi Ns Op Cm sual
1814.Op Ar type
1815.Op Ar count
1816.Op Ar flags
1817.Xc
1818.Nm ex
1819mode only.
1820Enter
1821.Nm vi .
1822.Pp
1823.It Xo
1824.Op Cm Vi Ns
1825.Cm i Ns Op Cm sual Ns
1826.Op Cm !\&
1827.Op Ar +cmd
1828.Op Ar file
1829.Xc
1830.Nm vi
1831mode only.
1832Edit a new file.
1833.Pp
1834.It Xo
1835.Cm viu Ns Op Cm sage
1836.Op Ar command
1837.Xc
1838Display usage for a
1839.Nm vi
1840command.
1841.Pp
1842.It Xo
1843.Op Ar range
1844.Cm w Ns Op Cm rite Ns
1845.Op Cm !\&
1846.Op >>
1847.Op Ar file
1848.Xc
1849.It Xo
1850.Op Ar range
1851.Cm w Ns Op Cm rite
1852.Op Cm !\&
1853.Op Ar file
1854.Xc
1855.It Xo
1856.Op Ar range
1857.Cm wn Ns Op Cm !\&
1858.Op >>
1859.Op Ar file
1860.Xc
1861.It Xo
1862.Op Ar range
1863.Cm wq Ns Op Cm !\&
1864.Op >>
1865.Op Ar file
1866.Xc
1867Write the file.
1868.Pp
1869.It Xo
1870.Op Ar range
1871.Cm x Ns Op Cm it Ns
1872.Op Cm !\&
1873.Op Ar file
1874.Xc
1875Exit the editor,
1876writing the file if it has been modified.
1877.Pp
1878.It Xo
1879.Op Ar range
1880.Cm ya Ns Op Cm nk
1881.Op Ar buffer
1882.Op Ar count
1883.Xc
1884Copy the specified lines to a buffer.
1885.Pp
1886.It Xo
1887.Op Ar line
1888.Cm z
1889.Op Ar type
1890.Op Ar count
1891.Op Ar flags
1892.Xc
1893Adjust the window.
1894.El
1895.Sh SET OPTIONS
1896There are a large number of options that may be set
1897.Pq or unset
1898to change the editor's behavior.
1899This section describes the options, their abbreviations and their
1900default values.
1901.Pp
1902In each entry below, the first part of the tag line is the full name
1903of the option, followed by any equivalent abbreviations.
1904The part in square brackets is the default value of the option.
1905Most of the options are boolean, i.e. they are either on or off,
1906and do not have an associated value.
1907.Pp
1908Options apply to both
1909.Nm ex
1910and
1911.Nm vi
1912modes, unless otherwise specified.
1913.Bl -tag -width Ds
1914.It Cm altwerase Bq off
1915.Nm vi
1916only.
1917Select an alternate word erase algorithm.
1918.It Cm autoindent , ai Bq off
1919Automatically indent new lines.
1920.It Cm autoprint , ap Bq on
1921.Nm ex
1922only.
1923Display the current line automatically.
1924.It Cm autowrite , aw Bq off
1925Write modified files automatically when changing files.
1926.It Cm backup Bq \&"\&"
1927Back up files before they are overwritten.
1928.It Cm beautify , bf Bq off
1929Discard control characters.
1930.It Cm cdpath Bq "environment variable CDPATH, or current directory"
1931The directory paths used as path prefixes for the
1932.Cm cd
1933command.
1934.It Cm cedit Bq no default
1935Set the character to edit the colon command-line history.
1936.It Cm columns , co Bq 80
1937Set the number of columns in the screen.
1938.It Cm comment Bq off
1939.Nm vi
1940only.
1941Skip leading comments in shell, C and C++ language files.
1942.It Cm directory , dir Bq "environment variable TMPDIR, or /tmp"
1943The directory where temporary files are created.
1944.It Cm edcompatible , ed Bq off
1945Remember the values of the
1946.Sq c
1947and
1948.Sq g
1949suffixes to the
1950.Cm substitute
1951commands, instead of initializing them as unset for each new command.
1952.It Cm escapetime Bq 1
1953The 10th's of a second
1954.Nm ex Ns / Ns Nm vi
1955waits for a subsequent key to complete an
1956.Aq escape
1957key mapping.
1958.It Cm errorbells , eb Bq off
1959.Nm ex
1960only.
1961Announce error messages with a bell.
1962.It Cm exrc , ex Bq off
1963Read the startup files in the local directory.
1964.It Cm extended Bq off
1965Use extended regular expressions
1966.Pq EREs
1967rather than basic regular expressions
1968.Pq BREs .
1969See
1970.Xr re_format 7
1971for more information on regular expressions.
1972.It Cm filec Bq no default
1973Set the character to perform file path completion on the colon command line.
1974.It Cm flash Bq off
1975Flash the screen instead of beeping the keyboard on error.
1976.It Cm hardtabs , ht Bq 0
1977Set the spacing between hardware tab settings.
1978This option currently has no effect.
1979.It Cm iclower Bq off
1980Makes all regular expressions case-insensitive,
1981as long as an upper-case letter does not appear in the search string.
1982.It Cm ignorecase , ic Bq off
1983Ignore case differences in regular expressions.
1984.It Cm keytime Bq 6
1985The 10th's of a second
1986.Nm ex Ns / Ns Nm vi
1987waits for a subsequent key to complete a key mapping.
1988.It Cm leftright Bq off
1989.Nm vi
1990only.
1991Do left-right scrolling.
1992.It Cm lines , li Bq 24
1993.Nm vi
1994only.
1995Set the number of lines in the screen.
1996.It Cm lisp Bq off
1997.Nm vi
1998only.
1999Modify various search commands and options to work with Lisp.
2000This option is not yet implemented.
2001.It Cm list Bq off
2002Display lines in an unambiguous fashion.
2003.It Cm lock Bq on
2004Attempt to get an exclusive lock on any file being edited, read or written.
2005.It Cm magic Bq on
2006Treat certain characters specially in regular expressions.
2007.It Cm matchtime Bq 7
2008.Nm vi
2009only.
2010The 10th's of a second
2011.Nm ex Ns / Ns Nm vi
2012pauses on the matching character when the
2013.Cm showmatch
2014option is set.
2015.It Cm mesg Bq on
2016Permit messages from other users.
2017.It Cm msgcat Bq /usr/share/vi/catalog/
2018Selects a message catalog to be used to display error and informational
2019messages in a specified language.
2020.It Cm modelines , modeline Bq off
2021Read the first and last few lines of each file for
2022.Nm ex
2023commands.
2024This option will never be implemented.
2025.It Cm noprint Bq \&"\&"
2026Characters that are never handled as printable characters.
2027.It Cm number, nu Bq off
2028Precede each line displayed with its current line number.
2029.It Cm octal Bq off
2030Display unknown characters as octal numbers, instead of the default
2031hexadecimal.
2032.It Cm open Bq on
2033.Nm ex
2034only.
2035If this option is not set, the
2036.Cm open
2037and
2038.Cm visual
2039commands are disallowed.
2040.It Cm optimize , opt Bq on
2041.Nm vi
2042only.
2043Optimize text throughput to dumb terminals.
2044This option is not yet implemented
2045.It Cm paragraphs , para Bq "IPLPPPQPP LIpplpipbp"
2046.Nm vi
2047only.
2048Define additional paragraph boundaries for the
2049.Cm {\&
2050and
2051.Cm }\&
2052commands.
2053.It Cm path Bq \&"\&"
2054Define additional directories to search for files being edited.
2055.It Cm print Bq \&"\&"
2056Characters that are always handled as printable characters.
2057.It Cm prompt Bq on
2058.Nm ex
2059only.
2060Display a command prompt.
2061.It Cm readonly , ro Bq off
2062Mark the file and session as read-only.
2063.It Cm recdir Bq /var/tmp/vi.recover
2064The directory where recovery files are stored.
2065.It Cm redraw , re Bq off
2066.Nm vi
2067only.
2068Simulate an intelligent terminal on a dumb one.
2069This option is not yet implemented.
2070.It Cm remap Bq on
2071Remap keys until resolved.
2072.It Cm report Bq 5
2073Set the number of lines about which the editor reports changes or yanks.
2074.It Cm ruler Bq off
2075.Nm vi
2076only.
2077Display a row/column ruler on the colon command line.
2078.It Cm scroll , scr Bq "($LINES \- 1) / 2"
2079Set the number of lines scrolled.
2080.It Cm searchincr Bq off
2081Makes the
2082.Cm /
2083and
2084.Cm ?\&
2085commands incremental.
2086.It Cm sections , sect Bq "NHSHH HUnhsh"
2087.Nm vi
2088only.
2089Define additional section boundaries for the
2090.Cm [[
2091and
2092.Cm ]]
2093commands.
2094.It Cm secure Bq off
2095Turns off all access to external programs.
2096.It Cm shell , sh Bq "environment variable SHELL, or /bin/sh"
2097Select the shell used by the editor.
2098.It Cm shellmeta Bq ~{[*?$`'\&"\e
2099Set the meta characters checked to determine if file name expansion
2100is necessary.
2101.It Cm shiftwidth , sw Bq 8
2102Set the autoindent and shift command indentation width.
2103.It Cm showmatch , sm Bq off
2104.Nm vi
2105only.
2106Note matching
2107.Sq {
2108and
2109.Sq \&(
2110for
2111.Sq }
2112and
2113.Sq )\&
2114characters.
2115.It Cm showmode , smd Bq off
2116.Nm vi
2117only.
2118Display the current editor mode and a
2119.Dq modified
2120flag.
2121.It Cm sidescroll Bq 16
2122.Nm vi
2123only.
2124Set the amount a left-right scroll will shift.
2125.It Cm slowopen , slow Bq off
2126Delay display updating during text input.
2127This option is not yet implemented.
2128.It Cm sourceany Bq off
2129Read startup files not owned by the current user.
2130This option will never be implemented.
2131.It Cm tabstop , ts Bq 8
2132This option sets tab widths for the editor display.
2133.It Cm taglength , tl Bq 0
2134Set the number of significant characters in tag names.
2135.It Cm tags, tag Bq tags
2136Set the list of tags files.
2137.It Xo
2138.Cm term , ttytype , tty
2139.Bq "environment variable TERM"
2140.Xc
2141Set the terminal type.
2142.It Cm terse Bq off
2143This option has historically made editor messages less verbose.
2144It has no effect in this implementation.
2145.It Cm tildeop Bq off
2146Modify the
2147.Cm ~
2148command to take an associated motion.
2149.It Cm timeout , to Bq on
2150Time out on keys which may be mapped.
2151.It Cm ttywerase Bq off
2152.Nm vi
2153only.
2154Select an alternate erase algorithm.
2155.It Cm verbose Bq off
2156.Nm vi
2157only.
2158Display an error message for every error.
2159.It Cm w300 Bq no default
2160.Nm vi
2161only.
2162Set the window size if the baud rate is less than 1200 baud.
2163.It Cm w1200 Bq no default
2164.Nm vi
2165only.
2166Set the window size if the baud rate is equal to 1200 baud.
2167.It Cm w9600 Bq no default
2168.Nm vi
2169only.
2170Set the window size if the baud rate is greater than 1200 baud.
2171.It Cm warn Bq on
2172.Nm ex
2173only.
2174This option causes a warning message to be printed on the terminal
2175if the file has been modified since it was last written, before a
2176.Cm !\&
2177command.
2178.It Xo
2179.Cm window , w , wi
2180.Bq "environment variable LINES \- 1"
2181.Xc
2182Set the window size for the screen.
2183.It Cm windowname Bq off
2184Change the icon/window name to the current file name even if it can't
2185be restored on editor exit.
2186.It Cm wraplen , wl Bq 0
2187.Nm vi
2188only.
2189Break lines automatically,
2190the specified number of columns from the left-hand margin.
2191If both the
2192.Cm wraplen
2193and
2194.Cm wrapmargin
2195edit options are set, the
2196.Cm wrapmargin
2197value is used.
2198.It Cm wrapmargin , wm Bq 0
2199.Nm vi
2200only.
2201Break lines automatically,
2202the specified number of columns from the right-hand margin.
2203If both the
2204.Cm wraplen
2205and
2206.Cm wrapmargin
2207edit options are set, the
2208.Cm wrapmargin
2209value is used.
2210.It Cm wrapscan , ws Bq on
2211Set searches to wrap around the end or beginning of the file.
2212.It Cm writeany , wa Bq off
2213Turn off file-overwriting checks.
2214.El
2215.Sh ENVIRONMENT
2216.Bl -tag -width "COLUMNS"
2217.It Ev COLUMNS
2218The number of columns on the screen.
2219This value overrides any system or terminal specific values.
2220If the
2221.Ev COLUMNS
2222environment variable is not set when
2223.Nm ex Ns / Ns Nm vi
2224runs, or the
2225.Cm columns
2226option is explicitly reset by the user,
2227.Nm ex Ns / Ns Nm vi
2228enters the value into the environment.
2229.It Ev EXINIT
2230A list of
2231.Nm ex
2232startup commands, read after
2233.Pa /etc/vi.exrc
2234unless the variable
2235.Ev NEXINIT
2236is also set.
2237.It Ev HOME
2238The user's home directory, used as the initial directory path for the startup
2239.Pa $HOME/.nexrc
2240and
2241.Pa $HOME/.exrc
2242files.
2243This value is also used as the default directory for the
2244.Nm vi
2245.Cm cd
2246command.
2247.It Ev LINES
2248The number of rows on the screen.
2249This value overrides any system or terminal specific values.
2250If the
2251.Ev LINES
2252environment variable is not set when
2253.Nm ex Ns / Ns Nm vi
2254runs, or the
2255.Cm lines
2256option is explicitly reset by the user,
2257.Nm ex Ns / Ns Nm vi
2258enters the value into the environment.
2259.It Ev NEXINIT
2260A list of
2261.Nm ex
2262startup commands, read after
2263.Pa /etc/vi.exrc .
2264.It Ev SHELL
2265The user's shell of choice (see also the
2266.Cm shell
2267option).
2268.It Ev TERM
2269The user's terminal type.
2270The default is the type
2271.Dq unknown .
2272If the
2273.Ev TERM
2274environment variable is not set when
2275.Nm ex Ns / Ns Nm vi
2276runs, or the
2277.Cm term
2278option is explicitly reset by the user,
2279.Nm ex Ns / Ns Nm vi
2280enters the value into the environment.
2281.It Ev TMPDIR
2282The location used to stored temporary files (see also the
2283.Cm directory
2284edit option).
2285.El
2286.Sh ASYNCHRONOUS EVENTS
2287.Bl -tag -width "SIGWINCH" -compact
2288.It Dv SIGALRM
2289.Nm vi Ns / Ns Nm ex
2290uses this signal for periodic backups of file modifications and to display
2291.Dq busy
2292messages when operations are likely to take a long time.
2293.Pp
2294.It Dv SIGHUP
2295.It Dv SIGTERM
2296If the current buffer has changed since it was last written in its entirety,
2297the editor attempts to save the modified file so it can be later recovered.
2298See the
2299.Nm vi Ns / Ns Nm ex
2300reference manual section
2301.Sx Recovery
2302for more information.
2303.Pp
2304.It Dv SIGINT
2305When an interrupt occurs, the current operation is halted
2306and the editor returns to the command level.
2307If interrupted during text input,
2308the text already input is resolved into the file as if the text
2309input had been normally terminated.
2310.Pp
2311.It Dv SIGWINCH
2312The screen is resized.
2313See the
2314.Nm vi Ns / Ns Nm ex
2315reference manual section
2316.Sx Sizing the Screen
2317for more information.
2318.\" .Pp
2319.\" .It Dv SIGCONT
2320.\" .It Dv SIGTSTP
2321.\" .Nm vi Ns / Ns Nm ex
2322.\" ignores these signals.
2323.El
2324.Sh FILES
2325.Bl -tag -width "/var/tmp/vi.recover"
2326.It Pa /bin/sh
2327The default user shell.
2328.It Pa /etc/vi.exrc
2329System-wide
2330.Nm vi
2331startup file.
2332It is read for
2333.Nm ex
2334commands first in the startup sequence.
2335Must be owned by root or the user,
2336and writable only by the owner.
2337.It Pa /tmp
2338Temporary file directory.
2339.It Pa /var/tmp/vi.recover
2340The default recovery file directory.
2341.It Pa $HOME/.nexrc
2342First choice for user's home directory startup file, read for
2343.Nm ex
2344commands right after
2345.Pa /etc/vi.exrc
2346unless either
2347.Ev NEXINIT
2348or
2349.Ev EXINIT
2350are set.
2351Must be owned by root or the user,
2352and writable only by the owner.
2353.It Pa $HOME/.exrc
2354Second choice for user's home directory startup file, read for
2355.Nm ex
2356commands under the same conditions as
2357.Pa $HOME/.nexrc .
2358.It Pa .nexrc
2359First choice for local directory startup file, read for
2360.Nm ex
2361commands at the end of the startup sequence if the
2362.Cm exrc
2363option was turned on earlier.
2364Must be owned by the user
2365and writable only by the owner.
2366.It Pa .exrc
2367Second choice for local directory startup file, read for
2368.Nm ex
2369commands under the same conditions as
2370.Pa .nexrc .
2371.El
2372.Sh EXIT STATUS
2373The
2374.Nm ex
2375and
2376.Nm vi
2377utilities exit 0 on success,
2378and \*(Gt0 if an error occurs.
2379.Sh SEE ALSO
2380.Xr ctags 1 ,
2381.Xr re_format 7
2382.Sh STANDARDS
2383.Nm nex Ns / Ns Nm nvi
2384is close to
2385.St -p1003.1-2008 .
2386That document differs from historical
2387.Nm ex Ns / Ns Nm vi
2388practice in several places; there are changes to be made on both sides.
2389.Sh HISTORY
2390The
2391.Nm nex Ns / Ns Nm nvi
2392replacements for the
2393.Nm ex Ns / Ns Nm vi
2394editor first appeared in
2395.Bx 4.4 .
2396