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