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