aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/vi/USD.doc/vi.man/vi.1
blob: 25f2a2ce0f3b402551c9176539c29616b4d84761 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
.\" Copyright (c) 1994
.\"     The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)vi.1	8.12 (Berkeley) 7/15/94
.\"
.Dd "July 15, 1994"
.Dt EX/VI 1
.Os
.Sh NAME
.Nm ex, vi, view
.Nd text editors
.Sh SYNOPSIS
.Nm \&ex
.Op Fl eFRrsv
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.\".Op Fl X Ar \&aw
.Op Ar "file ..."
.Nm \&vi
.Op Fl eFRrv
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.\".Op Fl X Ar \&aw
.Op Ar "file ..."
.Nm view
.Op Fl eFRrv
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.\".Op Fl X Ar \&aw
.Op Ar "file ..."
.Sh DESCRIPTION
.Nm \&Vi
is a screen oriented text editor.
.Nm \&Ex
is a line-oriented text editor.
.Nm \&Ex
and
.Nm \&vi
are different interfaces to the same program,
and it is possible to switch back and forth during an edit session.
.Nm View
is the equivalent of using the
.Fl R
(read-only) option of
.Nm \&vi .
.Pp
This manual page is the one provided with the
.Nm nex/nvi
versions of the
.Nm ex/vi
text editors.
.Nm Nex/nvi
are intended as bug-for-bug compatible replacements for the original
Fourth Berkeley Software Distribution (4BSD)
.Nm \&ex
and
.Nm \&vi
programs.
For the rest of this manual page,
.Nm nex/nvi
is used only when it's necessary to distinguish it from the historic
implementations of
.Nm ex/vi .
.Pp
This manual page is intended for users already familiar with
.Nm ex/vi .
Anyone else should almost certainly read a good tutorial on the
editor before this manual page.
If you're in an unfamiliar environment, and you absolutely have to
get work done immediately, read the section after the options
description, entitled
.Dq "Fast Startup" .
It's probably enough to get you going.
.Pp
The following options are available:
.Bl -tag -width Ds 
.It Fl c
Execute
.Ar cmd
immediately after starting the edit session.
Particularly useful for initial positioning in the file, however
.Ar cmd
is not limited to positioning commands.
This is the POSIX 1003.2 interface for the historic
.Dq "+cmd"
syntax.
.Nm Nex/nvi
supports both the old and new syntax.
.It Fl e
Start editing in ex mode, as if the command name were
.Nm \&ex .
.It Fl F
Don't copy the entire file when first starting to edit.
(The default is to make a copy in case someone else modifies
the file during your edit session.)
.It Fl R
Start editing in read-only mode, as if the command name was
.Nm view ,
or the readonly option was set.
.It Fl r
Recover the specified files, or, if no files are specified,
list the files that could be recovered.
If no recoverable files by the specified name exist,
the file is edited as if the
.Fl r
option had not been specified.
.It Fl s
Enter batch mode; applicable only to
.Nm \&ex
edit sessions.
Batch mode is useful when running
.Nm \&ex
scripts.
Prompts, informative messages and other user oriented message
are turned off,
and no startup files or environmental variables are read.
This is the POSIX 1003.2 interface for the historic
.Dq \&\-
argument.
.Nm \&Nex/nvi
supports both the old and new syntax.
.It Fl t
Start editing at the specified tag.
(See
.Xr ctags 1 ).
.It Fl w
Set the initial window size to the specified number of lines.
.It Fl v
Start editing in vi mode, as if the command name was
.Nm \&vi
or
.Nm view .
.It Fl X
Reserved for X11 interfaces.
.Em "No X11 support is currently implemented."
.El
.Pp
Command input for
.Nm ex/vi
is read from the standard input.
In the
.Nm \&vi
interface, it is an error if standard input is not a terminal.
In the
.Nm \&ex
interface, if standard input is not a terminal,
.Nm \&ex
will read commands from it regardless, however, the session will be a
batch mode session, exactly as if the
.Fl s
option had been specified.
.Pp
.Nm Ex/vi
exits 0 on success, and greater than 0 if an error occurs.
.Sh FAST STARTUP
This section will tell you the minimum amount that you need to
do simple editing tasks using
.Nm \&vi .
If you've never used any screen editor before, you're likely to have
problems even with this simple introduction.
In that case you should find someone that already knows
.Nm \&vi
and have them walk you through this section.
.Pp
.Nm \&Vi
is a screen editor.
This means that it takes up almost the entire screen, displaying part
of the file on each screen line, except for the last line of the screen.
The last line of the screen is used for you to give commands to
.Nm \&vi ,
and for
.Nm \&vi
to give information to you.
.Pp
The other fact that you need to understand is that
.Nm \&vi
is a modeful editor, i.e. you are either entering text or you
are executing commands, and you have to be in the right mode
to do one or the other.
You will be in command mode when you first start editing a file.
There are commands that switch you into input mode.
There is only one key that takes you out of input mode,
and that is the <escape> key.
(Key names are written using less-than and greater-than signs, e.g.
<escape> means the
.Dq escape
key, usually labeled
.Dq esc
on your terminal's keyboard.)
If you're ever confused as to which mode you're in,
keep entering the <escape> key until
.Nm \&vi
beeps at you.
(Generally,
.Nm \&vi
will beep at you if you try and do something that's not allowed.
It will also display error messages.)
.Pp
To start editing a file, enter the command
.Dq Li "vi file_name<carriage-return>" .
The command you should enter as soon as you start editing is
.Dq Li ":set verbose showmode<carriage-return>" .
This will make the editor give you verbose error messages and display
the current mode at the bottom of the screen.
.Pp
The commands to move around the file are:
.Bl -tag -width XXXX -compact
.It Sy h
Move the cursor left one character.
.It Sy j
Move the cursor down one line.
.It Sy k
Move the cursor up one line.
.It Sy l
Move the cursor right one character.
.It Sy <cursor-arrows>
The cursor arrow keys should work, too.
.It Sy /text<carriage-return>
Search for the string
.Dq text
in the file, and move the cursor to its first character.
.El
.Pp
The commands to enter new text are:
.Bl -tag -width XXXX -compact
.It Sy a
Append new text,
.Em after
the cursor.
.It Sy i
Insert new text,
.Em before
the cursor.
.It Sy o
Open a new line below the line the cursor is on, and start
entering text.
.It Sy O
Open a new line above the line the cursor is on, and start
entering text.
.It Sy <escape>
Once you've entered input mode using the one of the
.Sy \&a ,
.Sy \&i ,
.Sy \&O ,
or 
.Sy \&o
commands, use
.Sy <escape>
to quit entering text and return to command mode.
.El
.Pp
The commands to copy text are:
.Bl -tag -width XXXX -compact
.It Sy yy
Copy the line the cursor is on.
.It Sy p
Append the copied line after the line the cursor is on.
.El
.Pp
The commands to delete text are:
.Bl -tag -width XXXX -compact
.It Sy dd
Delete the line the cursor is on.
.It Sy x
Delete the character the cursor is on.
.El
.Pp
The commands to write the file are:
.Bl -tag -width XXXX -compact
.It Sy :w<carriage-return>
Write the file back to the file with the name that you originally used
as an argument on the
.Nm \&vi
command line.
.It Sy :w file_name<carriage-return>
Write the file back to the file with the name
.Dq file_name .
.El
.Pp
The commands to quit editing and exit the editor are:
.Bl -tag -width XXXX -compact
.It Sy :q<carriage-return>
Quit editing and leave vi (if you've modified the file, but not
saved your changes,
.Nm \&vi
will refuse to quit).
.It Sy :q!<carriage-return>
Quit, discarding any modifications that you may have made.
.El
.Pp
One final caution.
Unusual characters can take up more than one column on the screen,
and long lines can take up more than a single screen line.
The above commands work on
.Dq physical
characters and lines, i.e. they affect the entire line no matter
how many screen lines it takes up and the entire character no matter
how many screen columns it takes up.
.Sh VI COMMANDS
The following section describes the commands available in the command
mode of the
.Nm \&vi
editor.
In each entry below, the tag line is a usage synopsis for the command
character.
.sp
.Bl -tag -width "XXXX" -compact
.It Sy "[count] <control-A>"
Search forward
.Li count
times for the current word.
.It Sy "[count] <control-B>"
Page backwards
.Li count
screens.
.It Sy "[count] <control-D>"
Scroll forward
.Li count
lines.
.It Sy "[count] <control-E>"
Scroll forward
.Li count
lines, leaving the current line and column as is, if possible.
.It Sy "[count] <control-F>"
Page forward
.Li count
screens.
.It Sy "<control-G>"
Display the file information.
.It Sy "<control-H>"
.It Sy "[count] h"
Move the cursor back
.Li count
characters in the current line.
.It Sy "[count] <control-J>"
.It Sy "[count] <control-N>"
.It Sy "[count] j"
Move the cursor down
.Li count
lines without changing the current column.
.It Sy "<control-L>"
.It Sy "<control-R>"
Repaint the screen.
.It Sy "[count] <control-M>"
.It Sy "[count] +"
Move the cursor down
.Li count
lines to the first nonblank character of that line.
.It Sy "[count] <control-P>"
.It Sy "[count] k"
Move the cursor up
.Li count
lines, without changing the current column.
.It Sy "<control-T>"
Return to the most recent tag context.
.It Sy "<control-U>"
Scroll backwards
.Li count
lines.
.It Sy "<control-W>"
Switch to the next lower screen in the window, or, to the first
screen if there are no lower screens in the window.
.It Sy "<control-Y>"
Scroll backwards
.Li count
lines, leaving the current line and column as is, if possible.
.It Sy "<control-Z>"
Suspend the current editor session.
.It Sy "<escape>"
Execute
.Nm \&ex
commands or cancel partial commands.
.It Sy "<control-]>"
Push a tag reference onto the tag stack.
.It Sy "<control-^>"
Switch to the most recently edited file.
.It Sy "[count] <space>"
.It Sy "[count] l"
Move the cursor forward
.Li count
characters without changing the current line.
.It Sy "[count] ! motion shell-argument(s)"
Replace text with results from a shell command.
.It Sy "[count] # +|-|#"
Increment or decrement the cursor number.
.It Sy "[count] $"
Move the cursor to the end of a line.
.It Sy "%"
Move to the matching character.
.It Sy "&"
Repeat the previous substitution command on the current line.
.It Sy "'<character>"
.It Sy "`<character>"
Return to a context marked by the character
.Li <character> .
.It Sy "[count] ("
Back up
.Li count
sentences.
.It Sy "[count] )"
Move forward
.Li count
sentences.
.It Sy "[count] ,"
Reverse find character
.Li count
times.
.It Sy "[count] -"
Move to first nonblank of the previous line,
.Li count
times.
.It Sy "[count] ."
Repeat the last
.Nm \&vi
command that modified text.
.It Sy "/RE<carriage-return>"
.It Sy "/RE/ [offset]<carriage-return>"
.It Sy "?RE<carriage-return>"
.It Sy "?RE? [offset]<carriage-return>"
.It Sy "N"
.It Sy "n"
Search forward or backward for a regular expression.
.It Sy "0"
Move to the first character in the current line.
.It Sy ":"
Execute an ex command.
.It Sy "[count] ;"
Repeat the last character find
.Li count
times.
.It Sy "[count] < motion"
.It Sy "[count] > motion"
Shift lines left or right.
.It Sy "@ buffer"
Execute a named buffer.
.It Sy "[count] A"
Enter input mode, appending the text after the end of the line.
.It Sy "[count] B"
Move backwards
.Li count
bigwords.
.It Sy "[buffer] [count] C"
Change text from the current position to the end-of-line.
.It Sy "[buffer] D"
Delete text from the current position to the end-of-line.
.It Sy "[count] E"
Move forward
.Li count
end-of-bigwords.
.It Sy "[count] F <character>"
Search
.Li count
times backward through the current line for
.Li <character> .
.It Sy "[count] G"
Move to line
.Li count ,
or the last line of the file if
.Li count
not specified.
.It Sy "[count] H"
Move to the screen line
.Li "count - 1"
lines below the top of the screen.
.It Sy "[count] I"
Enter input mode, inserting the text at the beginning of the line.
.It Sy "[count] J"
Join lines.
.It Sy "[count] L"
Move to the screen line
.Li "count - 1"
lines above the bottom of the screen.
.It Sy " M"
Move to the screen line in the middle of the screen.
.It Sy "[count] O"
Enter input mode, appending text in a new line above the current line.
.It Sy "[buffer] P"
Insert text from a buffer.
.It Sy "Q"
Exit
.Nm \&vi
(or visual) mode and switch to
.Nm \&ex
mode.
.It Sy "[count] R"
Enter input mode, replacing the characters in the current line.
.It Sy "[buffer] [count] S"
Substitute
.Li count
lines.
.It Sy "[count] T <character>"
Search backwards,
.Li count
times,
through the current line for the character
.Em after
the specified
.Li <character> .
.It Sy "U"
Restore the current line to its state before the cursor last
moved to it.
.It Sy "[count] W"
Move forward
.Li count
bigwords.
.It Sy "[buffer] [count] X"
Delete
.Li count
characters before the cursor.
.It Sy "[buffer] [count] Y"
Copy (or
.Dq yank )
.Li count
lines into the specified buffer.
.It Sy "ZZ"
Write the file and exit
.Nm \&vi .
.It Sy "[count] [["
Back up
.Li count
section boundaries.
.It Sy "[count] ]]"
Move forward
.Li count
section boundaries.
.It Sy "\&^"
Move to first nonblank character on the current line.
.It Sy "[count] _"
Move down
.Li "count - 1"
lines, to the first nonblank character.
.It Sy "[count] a"
Enter input mode, appending the text after the cursor.
.It Sy "[count] b"
Move backwards
.Li count
words.
.It Sy "[buffer] [count] c motion"
Change a region of text.
.It Sy "[buffer] [count] d motion"
Delete a region of text.
.It Sy "[count] e"
Move forward
.Li count
end-of-words.
.It Sy "[count] f<character>"
Search forward,
.Li count
times, through the rest of the current line for
.Li <character> .
.It Sy "[count] i"
Enter input mode, inserting the text before the cursor.
.It Sy "m <character>"
Save the current context (line and column) as
.Li <character> .
.It Sy "[count] o"
Enter input mode, appending text in a new line under the current line.
.It Sy "[buffer] p"
Append text from a buffer.
.It Sy "[count] r <character>
Replace
.Li count
characters.
.It Sy "[buffer] [count] s"
Substitute
.Li count
characters in the current line starting with the current character.
.It Sy "[count] t <character>"
Search forward,
.Li count
times, through the current line for the character immediately
.Em before
.Li <character> .
.It Sy "u"
Undo the last change made to the file.
.It Sy "[count] w"
Move forward
.Li count
words.
.It Sy "[buffer] [count] x"
Delete
.Li count
characters.
.It Sy "[buffer] [count] y motion"
Copy (or
.Dq yank )
a text region specified by the
.Li count
and motion into a buffer.
.It Sy "[count1] z [count2] -|.|+|^|<carriage-return>"
Redraw, optionally repositioning and resizing the screen.
.It Sy "[count] {"
Move backward
.Li count
paragraphs.
.It Sy "[count] |"
Move to a specific
.Em column
position on the current line.
.It Sy "[count] }"
Move forward
.Li count
paragraphs.
.It Sy "[count] ~"
Reverse the case of the next
.Li count
character(s).
.It Sy "[count] ~ motion"
Reverse the case of the characters in a text region specified by the
.Li count
and
.Li motion .
.It Sy "<interrupt>"
Interrupt the current operation.
.El
.Sh VI TEXT INPUT COMMANDS
The following section describes the commands available in the text
input mode of the
.Nm \&vi
editor.
.Pp
.Bl -tag -width "XXXX" -compact
.It Sy "<nul>"
Replay the previous input.
.It Sy "<control-D>"
Erase the previous autoindent character.
.It Sy "^<control-D>"
Erase all of the autoindent characters, and reset the autoindent level.
.It Sy "0<control-D>"
Erase all of the autoindent characters.
.It Sy "<control-T>"
Insert sufficient
.Li <tab>
and
.Li <space>
characters to move the cursor forward to a column immediately
after the next column which is an even multiple of the
.Sy shiftwidth
option.
.It Sy "<erase>
.It Sy "<control-H>"
Erase the last character.
.It Sy "<literal next>"
Quote the next character.
.It Sy "<escape>
Resolve all text input into the file, and return to command mode.
.It Sy "<line erase>
Erase the current line.
.It Sy "<control-W>"
.It Sy "<word erase>
Erase the last word.
The definition of word is dependent on the
.Sy altwerase
and
.Sy ttywerase
options.
.It Sy "<control-X>[0-9A-Fa-f]*"
Insert a character with the specified hexadecimal value into the text.
.It Sy "<interrupt>"
Interrupt text input mode, returning to command mode.
.El
.Sh EX COMMANDS
The following section describes the commands available in the
.Nm \&ex
editor.
In each entry below, the tag line is a usage synopsis for the command.
.sp
.Bl -tag -width "XXXX" -compact
.It Sy "<end-of-file>"
Scroll the screen.
.It Sy "! argument(s)"
.It Sy "[range]! argument(s)"
Execute a shell command, or filter lines through a shell command.
.It Sy \&"
A comment.
.It Sy "[range] nu[mber] [count] [flags]"
.It Sy "[range] # [count] [flags]"
Display the selected lines, each preceded with its line number.
.It Sy "@ buffer"
.It Sy "* buffer"
Execute a buffer.
.It Sy "[range] d[elete] [buffer] [count] [flags]"
Delete the lines from the file.
.It Sy "di[splay] b[uffers] | s[creens] | t[ags]"
Display buffers, screens or tags.
.It Sy "e[dit][!] [+cmd] [file]"
.It Sy "ex[!] [+cmd] [file]"
Edit a different file.
.It Sy "exu[sage] [command]"
Display usage for an
.Nm \&ex
command.
.It Sy "f[ile] [file]"
Display and optionally change the file name.
.It Sy "fg [name]"
.Nm \&Vi
mode only.
Foreground the specified screen.
.It Sy "[range] g[lobal] /pattern/ [commands]"
.It Sy "[range] v /pattern/ [commands]
Apply commands to lines matching (or not matching) a pattern.
.It Sy "he[lp]"
Display a help message.
.It Sy "[line] i[nsert][!]"
The input text is inserted before the specified line.
.It Sy "[range] j[oin][!] [count] [flags]"
Join lines of text together.
.It Sy "[range] l[ist] [count] [flags]"
Display the lines unambiguously.
.It Sy "map[!] [lhs rhs]"
Define or display maps (for
.Nm \&vi
only).
.It Sy "[line] ma[rk] <character>"
.It Sy "[line] k <character>"
Mark the line with the mark
.Li <character> .
.It Sy "[range] m[ove] line"
Move the specified lines after the target line.
.It Sy "mk[exrc][!] file"
Write the abbreviations, editor options and maps to the specified
file.
.It Sy "n[ext][!] [file ...]"
Edit the next file from the argument list.
.It Sy "[line] o[pen] /pattern/ [flags]"
Enter open mode.
.It Sy "pre[serve]"
Save the file in a form that can later be recovered using the
.Nm \&ex
.Fl r
option.
.It Sy "prev[ious][!]"
Edit the previous file from the argument list.
.It Sy "[range] p[rint] [count] [flags]"
Display the specified lines.
.It Sy "[line] pu[t] [buffer]"
Append buffer contents to the current line.
.It Sy "q[uit][!]"
End the editing session.
.It Sy "[line] r[ead][!] [file]"
Read a file.
.It Sy "rec[over] file"
Recover
.Li file
if it was previously saved.
.It Sy "res[ize] [+|-]size"
.Nm \&Vi
mode only.
Grow or shrink the current screen.
.It Sy "rew[ind][!]"
Rewind the argument list.
.It Sy "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
Display or set editor options.
.It Sy "sh[ell]"
Run a shell program.
.It Sy "so[urce] file"
Read and execute
.Nm \&ex
commands from a file.
.It Sy "sp[lit] [file ...]"
.Nm \&Vi
mode only.
Split the screen.
.It Sy "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
.It Sy "[range] & [options] [count] [flags]"
.It Sy "[range] ~ [options] [count] [flags]"
Make substitutions.
.It Sy "su[spend][!]"
.It Sy "st[op][!]"
.It Sy <suspend>
Suspend the edit session.
.It Sy "ta[g][!] tagstring"
Edit the file containing the specified tag.
.It Sy "tagp[op][!] [file | number]"
Pop to the specified tag in the tags stack.
.It Sy "unm[ap][!] lhs"
Unmap a mapped string.
.It Sy "ve[rsion]"
Display the version of the
.Nm \&ex/vi
editor.
.It Sy "[line] vi[sual] [type] [count] [flags]"
.Nm \&Ex
mode only.
Enter
.Nm \&vi .
.It Sy "vi[sual][!] [+cmd] [file]"
.Nm \&Vi
mode only.
Edit a new file.
.It Sy "viu[sage] [command]"
Display usage for a
.Nm \&vi
command.
.It Sy "[range] w[rite][!] [>>] [file]"
.It Sy "[range] w[rite] [!] [file]"
.It Sy "[range] wn[!] [>>] [file]"
.It Sy "[range] wq[!] [>>] [file]"
Write the file.
.It Sy "[range] x[it][!] [file]"
Write the file if it has been modified.
.It Sy "[range] ya[nk] [buffer] [count]"
Copy the specified lines to a buffer.
.It Sy "[line] z [type] [count] [flags]"
Adjust the window.
.El
.Sh SET OPTIONS
There are a large number of options that may be set (or unset) to
change the editor's behavior.
This section describes the options, their abbreviations and their
default values.
.Pp
In each entry below, the first part of the tag line is the full name
of the option, followed by any equivalent abbreviations.
The part in square brackets is the default value of the option.
Most of the options are boolean, i.e. they are either on or off,
and do not have an associated value.
.Pp
Options apply to both
.Nm \&ex
and
.Nm \&vi
modes, unless otherwise specified.
.sp
.Bl -tag -width "XXXX" -compact
.It Sy "altwerase [off]"
.Nm \&Vi
only.
Select an alternate word erase algorithm.
.It Sy "autoindent, ai [off]"
Automatically indent new lines.
.It Sy "autoprint, ap [off]"
.Nm \&Ex
only.
Display the current line automatically.
.It Sy "autowrite, aw [off]"
Write modified files automatically when changing files.
.It Sy "beautify, bf [off]"
Discard control characters.
.It Sy "cdpath [environment variable CDPATH, or current directory]"
The directory paths used as path prefixes for the
.Sy cd
command.
.It Sy "columns, co [80]"
Set the number of columns in the screen.
.It Sy "comment [off]"
.Nm \&Vi
only.
Skip leading comments in files.
.It Sy "directory, dir [environment variable TMPDIR, or /tmp]"
The directory where temporary files are created.
.It Sy "edcompatible, ed [off]"
Remember the values of the
.Dq \&c
and
.Dq \&g
suffices to the
.Sy substitute
commands, instead of initializing them as unset for each new
command.
.It Sy "errorbells, eb [off]"
.Nm \&Ex
only.
Announce error messages with a bell.
.It Sy "exrc, ex [off]"
Never read startup files in the local directory.
.It Sy "extended [off]"
Regular expressions are extended (i.e.
.Xr egrep 1
style) expressions.
.It Sy "flash [on]"
Flash the screen instead of beeping the keyboard on error.
.It Sy "hardtabs, ht [8]"
Set the spacing between hardware tab settings.
.It Sy "ignorecase, ic [off]"
Ignore case differences in regular expressions.
.It Sy "keytime [6]"
The 10th's of a second
.Nm ex/vi
waits for a subsequent key to complete a key mapping.
.It Sy "leftright [off]"
.Nm \&Vi
only.
Do left-right scrolling.
.It Sy "lines, li [24]"
.Nm \&Vi
only.
Set the number of lines in the screen.
.It Sy "lisp [off]"
.Nm \&Vi
only.
Modify various search commands and options to work with Lisp.
.Pp
.Em "This option is not yet implemented."
.It Sy "list [off]"
Display lines in an unambiguous fashion.
.It Sy "magic [on]"
Treat certain characters specially in regular expressions.
.It Sy "matchtime [7]"
.Nm \&Vi
only.
The 10th's of a second
.Nm ex/vi
pauses on the matching character when the
.Sy showmatch
option is set.
.It Sy "mesg [on]"
Permit messages from other users.
.It Sy "modelines, modeline [off]"
Read the first and last few lines of each file for
.Nm ex
commands.
.Pp
.Em "This option will never be implemented."
.It Sy "number, nu [off]"
Precede each line displayed with its current line number.
.It Sy "octal [off]"
Display unknown characters as octal numbers, instead of the default
hexadecimal.
.It Sy "open [on]"
.Nm \&Ex
only.
If this option is not set, the
.Sy open
and
.Sy visual
commands are disallowed.
.It Sy "optimize, opt [on]"
.Nm \&Vi
only.
Optimize text throughput to dumb terminals.
.Pp
.Em "This option is not yet implemented."
.It Sy "paragraphs, para [IPLPPPQPP LIpplpipbp]"
.Nm \&Vi
only.
Define additional paragraph boundaries for the
.Sy \&{
and
.Sy \&}
commands.
.It Sy "prompt [on]"
.Nm \&Ex
only.
Display a command prompt.
.It Sy "readonly, ro [off]"
Mark the file as read-only.
.It Sy "recdir [/var/tmp/vi.recover]"
The directory where recovery files are stored.
.It Sy "redraw, re [off]"
.Nm \&Vi
only.
Simulate an intelligent terminal on a dumb one.
.Pp
.Em "This option is not yet implemented."
.It Sy "remap [on]"
Remap keys until resolved.
.It Sy "report [5]"
Set the number of lines about which the editor reports changes
or yanks.
.It Sy "ruler [off]"
.Nm \&Vi
only.
Display a row/column ruler on the colon command line.
.It Sy "scroll, scr [window / 2]"
Set the number of lines scrolled.
.It Sy "sections, sect [NHSHH HUnhsh]"
.Nm \&Vi
only.
Define additional section boundaries for the
.Sy \&[[
and
.Sy \&]]
commands.
.It Sy "shell, sh [environment variable SHELL, or /bin/sh]"
Select the shell used by the editor.
.It Sy "shiftwidth, sw [8]"
Set the autoindent and shift command indentation width.
.It Sy "showdirty [off]"
.Nm \&Vi
only.
Display an asterisk on the colon command line if the file has been modified.
.It Sy "showmatch, sm [off]"
.Nm \&Vi
only.
Note matching
.Dq \&{
and
.Dq \&(
for
.Dq \&}
and
.Dq \&)
characters.
.It Sy "showmode [off]"
.Nm \&Vi
only.
Display the current editor mode (command or input).
.It Sy "sidescroll [16]"
.Nm \&Vi
only.
Set the amount a left-right scroll will shift.
.It Sy "slowopen, slow [off]"
Delay display updating during text input.
.Pp
.Em "This option is not yet implemented."
.It Sy "sourceany [off]"
Read startup files not owned by the current user.
.Pp
.Em "This option will never be implemented."
.It Sy "tabstop, ts [8]"
This option sets tab widths for the editor display.
.It Sy "taglength, tl [0]"
Set the number of significant characters in tag names.
.It Sy "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
Set the list of tags files.
.It Sy "term, ttytype, tty [environment variable TERM]"
Set the terminal type.
.It Sy "terse [off]"
This option has historically made editor messages less verbose.
It has no effect in this implementation.
.It Sy "tildeop"
Modify the
.Sy \&~
command to take an associated motion.
.It Sy "timeout, to [on]"
Time out on keys which may be mapped.
.It Sy "ttywerase [off]"
.Nm \&Vi
only.
Select an alternate erase algorithm.
.It Sy "verbose [off]"
.NM \&Vi
only.
Display an error message for every error.
.It Sy "w300 [no default]"
.Nm \&Vi
only.
Set the window size if the baud rate is less than 1200 baud.
.It Sy "w1200 [no default]"
.Nm \&Vi
only.
Set the window size if the baud rate is equal to 1200 baud.
.It Sy "w9600 [no default]"
.Nm \&Vi
only.
Set the window size if the baud rate is greater than 1200 baud.
.It Sy "warn [on]"
.Nm \&Ex
only.
This option causes a warning message to the terminal if the file has
been modified, since it was last written, before a
.Sy \&!
command.
.It Sy "window, w, wi [environment variable LINES]"
Set the window size for the screen.
.It Sy "wrapmargin, wm [0]"
.Nm \&Vi
only.
Break lines automatically when they reach the right-hand margin.
.It Sy "wrapscan, ws [on]"
Set searches to wrap around the end or beginning of the file.
.It Sy "writeany, wa [off]"
Turn off file-overwriting checks.
.El
.Sh ENVIRONMENTAL VARIABLES
.Bl -tag -width "COLUMNSXX" -compact
.It Ev COLUMNS
The number of columns on the screen.
This value overrides any system or terminal specific values.
If the COLUMNS environmental variable is not set when
.Nm ex/vi
runs, or the
.Sy columns
option is explicitly reset by the user,
.Nm ex/vi
enters the value into the environment.
.It Ev EXINIT
A list of
.Nm \&ex
startup commands, read if the variable
.Ev NEXINIT
is not set.
.It Ev HOME
The user's home directory, used as the initial directory path
for the startup
.Pa $HOME/.nexrc
and
.Pa $HOME/.exrc
files.
This value is also used as the default directory for the
.Nm \&vi
.Sy \&cd
command.
.It Ev LINES
The number of rows on the screen.
This value overrides any system or terminal specific values.
If the LINES environmental variable is not set when
.Nm ex/vi
runs, or the
.Sy lines
option is explicitly reset by the user,
.Nm ex/vi
enters the value into the environment.
.It Ev NEXINIT
A list of
.Nm \&ex
startup commands.
.It Ev SHELL
The user's shell of choice (see also the
.Sy shell
option).
.It Ev TERM
The user's terminal type.
The default is the type
.Dq unknown .
If the TERM environmental variable is not set when
.Nm ex/vi
runs, or the
.Sy term
option is explicitly reset by the user,
.Nm ex/vi
enters the value into the environment.
.It Ev TMPDIR
The location used to stored temporary files (see also the
.Sy directory
option).
.El
.Sh ASYNCHRONOUS EVENTS
.Bl -tag -width "SIGWINCHXX" -compact
.It SIGALRM
.Nm \&Vi/ex
uses this signal for periodic backups of file modifications
and to display
.Dq busy
messages when operations are likely to take a long time.
.It SIGHUP
.It SIGTERM
If the current buffer has changed since it was last written in its
entirety, the editor attempts to save the modified file so it can
be later recovered.
See the
.Nm \&vi/ex
Reference manual section entitled
.Dq Recovery
for more information.
.It SIGINT
When an interrupt occurs,
the current operation is halted,
and the editor returns to the command level.
If interrupted during text input,
the text already input is resolved into the file as if the text
input had been normally terminated.
.It SIGWINCH
The screen is resized.
See the
.Nm \&vi/ex
Reference manual section entitled
.Dq "Sizing the Screen"
for more information.
.It SIGCONT
.It SIGQUIT
.It SIGTSTP
.Nm \&Vi/ex
ignores these signals.
.El
.Sh BUGS
See the file
.Pa nvi/docs/bugs.current
for a list of the known bugs in this version.
.Sh FILES
.Bl -tag -width /var/tmp/vi.recover -compact
.It Pa /bin/sh
The default user shell.
.It Pa /etc/vi.exrc
System-wide vi startup file.
.It Pa /tmp
Temporary file directory.
.It Pa /var/tmp/vi.recover
The default recovery file directory.
.It Pa $HOME/.nexrc
1st choice for user's home directory startup file.
.It Pa $HOME/.exrc
2nd choice for user's home directory startup file.
.It Pa .nexrc
1st choice for local directory startup file.
.It Pa .exrc
2nd choice for local directory startup file.
.El
.Sh SEE ALSO
.Xr ctags 1 ,
.Xr more 1 ,
.Xr curses 3 ,
.Xr dbopen 3
.sp
The
.Dq "Vi Quick Reference"
card.
.sp
.Dq "\&An Introduction to Display Editing with Vi" ,
found in the
.Dq "UNIX User's Manual Supplementary Documents"
section of both the 4.3BSD and 4.4BSD manual sets.
This document is the closest thing available to an introduction to the
.Nm \&vi
screen editor.
.sp
.Dq "\&Ex Reference Manual (Version 3.7)" ,
found in the
.Dq "UNIX User's Manual Supplementary Documents"
section of both the 4.3BSD and 4.4BSD manual sets.
This document is the final reference for the
.Nm \&ex
editor, as distributed in most historic 4BSD and System V systems.
.sp
.Dq "Edit: A tutorial" ,
found in the
.Dq "UNIX User's Manual Supplementary Documents"
section of the 4.3BSD manual set.
This document is an introduction to a simple version of the
.Nm \&ex
screen editor.
.sp
.Dq "\&Ex/Vi Reference Manual" ,
found in the
.Dq "UNIX User's Manual Supplementary Documents"
section of the 4.4BSD manual set.
This document is the final reference for the
.Nm \&nex/nvi
text editors, as distributed in 4.4BSD and 4.4BSD-Lite.
.Pp
.Nm Roff
source for all of these documents is distributed with
.Nm nex/nvi
in the
.Pa nvi/USD.doc
directory of the
.Nm nex/nvi
source code.
.sp
The files
.Dq autowrite ,
.Dq input ,
.Dq quoting ,
and
.Dq structures ,
found in the
.Pa nvi/docs/internals
directory of the
.Nm nex/nvi
source code.
.Sh HISTORY
The
.Nm nex/nvi
replacements for the
.Nm ex/vi
editor first appeared in 4.4BSD.
.Sh STANDARDS
.Nm \&Nex/nvi
is close to IEEE Std1003.2 (``POSIX'').
That document differs from historical
.Nm ex/vi
practice in several places; there are changes to be made on both sides.