summaryrefslogtreecommitdiffstats
path: root/docs/USD.doc/vi.man/vi.1
blob: 22aee3e7e952eca270844fa61cfaf1728cfc7f64 (plain)
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
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
.\" Copyright (c) 1994
.\"     The Regents of the University of California.  All rights reserved.
.\" Copyright (c) 1994, 1995, 1996
.\"	Keith Bostic.  All rights reserved.
.\"
.\" This document may not be republished without written permission from
.\" Keith Bostic. 
.\"
.\" See the LICENSE file for redistribution information.
.\"
.\"     @(#)vi.1	8.51 (Berkeley) 10/10/96
.\"
.TH VI 1 "October 10, 1996"
.UC
.SH NAME
ex, vi, view \- text editors
.SH SYNOPSIS
.B ex
[\c
.B -eFRrSsv\c
] [\c
.BI -c " cmd"\c
] [\c
.BI -t " tag"\c
] [\c
.BI -w " size"\c
] [file ...]
.br
.B vi
[\c
.B -eFlRrSv\c
] [\c
.BI -c " cmd"\c
] [\c
.BI -t " tag"\c
] [\c
.BI -w " size"\c
] [file ...]
.br
.B view
[\c
.B -eFRrSv\c
] [\c
.BI -c " cmd"\c
] [\c
.BI -t " tag"\c
] [\c
.BI -w " size"\c
] [file ...]
.SH LICENSE
The vi program is freely redistributable.  You are welcome to copy,
modify and share it with others under the conditions listed in the
LICENSE file.  If any company (not individual!) finds vi sufficiently
useful that you would have purchased it, or if any company wishes to
redistribute it, contributions to the authors would be appreciated.
.SH DESCRIPTION
.I \&Vi
is a screen oriented text editor.
.I \&Ex
is a line-oriented text editor.
.I \&Ex
and
.I \&vi
are different interfaces to the same program,
and it is possible to switch back and forth during an edit session.
.I View
is the equivalent of using the
.B \-R
(read-only) option of
.IR \&vi .
.PP
This manual page is the one provided with the
.I nex/nvi
versions of the
.I ex/vi
text editors.
.I Nex/nvi
are intended as bug-for-bug compatible replacements for the original
Fourth Berkeley Software Distribution (4BSD)
.I \&ex
and
.I \&vi
programs.
For the rest of this manual page,
.I nex/nvi
is used only when it's necessary to distinguish it from the historic
implementations of
.IR ex/vi .
.PP
This manual page is intended for users already familiar with
.IR 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 ``Fast Startup''.
It's probably enough to get you going.
.PP
The following options are available:
.TP
.B \-c
Execute
.B cmd
immediately after starting the edit session.
Particularly useful for initial positioning in the file, however
.B cmd
is not limited to positioning commands.
This is the POSIX 1003.2 interface for the historic ``+cmd'' syntax.
.I Nex/nvi
supports both the old and new syntax.
.TP
.B \-e
Start editing in ex mode, as if the command name were
.IR \&ex .
.TP
.B \-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.)
.TP
.B \-l
Start editing with the lisp and showmatch options set.
.TP
.B \-R
Start editing in read-only mode, as if the command name was
.IR view ,
or the
.B readonly
option was set.
.TP
.B \-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
.B \-r
option had not been specified.
.TP
.B \-S
Run with the
.B secure
edit option set, disallowing all access to external programs.
.TP
.B \-s
Enter batch mode; applicable only to
.I \&ex
edit sessions.
Batch mode is useful when running
.I \&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 ``\-'' argument.
.I \&Nex/nvi
supports both the old and new syntax.
.TP
.B \-t
Start editing at the specified tag.
(See
.IR ctags (1)).
.TP
.B \-w
Set the initial window size to the specified number of lines.
.TP
.B \-v
Start editing in vi mode, as if the command name was
.I \&vi
or
.IR view .
.PP
Command input for
.I ex/vi
is read from the standard input.
In the
.I \&vi
interface, it is an error if standard input is not a terminal.
In the
.I \&ex
interface, if standard input is not a terminal,
.I \&ex
will read commands from it regardless, however, the session will be a
batch mode session, exactly as if the
.B \-s
option had been specified.
.PP
.I 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
.IR \&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
.I \&vi
and have them walk you through this section.
.PP
.I \&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
.IR \&vi ,
and for
.I \&vi
to give information to you.
.PP
The other fact that you need to understand is that
.I \&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 ``escape'' key, usually labeled ``esc'' on your
terminal's keyboard.)
If you're ever confused as to which mode you're in,
keep entering the <escape> key until
.I \&vi
beeps at you.
(Generally,
.I \&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 ``vi file_name<carriage-return>''.
The command you should enter as soon as you start editing is
``: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:
.TP
.B h
Move the cursor left one character.
.TP
.B j
Move the cursor down one line.
.TP
.B k
Move the cursor up one line.
.TP
.B l
Move the cursor right one character.
.TP
.B <cursor-arrows>
The cursor arrow keys should work, too.
.TP
.B /text<carriage-return>
Search for the string ``text'' in the file,
and move the cursor to its first character.
.PP
The commands to enter new text are:
.TP
.B a
Append new text,
.I after
the cursor.
.TP
.B i
Insert new text,
.I before
the cursor.
.TP
.B o
Open a new line below the line the cursor is on, and start
entering text.
.TP
.B O
Open a new line above the line the cursor is on, and start
entering text.
.TP
.B <escape>
Once you've entered input mode using the one of the
.BR \&a ,
.BR \&i ,
.BR \&O
or 
.B \&o
commands, use
.B <escape>
to quit entering text and return to command mode.
.PP
The commands to copy text are:
.TP
.B yy
Copy the line the cursor is on.
.TP
.B p
Append the copied line after the line the cursor is on.
.PP
The commands to delete text are:
.TP
.B dd
Delete the line the cursor is on.
.TP
.B x
Delete the character the cursor is on.
.PP
The commands to write the file are:
.TP
.B :w<carriage-return>
Write the file back to the file with the name that you originally used
as an argument on the
.I \&vi
command line.
.TP
.B ":w file_name<carriage-return>"
Write the file back to the file with the name ``file_name''.
.PP
The commands to quit editing and exit the editor are:
.TP
.B :q<carriage-return>
Quit editing and leave vi (if you've modified the file, but not
saved your changes,
.I \&vi
will refuse to quit).
.TP
.B :q!<carriage-return>
Quit, discarding any modifications that you may have made.
.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 ``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
.I \&vi
editor.
In each entry below, the tag line is a usage synopsis for the command
character.
.PP
.TP
.B "[count] <control-A>"
Search forward
.I count
times for the current word.
.TP
.B "[count] <control-B>"
Page backwards
.I count
screens.
.TP
.B "[count] <control-D>"
Scroll forward
.I count
lines.
.TP
.B "[count] <control-E>"
Scroll forward
.I count
lines, leaving the current line and column as is, if possible.
.TP
.B "[count] <control-F>"
Page forward
.I count
screens.
.TP
.B "<control-G>"
Display the file information.
.TP
.B "<control-H>"
.TP
.B "[count] h"
Move the cursor back
.I count
characters in the current line.
.TP
.B "[count] <control-J>"
.TP
.B "[count] <control-N>"
.TP
.B "[count] j"
Move the cursor down
.I count
lines without changing the current column.
.TP
.B "<control-L>"
.TP
.B "<control-R>"
Repaint the screen.
.TP
.B "[count] <control-M>"
.TP
.B "[count] +"
Move the cursor down
.I count
lines to the first nonblank character of that line.
.TP
.B "[count] <control-P>"
.TP
.B "[count] k"
Move the cursor up
.I count
lines, without changing the current column.
.TP
.B "<control-T>"
Return to the most recent tag context.
.TP
.B "<control-U>"
Scroll backwards
.I count
lines.
.TP
.B "<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.
.TP
.B "<control-Y>"
Scroll backwards
.I count
lines, leaving the current line and column as is, if possible.
.TP
.B "<control-Z>"
Suspend the current editor session.
.TP
.B "<escape>"
Execute
.I \&ex
commands or cancel partial commands.
.TP
.B "<control-]>"
Push a tag reference onto the tag stack.
.TP
.B "<control-^>"
Switch to the most recently edited file.
.TP
.B "[count] <space>"
.TP
.B "[count] l"
Move the cursor forward
.I count
characters without changing the current line.
.TP
.B "[count] ! motion shell-argument(s)"
Replace text with results from a shell command.
.TP
.B "[count] # #|+|-"
Increment or decrement the cursor number.
.TP
.B "[count] $"
Move the cursor to the end of a line.
.TP
.B "%"
Move to the matching character.
.TP
.B "&"
Repeat the previous substitution command on the current line.
.TP
.B "'<character>"
.TP
.B "`<character>"
Return to a context marked by the character
.IR <character> .
.TP
.B "[count] ("
Back up
.I count
sentences.
.TP
.B "[count] )"
Move forward
.I count
sentences.
.TP
.B "[count] ,"
Reverse find character
.I count
times.
.TP
.B "[count] -"
Move to first nonblank of the previous line,
.I count
times.
.TP
.B "[count] ."
Repeat the last
.I \&vi
command that modified text.
.TP
.B "/RE<carriage-return>"
.TP
.B "/RE/ [offset]<carriage-return>"
.TP
.B "?RE<carriage-return>"
.TP
.B "?RE? [offset]<carriage-return>"
.TP
.B "N"
.TP
.B "n"
Search forward or backward for a regular expression.
.TP
.B "0"
Move to the first character in the current line.
.TP
.B ":"
Execute an ex command.
.TP
.B "[count] ;"
Repeat the last character find
.I count
times.
.TP
.B "[count] < motion"
.TP
.B "[count] > motion"
Shift lines left or right.
.TP
.B "@ buffer"
Execute a named buffer.
.TP
.B "[count] A"
Enter input mode, appending the text after the end of the line.
.TP
.B "[count] B"
Move backwards
.I count
bigwords.
.TP
.B "[buffer] [count] C"
Change text from the current position to the end-of-line.
.TP
.B "[buffer] D"
Delete text from the current position to the end-of-line.
.TP
.B "[count] E"
Move forward
.I count
end-of-bigwords.
.TP
.B "[count] F <character>"
Search
.I count
times backward through the current line for
.IR <character> .
.TP
.B "[count] G"
Move to line
.IR count ,
or the last line of the file if
.I count
not specified.
.TP
.B "[count] H"
Move to the screen line
.I "count - 1"
lines below the top of the screen.
.TP
.B "[count] I"
Enter input mode, inserting the text at the beginning of the line.
.TP
.B "[count] J"
Join lines.
.TP
.B "[count] L"
Move to the screen line
.I "count - 1"
lines above the bottom of the screen.
.TP
.B " M"
Move to the screen line in the middle of the screen.
.TP
.B "[count] O"
Enter input mode, appending text in a new line above the current line.
.TP
.B "[buffer] P"
Insert text from a buffer.
.TP
.B "Q"
Exit
.I \&vi
(or visual) mode and switch to
.I \&ex
mode.
.TP
.B "[count] R"
Enter input mode, replacing the characters in the current line.
.TP
.B "[buffer] [count] S"
Substitute
.I count
lines.
.TP
.B "[count] T <character>"
Search backwards,
.I count
times,
through the current line for the character
.I after
the specified
.IR <character> .
.TP
.B "U"
Restore the current line to its state before the cursor last
moved to it.
.TP
.B "[count] W"
Move forward
.I count
bigwords.
.TP
.B "[buffer] [count] X"
Delete
.I count
characters before the cursor.
.TP
.B "[buffer] [count] Y"
Copy (or ``yank'')
.I count
lines into the specified buffer.
.TP
.B "ZZ"
Write the file and exit
.IR \&vi .
.TP
.B "[count] [["
Back up
.I count
section boundaries.
.TP
.B "[count] ]]"
Move forward
.I count
section boundaries.
.TP
.B "\&^"
Move to first nonblank character on the current line.
.TP
.B "[count] _"
Move down
.I "count - 1"
lines, to the first nonblank character.
.TP
.B "[count] a"
Enter input mode, appending the text after the cursor.
.TP
.B "[count] b"
Move backwards
.I count
words.
.TP
.B "[buffer] [count] c motion"
Change a region of text.
.TP
.B "[buffer] [count] d motion"
Delete a region of text.
.TP
.B "[count] e"
Move forward
.I count
end-of-words.
.TP
.B "[count] f<character>"
Search forward,
.I count
times, through the rest of the current line for
.IR <character> .
.TP
.B "[count] i"
Enter input mode, inserting the text before the cursor.
.TP
.B "m <character>"
Save the current context (line and column) as
.IR <character> .
.TP
.B "[count] o"
Enter input mode, appending text in a new line under the current line.
.TP
.B "[buffer] p"
Append text from a buffer.
.TP
.B "[count] r <character>"
Replace
.I count
characters.
.TP
.B "[buffer] [count] s"
Substitute
.I count
characters in the current line starting with the current character.
.TP
.B "[count] t <character>"
Search forward,
.I count
times, through the current line for the character immediately
.I before
.IR <character> .
.TP
.B "u"
Undo the last change made to the file.
.TP
.B "[count] w"
Move forward
.I count
words.
.TP
.B "[buffer] [count] x"
Delete
.I count
characters.
.TP
.B "[buffer] [count] y motion"
Copy (or ``yank'')
a text region specified by the
.I count
and motion into a buffer.
.TP
.B "[count1] z [count2] -|.|+|^|<carriage-return>"
Redraw, optionally repositioning and resizing the screen.
.TP
.B "[count] {"
Move backward
.I count
paragraphs.
.TP
.B "[count] |"
Move to a specific
.I column
position on the current line.
.TP
.B "[count] }"
Move forward
.I count
paragraphs.
.TP
.B "[count] ~"
Reverse the case of the next
.I count
character(s).
.TP
.B "[count] ~ motion"
Reverse the case of the characters in a text region specified by the
.I count
and
.IR motion .
.TP
.B "<interrupt>"
Interrupt the current operation.
.SH VI TEXT INPUT COMMANDS
The following section describes the commands available in the text
input mode of the
.I \&vi
editor.
.PP
.TP
.B "<nul>"
Replay the previous input.
.TP
.B "<control-D>"
Erase to the previous
.B shiftwidth
column boundary.
.TP
.B "^<control-D>"
Erase all of the autoindent characters, and reset the autoindent level.
.TP
.B "0<control-D>"
Erase all of the autoindent characters.
.TP
.B "<control-T>"
Insert sufficient
.I <tab>
and
.I <space>
characters to move forward to the next
.B shiftwidth
column boundary.
.TP
.B "<erase>
.TP
.B "<control-H>"
Erase the last character.
.TP
.B "<literal next>"
Quote the next character.
.TP
.B "<escape>
Resolve all text input into the file, and return to command mode.
.TP
.B "<line erase>"
Erase the current line.
.TP
.B "<control-W>"
.TP
.B "<word erase>"
Erase the last word.
The definition of word is dependent on the
.B altwerase
and
.B ttywerase
options.
.TP
.B "<control-X>[0-9A-Fa-f]+"
Insert a character with the specified hexadecimal value into the text.
.TP
.B "<interrupt>"
Interrupt text input mode, returning to command mode.
.SH EX COMMANDS
The following section describes the commands available in the
.I \&ex
editor.
In each entry below, the tag line is a usage synopsis for the command.
.PP
.TP
.B "<end-of-file>"
Scroll the screen.
.TP
.B "! argument(s)"
.TP
.B "[range]! argument(s)"
Execute a shell command, or filter lines through a shell command.
.TP
.B \&"
A comment.
.TP
.B "[range] nu[mber] [count] [flags]"
.TP
.B "[range] # [count] [flags]"
Display the selected lines, each preceded with its line number.
.TP
.B "@ buffer"
.TP
.B "* buffer"
Execute a buffer.
.TP
.B "[line] a[ppend][!]"
The input text is appended after the specified line.
.TP
.B "[range] c[hange][!] [count]"
The input text replaces the specified range.
.TP
.B "cs[cope] add | find | help | kill | reset"
Execute a Cscope command.
.TP
.B "[range] d[elete] [buffer] [count] [flags]"
Delete the lines from the file.
.TP
.B "di[splay] b[uffers] | c[onnections] | s[creens] | t[ags]"
Display buffers, Cscope connections, screens or tags.
.TP
.B "[Ee][dit][!] [+cmd] [file]"
.TP
.B "[Ee]x[!] [+cmd] [file]"
Edit a different file.
.TP
.B "exu[sage] [command]"
Display usage for an
.I \&ex
command.
.TP
.B "f[ile] [file]"
Display and optionally change the file name.
.TP
.B "[Ff]g [name]"
.I \&Vi
mode only.
Foreground the specified screen.
.TP
.B "[range] g[lobal] /pattern/ [commands]"
.TP
.B "[range] v /pattern/ [commands]"
Apply commands to lines matching (or not matching) a pattern.
.TP
.B "he[lp]"
Display a help message.
.TP
.B "[line] i[nsert][!]"
The input text is inserted before the specified line.
.TP
.B "[range] j[oin][!] [count] [flags]"
Join lines of text together.
.TP
.B "[range] l[ist] [count] [flags]"
Display the lines unambiguously.
.TP
.B "map[!] [lhs rhs]"
Define or display maps (for
.I \&vi
only).
.TP
.B "[line] ma[rk] <character>"
.TP
.B "[line] k <character>"
Mark the line with the mark
.IR <character> .
.TP
.B "[range] m[ove] line"
Move the specified lines after the target line.
.TP
.B "mk[exrc][!] file"
Write the abbreviations, editor options and maps to the specified
file.
.TP
.B "[Nn][ext][!] [file ...]"
Edit the next file from the argument list.
.TP
.B "[line] o[pen] /pattern/ [flags]"
Enter open mode.
.TP
.B "pre[serve]"
Save the file in a form that can later be recovered using the
.I \&ex
.B \-r
option.
.TP
.B "[Pp]rev[ious][!]"
Edit the previous file from the argument list.
.TP
.B "[range] p[rint] [count] [flags]"
Display the specified lines.
.TP
.B "[line] pu[t] [buffer]"
Append buffer contents to the current line.
.TP
.B "q[uit][!]"
End the editing session.
.TP
.B "[line] r[ead][!] [file]"
Read a file.
.TP
.B "rec[over] file"
Recover
.I file
if it was previously saved.
.TP
.B "res[ize] [+|-]size"
.I \&Vi
mode only.
Grow or shrink the current screen.
.TP
.B "rew[ind][!]"
Rewind the argument list.
.TP
.B "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
Display or set editor options.
.TP
.B "sh[ell]"
Run a shell program.
.TP
.B "so[urce] file"
Read and execute
.I \&ex
commands from a file.
.TP
.B "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
.TP
.B "[range] & [options] [count] [flags]"
.TP
.B "[range] ~ [options] [count] [flags]"
Make substitutions.
.TP
.B "su[spend][!]"
.TP
.B "st[op][!]"
.TP
.B <suspend>
Suspend the edit session.
.TP
.B "[Tt]a[g][!] tagstring"
Edit the file containing the specified tag.
.TP
.B "tagn[ext][!]"
Edit the file containing the next context for the current tag.
.TP
.B "tagp[op][!] [file | number]"
Pop to the specified tag in the tags stack.
.TP
.B "tagp[rev][!]"
Edit the file containing the previous context for the current tag.
.TP
.B "unm[ap][!] lhs"
Unmap a mapped string.
.TP
.B "ve[rsion]"
Display the version of the
.I \&ex/vi
editor.
.TP
.B "[line] vi[sual] [type] [count] [flags]"
.I \&Ex
mode only.
Enter
.IR \&vi .
.TP
.B "[Vi]i[sual][!] [+cmd] [file]"
.I \&Vi
mode only.
Edit a new file.
.TP
.B "viu[sage] [command]"
Display usage for a
.I \&vi
command.
.TP
.B "[range] w[rite][!] [>>] [file]"
.TP
.B "[range] w[rite] [!] [file]"
.TP
.B "[range] wn[!] [>>] [file]"
.TP
.B "[range] wq[!] [>>] [file]"
Write the file.
.TP
.B "[range] x[it][!] [file]"
Write the file if it has been modified.
.TP
.B "[range] ya[nk] [buffer] [count]"
Copy the specified lines to a buffer.
.TP
.B "[line] z [type] [count] [flags]"
Adjust the window.
.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
.I \&ex
and
.I \&vi
modes, unless otherwise specified.
.PP
.TP
.B "altwerase [off]"
.I \&Vi
only.
Select an alternate word erase algorithm.
.TP
.B "autoindent, ai [off]"
Automatically indent new lines.
.TP
.B "autoprint, ap [off]"
.I \&Ex
only.
Display the current line automatically.
.TP
.B "autowrite, aw [off]"
Write modified files automatically when changing files.
.\" I cannot get a double quote to print between the square brackets
.\" to save my life.  The ONLY way I've been able to get this to work
.\" is with the .tr command.
.tr Q"
.ds ms backup [QQ]
.TP
.B "\*(ms"
.tr QQ
Backup files before they are overwritten.
.TP
.B "beautify, bf [off]"
Discard control characters.
.TP
.B "cdpath [environment variable CDPATH, or current directory]"
The directory paths used as path prefixes for the
.B cd
command.
.TP
.B "cedit [no default]"
Set the character to edit the colon command-line history.
.TP
.B "columns, co [80]"
Set the number of columns in the screen.
.TP
.B "comment [off]"
.I \&Vi
only.
Skip leading comments in shell, C and C++ language files.
.TP
.B "directory, dir [environment variable TMPDIR, or /tmp]"
The directory where temporary files are created.
.TP
.B "edcompatible, ed [off]"
Remember the values of the ``c'' and ``g'' suffices to the
.B substitute
commands, instead of initializing them as unset for each new
command.
.TP
.B "errorbells, eb [off]"
.I \&Ex
only.
Announce error messages with a bell.
.TP
.B "exrc, ex [off]"
Read the startup files in the local directory.
.TP
.B "extended [off]"
Regular expressions are extended (i.e.
.IR egrep (1)\-\c
style) expressions.
.TP
.B "filec [no default]"
Set the character to perform file path completion on the colon
command line.
.TP
.B "flash [on]"
Flash the screen instead of beeping the keyboard on error.
.TP
.B "hardtabs, ht [8]"
Set the spacing between hardware tab settings.
.TP
.B "iclower [off]"
Makes all Regular Expressions case-insensitive,
as long as an upper-case letter does not appear in the search string.
.TP
.B "ignorecase, ic [off]"
Ignore case differences in regular expressions.
.TP
.B "keytime [6]"
The 10th's of a second
.I ex/vi
waits for a subsequent key to complete a key mapping.
.TP
.B "leftright [off]"
.I \&Vi
only.
Do left-right scrolling.
.TP
.B "lines, li [24]"
.I \&Vi
only.
Set the number of lines in the screen.
.TP
.B "lisp [off]"
.I \&Vi
only.
Modify various search commands and options to work with Lisp.
.I "This option is not yet implemented."
.TP
.B "list [off]"
Display lines in an unambiguous fashion.
.TP
.B "lock [on]"
Attempt to get an exclusive lock on any file being edited,
read or written.
.TP
.B "magic [on]"
Treat certain characters specially in regular expressions.
.TP
.B "matchtime [7]"
.I \&Vi
only.
The 10th's of a second
.I ex/vi
pauses on the matching character when the
.B showmatch
option is set.
.TP
.B "mesg [on]"
Permit messages from other users.
.TP
.B "modelines, modeline [off]"
Read the first and last few lines of each file for
.I ex
commands.
.I "This option will never be implemented."
.\" I cannot get a double quote to print between the square brackets
.\" to save my life.  The ONLY way I've been able to get this to work
.\" is with the .tr command.
.tr Q"
.ds ms noprint [QQ]
.TP
.B "\*(ms"
.tr QQ
Characters that are never handled as printable characters.
.TP
.B "number, nu [off]"
Precede each line displayed with its current line number.
.TP
.B "octal [off]"
Display unknown characters as octal numbers, instead of the default
hexadecimal.
.TP
.B "open [on]"
.I \&Ex
only.
If this option is not set, the
.B open
and
.B visual
commands are disallowed.
.TP
.B "optimize, opt [on]"
.I \&Vi
only.
Optimize text throughput to dumb terminals.
.I "This option is not yet implemented."
.TP
.B "paragraphs, para [IPLPPPQPP LIpplpipbp]"
.I \&Vi
only.
Define additional paragraph boundaries for the
.B \&{
and
.B \&}
commands.
.TP
.B "path []"
Define additional directories to search for files being edited.
.\" I cannot get a double quote to print between the square brackets
.\" to save my life.  The ONLY way I've been able to get this to work
.\" is with the .tr command.
.tr Q"
.ds ms print [QQ]
.TP
.B "\*(ms"
.tr QQ
Characters that are always handled as printable characters.
.TP
.B "prompt [on]"
.I \&Ex
only.
Display a command prompt.
.TP
.B "readonly, ro [off]"
Mark the file and session as read-only.
.TP
.B "recdir [/var/tmp/vi.recover]"
The directory where recovery files are stored.
.TP
.B "redraw, re [off]"
.I \&Vi
only.
Simulate an intelligent terminal on a dumb one.
.I "This option is not yet implemented."
.TP
.B "remap [on]"
Remap keys until resolved.
.TP
.B "report [5]"
Set the number of lines about which the editor reports changes
or yanks.
.TP
.B "ruler [off]"
.I \&Vi
only.
Display a row/column ruler on the colon command line.
.TP
.B "scroll, scr [window / 2]"
Set the number of lines scrolled.
.TP
.B "searchincr [off]"
Makes the
.B \&/
and
.B \&?
commands incremental.
.TP
.B "sections, sect [NHSHH HUnhsh]"
.I \&Vi
only.
Define additional section boundaries for the
.B \&[[
and
.B \&]]
commands.
.TP
.B "secure [off]"
Turns off all access to external programs.
.TP
.B "shell, sh [environment variable SHELL, or /bin/sh]"
Select the shell used by the editor.
.\" I cannot get a double quote to print between the square brackets
.\" to save my life.  The ONLY way I've been able to get this to work
.\" is with the .tr command.
.tr Q"
.ds ms shellmeta [~{[*?$`'Q\e]
.TP
.B "\*(ms"
.tr QQ
Set the meta characters checked to determine if file name expansion
is necessary.
.TP
.B "shiftwidth, sw [8]"
Set the autoindent and shift command indentation width.
.TP
.B "showmatch, sm [off]"
.I \&Vi
only.
Note matching ``{'' and ``('' for ``}'' and ``)'' characters.
.TP
.B "showmode, smd [off]"
.I \&Vi
only.
Display the current editor mode and a ``modified'' flag.
.TP
.B "sidescroll [16]"
.I \&Vi
only.
Set the amount a left-right scroll will shift.
.TP
.B "slowopen, slow [off]"
Delay display updating during text input.
.I "This option is not yet implemented."
.TP
.B "sourceany [off]"
Read startup files not owned by the current user.
.I "This option will never be implemented."
.TP
.B "tabstop, ts [8]"
This option sets tab widths for the editor display.
.TP
.B "taglength, tl [0]"
Set the number of significant characters in tag names.
.TP
.B "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
Set the list of tags files.
.TP
.B "term, ttytype, tty [environment variable TERM]"
Set the terminal type.
.TP
.B "terse [off]"
This option has historically made editor messages less verbose.
It has no effect in this implementation.
.TP
.B "tildeop [off]"
Modify the
.B \&~
command to take an associated motion.
.TP
.B "timeout, to [on]"
Time out on keys which may be mapped.
.TP
.B "ttywerase [off]"
.I \&Vi
only.
Select an alternate erase algorithm.
.TP
.B "verbose [off]"
.I \&Vi
only.
Display an error message for every error.
.TP
.B "w300 [no default]"
.I \&Vi
only.
Set the window size if the baud rate is less than 1200 baud.
.TP
.B "w1200 [no default]"
.I \&Vi
only.
Set the window size if the baud rate is equal to 1200 baud.
.TP
.B "w9600 [no default]"
.I \&Vi
only.
Set the window size if the baud rate is greater than 1200 baud.
.TP
.B "warn [on]"
.I \&Ex
only.
This option causes a warning message to the terminal if the file has
been modified, since it was last written, before a
.B \&!
command.
.TP
.B "window, w, wi [environment variable LINES]"
Set the window size for the screen.
.TP
.B "windowname [off]"
Change the icon/window name to the current file name even if it can't
be restored on editor exit.
.TP
.B "wraplen, wl [0]"
.I \&Vi
only.
Break lines automatically, the specified number of columns from the
left-hand margin.
If both the
.B wraplen
and
.B wrapmargin
edit options are set, the
.B wrapmargin
value is used.
.TP
.B "wrapmargin, wm [0]"
.I \&Vi
only.
Break lines automatically, the specified number of columns from the
right-hand margin.
If both the
.B wraplen
and
.B wrapmargin
edit options are set, the
.B wrapmargin
value is used.
.TP
.B "wrapscan, ws [on]"
Set searches to wrap around the end or beginning of the file.
.TP
.B "writeany, wa [off]"
Turn off file-overwriting checks.
.SH ENVIRONMENTAL VARIABLES
.TP
.I COLUMNS
The number of columns on the screen.
This value overrides any system or terminal specific values.
If the
.I COLUMNS
environmental variable is not set when
.I ex/vi
runs, or the
.B columns
option is explicitly reset by the user,
.I ex/vi
enters the value into the environment.
.TP
.I EXINIT
A list of
.I \&ex
startup commands, read if the variable
.I NEXINIT
is not set.
.TP
.I HOME
The user's home directory, used as the initial directory path
for the startup ``$\fIHOME\fP/.nexrc'' and ``$\fIHOME\fP/.exrc''
files.
This value is also used as the default directory for the
.I \&vi
.B \&cd
command.
.TP
.I LINES
The number of rows on the screen.
This value overrides any system or terminal specific values.
If the
.I LINES
environmental variable is not set when
.I ex/vi
runs, or the
.B lines
option is explicitly reset by the user,
.I ex/vi
enters the value into the environment.
.TP
.I NEXINIT
A list of
.I \&ex
startup commands.
.TP
.I SHELL
The user's shell of choice (see also the
.B shell
option).
.TP
.I TERM
The user's terminal type.
The default is the type ``unknown''.
If the
.I TERM
environmental variable is not set when
.I ex/vi
runs, or the
.B term
option is explicitly reset by the user,
.I ex/vi
enters the value into the environment.
.TP
.I TMPDIR
The location used to stored temporary files (see also the
.B directory
edit option).
.SH ASYNCHRONOUS EVENTS
.TP
SIGALRM
.I \&Vi/ex
uses this signal for periodic backups of file modifications and to
display ``busy'' messages when operations are likely to take a long time.
.TP
SIGHUP
.TP
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
.I \&vi/ex
Reference manual section entitled ``Recovery'' for more information.
.TP
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.
.TP
SIGWINCH
The screen is resized.
See the
.I \&vi/ex
Reference manual section entitled ``Sizing the Screen'' for more information.
.TP
SIGCONT
.TP
SIGQUIT
.TP
SIGTSTP
.I \&Vi/ex
ignores these signals.
.SH FILES
.TP
/bin/sh
The default user shell.
.TP
/etc/vi.exrc
System-wide vi startup file.
.TP
/tmp
Temporary file directory.
.TP
/var/tmp/vi.recover
The default recovery file directory.
.TP
$HOME/.nexrc
1st choice for user's home directory startup file.
.TP
$HOME/.exrc
2nd choice for user's home directory startup file.
.TP
\&.nexrc
1st choice for local directory startup file.
.TP
\&.exrc
2nd choice for local directory startup file.
.SH SEE ALSO
.IR ctags (1),
.IR more (3),
.IR curses (3),
.IR dbopen (3)
.sp
The ``Vi Quick Reference'' card.
.sp
``An Introduction to Display Editing with Vi'', found in the
``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
.I \&vi
screen editor.
.sp
``Ex Reference Manual (Version 3.7)'',
found in the
``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
.I \&ex
editor, as distributed in most historic 4BSD and System V systems.
.sp
``Edit: A tutorial'',
found in the
``UNIX User's Manual Supplementary Documents''
section of the 4.3BSD manual set.
This document is an introduction to a simple version of the
.I \&ex
screen editor.
.sp
``Ex/Vi Reference Manual'',
found in the
``UNIX User's Manual Supplementary Documents''
section of the 4.4BSD manual set.
This document is the final reference for the
.I \&nex/nvi
text editors, as distributed in 4.4BSD and 4.4BSD-Lite.
.PP
.I Roff
source for all of these documents is distributed with
.I nex/nvi
in the
.I nvi/USD.doc
directory of the
.I nex/nvi
source code.
.sp
The files ``autowrite'', ``input'', ``quoting'' and ``structures''
found in the
.I nvi/docs/internals
directory of the
.I nex/nvi
source code.
.SH HISTORY
The
.I nex/nvi
replacements for the
.I ex/vi
editor first appeared in 4.4BSD.
.SH STANDARDS
.I \&Nex/nvi
is close to IEEE Std1003.2 (``POSIX'').
That document differs from historical
.I ex/vi
practice in several places; there are changes to be made on both sides.
OpenPOWER on IntegriCloud