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
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
|
.\" $OpenBSD: vi.1,v 1.28 2004/04/09 12:12:44 jmc Exp $
.\"
.\" 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
.\"
.Dd October 10, 1996
.Dt VI 1
.Os
.Sh NAME
.Nm ex , vi , view
.Nd text editor
.Sh SYNOPSIS
.Nm ex
.Op Fl FRrSsv
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.Op Ar file ...
.Nm vi\ \&
.Op Fl eFRrS
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.Op Ar file ...
.Nm view
.Op Fl eFrS
.Op Fl c Ar cmd
.Op Fl t Ar tag
.Op Fl w Ar size
.Op Ar file ...
.Sh DESCRIPTION
.Nm ex
is a line-oriented text editor;
.Nm vi
is a screen-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
.Pq read-only
option of
.Nm vi .
.Pp
This manual page is the one provided with the
.Nm nex Ns / Ns Nm nvi
versions of the
.Nm ex Ns / Ns Nm vi
text editors.
.Nm nex Ns / Ns Nm nvi
are intended as bug-for-bug compatible replacements for the original
Fourth Berkeley Software Distribution
.Pq 4BSD
.Nm ex
and
.Nm vi
programs.
For the rest of this manual page,
.Nm nex Ns / Ns Nm nvi
is used only when it's necessary to distinguish it from the historic
implementations of
.Nm ex Ns / Ns Nm vi .
.Pp
This manual page is intended for users already familiar with
.Nm ex Ns / Ns Nm vi .
Anyone else should almost certainly read a good tutorial on the
editor before this manual page.
See the
.Sx SEE ALSO
section below, for a list of additional materials.
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 "-w size "
.It Fl c Ar cmd
Execute
.Ar cmd
on the first file loaded.
Particularly useful for initial positioning in the file, although
.Ar cmd
is not limited to positioning commands.
This is the POSIX 1003.2 interface for the historic
.Dq +cmd
syntax.
.Nm nex Ns / Ns Nm 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 l
.\" Start editing with the lisp and showmatch options set.
.It Fl R
Start editing in read-only mode, as if the command name was
.Nm view ,
or the
.Cm 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
Run with the
.Cm secure
edit option set, disallowing all access to external programs.
.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 messages are turned off,
and no startup files or environment variables are read.
This is the POSIX 1003.2 interface for the historic
.Dq -
argument.
.Nm nex Ns / Ns Nm nvi
supports both the old and new syntax.
.It Fl t Ar tag
Start editing at the specified
.Ar tag
(see
.Xr ctags 1 ) .
.It Fl w Ar size
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 .
.El
.Pp
Command input for
.Nm ex Ns / Ns Nm 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 Ns / Ns Nm vi
exits 0 on success, or 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
.Aq escape
key.
(Key names are written using less-than and greater-than signs, e.g.\&
.Aq 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
.Aq 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
.Pp
.Dl vi file_name
.Pp
The command you should enter as soon as you start editing is
.Pp
.Dl :set verbose showmode
.Pp
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 Ds
.It Cm h
Move the cursor left one character.
.It Cm j
Move the cursor down one line.
.It Cm k
Move the cursor up one line.
.It Cm l
Move the cursor right one character.
.It Aq Cm cursor-arrows
The cursor arrow keys should work, too.
.It Cm / Ns text
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 "<escape>"
.It Cm a
Append new text, after the cursor.
.It Cm i
Insert new text, before the cursor.
.It Cm O
Open a new line above the line the cursor is on, and start entering text.
.It Cm o
Open a new line below the line the cursor is on, and start entering text.
.It Aq Cm escape
Once you've entered input mode using one of the
.Cm a ,
.Cm i ,
.Cm O
or
.Cm o
commands, use
.Aq Cm escape
to quit entering text and return to command mode.
.El
.Pp
The commands to copy text are:
.Bl -tag -width Ds
.It Cm p
Append the copied line after the line the cursor is on.
.It Cm yy
Copy the line the cursor is on.
.El
.Pp
The commands to delete text are:
.Bl -tag -width Ds
.It Cm dd
Delete the line the cursor is on.
.It Cm x
Delete the character the cursor is on.
.El
.Pp
The commands to write the file are:
.Bl -tag -width Ds
.It Cm :w
Write the file back to the file with the name that you originally used
as an argument on the
.Nm vi
command line.
.It Cm :w Ar file_name
Write the file back to the file with the name
.Ar file_name .
.El
.Pp
The commands to quit editing and exit the editor are:
.Bl -tag -width Ds
.It Cm :q
Quit editing and leave
.Nm vi
(if you've modified the file, but not saved your changes,
.Nm vi
will refuse to quit).
.It Cm :q!
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.
.Pp
.Bl -tag -width Ds -compact
.It Xo
.\" .Op Ar count
.Aq Cm control-A
.Xc
Search forward
.\" .Ar count
.\" times
for the current word.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-B
.Xc
Page backwards
.Ar count
screens.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-D
.Xc
Scroll forward
.Ar count
lines.
If
.Ar count
is not given, scroll forward half the number of lines in the current screen.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-E
.Xc
Scroll forward
.Ar count
lines, leaving the current line and column as is, if possible.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-F
.Xc
Page forward
.Ar count
screens.
.Pp
.It Aq Cm control-G
Display the file information.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-H
.Xc
.It Xo
.Op Ar count
.Cm h
.Xc
Move the cursor back
.Ar count
characters in the current line.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-J
.Xc
.It Xo
.Op Ar count
.Aq Cm control-N
.Xc
.It Xo
.Op Ar count
.Cm j
.Xc
Move the cursor down
.Ar count
lines without changing the current column.
.Pp
.It Aq Cm control-L
.It Aq Cm control-R
Repaint the screen.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-M
.Xc
.It Xo
.Op Ar count
.Cm +
.Xc
Move the cursor down
.Ar count
lines to the first non-blank character of that line.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-P
.Xc
.It Xo
.Op Ar count
.Cm k
.Xc
Move the cursor up
.Ar count
lines, without changing the current column.
.Pp
.It Aq Cm control-T
Return to the most recent tag context.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-U
.Xc
Scroll backwards
.Ar count
lines.
If
.Ar count
is not given, scroll forward half the number of lines in the current screen.
.Pp
.It Aq Cm 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.
.Pp
.It Xo
.Op Ar count
.Aq Cm control-Y
.Xc
Scroll backwards
.Ar count
lines, leaving the current line and column as is, if possible.
.Pp
.It Aq Cm control-Z
Suspend the current editor session.
.Pp
.It Aq Cm escape
Execute
.Nm ex
commands or cancel partial commands.
.Pp
.It Aq Cm control-]
Push a tag reference onto the tag stack.
.Pp
.It Aq Cm control-^
Switch to the most recently edited file.
.Pp
.It Xo
.Op Ar count
.Aq Cm space
.Xc
.It Xo
.Op Ar count
.Cm l
.Xc
Move the cursor forward
.Ar count
characters without changing the current line.
.Pp
.It Xo
.Op Ar count
.Cm !\&
.Ar motion shell-argument(s)
.Aq Li carriage-return
.Xc
Replace text with results from a shell command.
.Pp
.It Xo
.Op Ar count
.Cm #
.Sm off
.Cm # | + | -
.Sm on
.Xc
Increment or decrement the number under the cursor.
If the trailing character is a
.Sq #
or
.Sq + ,
the number is incremented.
If the trailing character is a
.Sq - ,
the number is decremented.
.Pp
.It Xo
.Op Ar count
.Cm $
.Xc
Move the cursor to the end of a line.
.Pp
.It Cm %
Move to the matching character.
.Pp
.It Cm &
Repeat the previous substitution command on the current line.
.Pp
.It Xo
.Cm ' Ns Aq Ar character
.Xc
.It Xo
.Cm ` Ns Aq Ar character
.Xc
Return to a context marked by the character
.Ar character .
The first form returns to the beginning of the line marked by
.Ar character .
The second form returns to the first character of the context marked by
.Ar character .
.Pp
.It Xo
.Op Ar count
.Cm (\&
.Xc
Back up
.Ar count
sentences.
.Pp
.It Xo
.Op Ar count
.Cm )\&
.Xc
Move forward
.Ar count
sentences.
.Pp
.It Xo
.Op Ar count
.Cm ,\&
.Xc
Reverse find character
.Ar count
times.
.Pp
.It Xo
.Op Ar count
.Cm -
.Xc
Move to the first non-blank of the previous line,
.Ar count
times.
.Pp
.It Xo
.Op Ar count
.Cm .\&
.Xc
Repeat the last
.Nm vi
command that modified text.
.Pp
.It Xo
.Pf / Ns Ar RE
.Aq Li carriage-return
.Xc
.It Xo
.Pf / Ns Ar RE Ns /
.Op Ar offset
.Aq Li carriage-return
.Xc
.It Xo
.Pf ?\& Ns Ar RE
.Aq Li carriage-return
.Xc
.It Xo
.Pf ?\& Ns Ar RE Ns ?\&
.Op Ar offset
.Aq Li carriage-return
.Xc
.It Cm N
.It Cm n
Search forward
.Pq Sq /
or backward
.Pq Sq ?\&
for a regular expression.
.Cm n
and
.Cm N
repeat the last search in the same or opposite directions, respectively.
If
.Ar offset
is specified, the cursor is placed
.Ar offset
lines before or after the matched regular expression.
.Pp
.It Cm 0
Move to the first character in the current line.
.Pp
.It Cm :\&
Execute an
.Nm ex
command.
.Pp
.It Xo
.Op Ar count
.Cm ;\&
.Xc
Repeat the last character find
.Ar count
times.
.Pp
.It Xo
.Op Ar count
.Pf \ \&< Ar motion
.Xc
.It Xo
.Op Ar count
.Pf \ \&> Ar motion
.Xc
Shift lines left or right.
.Pp
.It Cm @ Ar buffer
Execute a named
.Ar buffer .
.Pp
.It Xo
.Op Ar count
.Cm A
.Xc
Enter input mode, appending the text after the end of the line.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\- 1 number of times.
.Pp
.It Xo
.Op Ar count
.Cm B
.Xc
Move backwards
.Ar count
bigwords.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm C
.Xc
Change text from the current position to the end-of-line.
If
.Ar buffer
is specified,
.Dq yank
the deleted text into
.Ar buffer .
.Pp
.It Xo
.Op Ar buffer
.Cm D
.Xc
Delete text from the current position to the end-of-line.
If
.Ar buffer
is specified,
.Dq yank
the deleted text into
.Ar buffer .
.Pp
.It Xo
.Op Ar count
.Cm E
.Xc
Move forward
.Ar count
end-of-bigwords.
.Pp
.It Xo
.Op Ar count
.Cm F Aq Ar character
.Xc
Search
.Ar count
times backward through the current line for
.Ar character .
.Pp
.It Xo
.Op Ar count
.Cm G
.Xc
Move to line
.Ar count ,
or the last line of the file if
.Ar count
is not specified.
.Pp
.It Xo
.Op Ar count
.Cm H
.Xc
Move to the screen line
.Ar count
\- 1 lines below the top of the screen.
.Pp
.It Xo
.Op Ar count
.Cm I
.Xc
Enter input mode, inserting the text at the beginning of the line.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\- 1 number of times.
.Pp
.It Xo
.Op Ar count
.Cm J
.Xc
Join lines.
.Pp
.It Xo
.Op Ar count
.Cm L
.Xc
Move to the screen line
.Ar count
\- 1 lines above the bottom of the screen.
.Pp
.It Cm M
Move to the screen line in the middle of the screen.
.Pp
.It Xo
.Op Ar count
.Cm O
.Xc
Enter input mode, appending text in a new line above the current line.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\- 1 number of times.
.Pp
.It Xo
.Op Ar buffer
.Cm P
.Xc
Insert text from a buffer.
.Pp
.It Cm Q
Exit
.Nm vi
.Pq or visual
mode and switch to
.Nm ex
mode.
.Pp
.It Xo
.Op Ar count
.Cm R
.Xc
Enter input mode, replacing the characters in the current line.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\- 1 number of times.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm S
.Xc
Substitute
.Ar count
lines.
If
.Ar buffer
is specified,
.Dq yank
the deleted text into
.Ar buffer .
.Pp
.It Xo
.Op Ar count
.Cm T
.Aq Ar character
.Xc
Search backwards,
.Ar count
times, through the current line for the character after the specified
.Ar character .
.Pp
.It Cm U
Restore the current line to its state before the cursor last moved to it.
.Pp
.It Xo
.Op Ar count
.Cm W
.Xc
Move forward
.Ar count
bigwords.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm X
.Xc
Delete
.Ar count
characters before the cursor.
If
.Ar buffer
is specified,
.Dq yank
the deleted text into
.Ar buffer .
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm Y
.Xc
Copy (or
.Dq yank )
.Ar count
lines into the specified
.Ar buffer ,
or the default buffer if none is specified.
.Pp
.It Cm ZZ
Write the file and exit
.Nm vi .
.Pp
.It Xo
.Op Ar count
.Cm [[
.Xc
Back up
.Ar count
section boundaries.
.Pp
.It Xo
.Op Ar count
.Cm ]]
.Xc
Move forward
.Ar count
section boundaries.
.Pp
.It Cm ^
Move to the first non-blank character on the current line.
.Pp
.It Xo
.Op Ar count
.Cm _
.Xc
Move down
.Ar count
\- 1 lines, to the first non-blank character.
.Pp
.It Xo
.Op Ar count
.Cm a
.Xc
Enter input mode, appending the text after the cursor.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\-1 number of times.
.Pp
.It Xo
.Op Ar count
.Cm b
.Xc
Move backwards
.Ar count
words.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm c
.Ar motion
.Xc
Change a region of text.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm d
.Ar motion
.Xc
Delete a region of text.
.Pp
.It Xo
.Op Ar count
.Cm e
.Xc
Move forward
.Ar count
end-of-words.
.Pp
.It Xo
.Op Ar count
.Cm f Aq Ar character
.Xc
Search forward,
.Ar count
times, through the rest of the current line for
.Aq Ar character .
.Pp
.It Xo
.Op Ar count
.Cm i
.Xc
Enter input mode, inserting the text before the cursor.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\-1 number of times.
.Pp
.It Xo
.Cm m
.Aq Ar character
.Xc
Save the current context
.Pq line and column
as
.Aq Ar character .
.Pp
.It Xo
.Op Ar count
.Cm o
.Xc
Enter input mode, appending text in a new line under the current line.
If a
.Ar count
argument is given,
the characters input are repeated
.Ar count
\- 1 number of times.
.Pp
.It Xo
.Op Ar buffer
.Cm p
.Xc
Append text from a buffer.
.Pp
.It Xo
.Op Ar count
.Cm r
.Aq Ar character
.Xc
Replace
.Ar count
characters.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm s
.Xc
Substitute
.Ar count
characters in the current line starting with the current character.
.Pp
.It Xo
.Op Ar count
.Cm t
.Aq Ar character
.Xc
Search forward,
.Ar count
times, through the current line for the character immediately before
.Aq Ar character .
.Pp
.It Cm u
Undo the last change made to the file.
.Pp
.It Xo
.Op Ar count
.Cm w
.Xc
Move forward
.Ar count
words.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm x
.Xc
Delete
.Ar count
characters.
.Pp
.It Xo
.Op Ar buffer
.Op Ar count
.Cm y
.Ar motion
.Xc
Copy (or
.Dq yank )
a text region specified by
.Ar count
and
.Ar motion
into a buffer.
.Pp
.It Xo
.Op Ar count1
.Cm z
.Op Ar count2
.Cm type
.Xc
Redraw, optionally repositioning and resizing the screen.
If
.Ar count2
is specified, limit the screen size to
.Ar count2
lines.
The following
.Cm type
characters may be used:
.Bl -tag -width Ds
.It Cm +
If
.Ar count1
is specified, place the line
.Ar count1
at the top of the screen.
Otherwise, display the screen after the current screen.
.It Aq Cm carriage-return
Place the line
.Ar count1
at the top of the screen.
.It Cm .\&
Place the line
.Ar count1
in the center of the screen.
.It Cm -
Place the line
.Ar count1
at the bottom of the screen.
.It Cm ^
If
.Ar count1
is given,
display the screen before the screen before
.Ar count1
.Pq i.e. 2 screens before .
Otherwise, display the screen before the current screen.
.El
.Pp
.It Xo
.Op Ar count
.Cm {\&
.Xc
Move backward
.Ar count
paragraphs.
.Pp
.It Xo
.Op Ar column
.Cm |\&
.Xc
Move to a specific
.Ar column
position on the current line.
If
.Ar column
is omitted,
move to the start of the current line.
.Pp
.It Xo
.Op Ar count
.Cm }\&
.Xc
Move forward
.Ar count
paragraphs.
.Pp
.It Xo
.Op Ar count
.Cm ~
.Xc
Reverse the case of the next
.Ar count
character(s).
.Pp
.It Xo
.Op Ar count
.Cm ~
.Ar motion
.Xc
Reverse the case of the characters in a text region specified by the
.Ar count
and
.Ar motion .
Only in effect if the
.Cm tildeop
option is set.
.Pp
.It Aq Cm interrupt
Interrupt the current operation.
The
.Aq interrupt
character is usually
.Aq control-C .
.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 Ds -compact
.It Aq Cm nul
Replay the previous input.
.Pp
.It Aq Cm control-D
Erase to the previous
.Ar shiftwidth
column boundary.
.Pp
.It Cm ^ Ns Aq Cm control-D
Erase all of the autoindent characters, and reset the autoindent level.
.Pp
.It Cm 0 Ns Aq Cm control-D
Erase all of the autoindent characters.
.Pp
.It Aq Cm control-T
Insert sufficient
.Aq tab
and
.Aq space
characters to move forward to the next
.Ar shiftwidth
column boundary.
.Pp
.It Aq Cm erase
.It Aq Cm control-H
Erase the last character.
.Pp
.It Aq Cm literal next
Escape the next character from any special meaning.
The
.Aq literal\ \&next
character is usually
.Aq control-V .
.Pp
.It Aq Cm escape
Resolve all text input into the file, and return to command mode.
.Pp
.It Aq Cm line erase
Erase the current line.
.Pp
.It Aq Cm control-W
.It Aq Cm word erase
Erase the last word.
The definition of word is dependent on the
.Cm altwerase
and
.Cm ttywerase
options.
.Pp
.Sm off
.It Xo
.Aq Cm control-X
.Bq Cm 0-9A-Fa-f
.Cm +
.Xc
.Sm on
Insert a character with the specified hexadecimal value into the text.
.Pp
.It Aq Cm interrupt
Interrupt text input mode, returning to command mode.
The
.Aq interrupt
character is usually
.Aq control-C .
.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.
.Pp
.Bl -tag -width Ds -compact
.It Aq Cm end-of-file
Scroll the screen.
.Pp
.It Cm !\& Ar argument(s)
.It Xo
.Op Ar range
.Cm !\&
.Ar argument(s)
.Xc
Execute a shell command, or filter lines through a shell command.
.Pp
.It Cm \&"
A comment.
.Pp
.It Xo
.Op Ar range
.Cm nu Ns Op Cm mber
.Op Ar count
.Op Ar flags
.Xc
.It Xo
.Op Ar range
.Cm #
.Op Ar count
.Op Ar flags
.Xc
Display the selected lines, each preceded with its line number.
.Pp
.It Cm @ Ar buffer
.It Cm * Ar buffer
Execute a buffer.
.Pp
.It Xo
.Op Ar range
.Cm < Ns Op Cm < ...
.Op Ar count
.Op Ar flags
.Xc
Shift lines left.
.Pp
.It Xo
.Op Ar line
.Cm =
.Op Ar flags
.Xc
Display the line number of
.Ar line .
If
.Ar line
is not specified, display the line number of the last line in the file.
.Pp
.It Xo
.Op Ar range
.Cm > Ns Op Cm > ...
.Op Ar count
.Op Ar flags
.Xc
Shift lines right.
.Pp
.It Xo
.Cm ab Ns Op Cm breviate
.Ar lhs rhs
.Xc
.Nm vi
only.
Add
.Ar lhs
as an abbreviation for
.Ar rhs
to the abbreviation list.
.Pp
.It Xo
.Op Ar line
.Cm a Ns Op Cm ppend Ns
.Op Cm !\&
.Xc
The input text is appended after the specified line.
.Pp
.It Cm ar Ns Op Cm gs
Display the argument list.
.Pp
.It Cm bg
.Nm vi
only.
Background the current screen.
.Pp
.It Xo
.Op Ar range
.Cm c Ns Op Cm hange Ns
.Op Cm !\&
.Op Ar count
.Xc
The input text replaces the specified range.
.Pp
.It Xo
.Cm chd Ns Op Cm ir Ns
.Op Cm !\&
.Op Ar directory
.Xc
.It Xo
.Cm cd Ns Op Cm !\&
.Op Ar directory
.Xc
Change the current working directory.
.Pp
.It Xo
.Op Ar range
.Cm co Ns Op Cm py
.Ar line
.Op Ar flags
.Xc
.It Xo
.Op Ar range
.Cm t
.Ar line
.Op Ar flags
.Xc
Copy the specified lines after the destination
.Ar line .
.Pp
.It Xo
.Cm cs Ns Op Cm cope
.Cm add | find | help | kill | reset
.Xc
Execute a Cscope command.
.Pp
.It Xo
.Op Ar range
.Cm d Ns Op Cm elete
.Op Ar buffer
.Op Ar count
.Op Ar flags
.Xc
Delete the lines from the file.
.Pp
.It Xo
.Cm di Ns Op Cm splay
.Cm b Ns Oo Cm uffers Oc \&|
.Cm c Ns Oo Cm onnections Oc \&|
.Cm s Ns Oo Cm creens Oc \&|
.Cm t Ns Op Cm ags
.Xc
Display buffers, Cscope connections, screens or tags.
.Pp
.It Xo
.Op Cm Ee Ns
.Op Cm dit Ns
.Op Cm !\&
.Op Ar +cmd
.Op Ar file
.Xc
.It Xo
.Op Cm Ee Ns
.Cm x Ns Op Cm !\&
.Op Ar +cmd
.Op Ar file
.Xc
Edit a different file.
.Pp
.It Xo
.Cm exu Ns Op Cm sage
.Op Ar command
.Xc
Display usage for an
.Nm ex
command.
.Pp
.It Xo
.Cm f Ns Op Cm ile
.Op Ar file
.Xc
Display and optionally change the file name.
.Pp
.It Xo
.Op Cm Ff Ns
.Cm g
.Op Ar name
.Xc
.Nm vi
mode only.
Foreground the specified screen.
.Pp
.It Xo
.Op Ar range
.Cm g Ns Op Cm lobal
.No / Ns Ar pattern Ns /
.Op Ar commands
.Xc
.It Xo
.Op Ar range
.Cm v
.No / Ns Ar pattern Ns /
.Op Ar commands
.Xc
Apply commands to lines matching
.Pq Sq global
or not matching
.Pq Sq v
a pattern.
.Pp
.It Cm he Ns Op Cm lp
Display a help message.
.Pp
.It Xo
.Op Ar line
.Cm i Ns Op Cm nsert Ns
.Op Cm !\&
.Xc
The input text is inserted before the specified line.
.Pp
.It Xo
.Op Ar range
.Cm j Ns Op Cm oin Ns
.Op Cm !\&
.Op Ar count
.Op Ar flags
.Xc
Join lines of text together.
.Pp
.It Xo
.Op Ar range
.Cm l Ns Op Cm ist
.Op Ar count
.Op Ar flags
.Xc
Display the lines unambiguously.
.Pp
.It Xo
.Cm map Ns Op Cm !\&
.Op Ar lhs rhs
.Xc
Define or display maps (for
.Nm vi
only).
.Pp
.It Xo
.Op Ar line
.Cm ma Ns Op Cm rk
.Aq Ar character
.Xc
.It Xo
.Op Ar line
.Cm k Aq Ar character
.Xc
Mark the line with the mark
.Aq Ar character .
.Pp
.It Xo
.Op Ar range
.Cm m Ns Op Cm ove
.Ar line
.Xc
Move the specified lines after the target line.
.Pp
.It Xo
.Cm mk Ns Op Cm exrc Ns
.Op Cm !\&
.Ar file
.Xc
Write the abbreviations, editor options and maps to the specified
.Ar file .
.Pp
.It Xo
.Op Cm Nn Ns
.Op Cm ext Ns
.Op Cm !\&
.Op Ar file ...
.Xc
Edit the next file from the argument list.
.\" .Pp
.\" .It Xo
.\" .Op Ar line
.\" .Cm o Ns Op Cm pen
.\" .No / Ns Ar pattern Ns /
.\" .Op Ar flags
.\" .Xc
.\" Enter open mode.
.Pp
.It Cm pre Ns Op Cm serve
Save the file in a form that can later be recovered using the
.Nm ex
.Fl r
option.
.Pp
.It Xo
.Op Cm \&Pp Ns
.Cm rev Ns Op Cm ious Ns
.Op Cm !\&
.Xc
Edit the previous file from the argument list.
.Pp
.It Xo
.Op Ar range
.Cm p Ns Op Cm rint
.Op Ar count
.Op Ar flags
.Xc
Display the specified lines.
.Pp
.It Xo
.Op Ar line
.Cm pu Ns Op Cm t
.Op Ar buffer
.Xc
Append buffer contents to the current line.
.Pp
.It Xo
.Cm q Ns Op Cm uit Ns
.Op Cm !\&
.Xc
End the editing session.
.Pp
.It Xo
.Op Ar line
.Cm r Ns Op Cm ead Ns
.Op Cm !\&
.Op Ar file
.Xc
Read a file.
.Pp
.It Xo
.Cm rec Ns Op Cm over
.Ar file
.Xc
Recover
.Ar file
if it was previously saved.
.Pp
.It Xo
.Cm res Ns Op Cm ize
.Op Cm + Ns | Ns Cm - Ns
.Ar size
.Xc
.Nm vi
mode only.
Grow or shrink the current screen.
.Pp
.It Xo
.Cm rew Ns Op Cm ind Ns
.Op Cm !\&
.Xc
Rewind the argument list.
.Pp
.It Xo
.Cm se Ns Op Cm t
.Sm off
.Op option Oo = Oo value Oc Oc \ \&...
.Sm on
.Pf \ \& Op nooption ...
.Op option? ...
.Op Ar all
.Xc
Display or set editor options.
.Pp
.It Cm sh Ns Op Cm ell
Run a shell program.
.Pp
.It Xo
.Cm so Ns Op Cm urce
.Ar file
.Xc
Read and execute
.Nm ex
commands from a file.
.Pp
.It Xo
.Op Ar range
.Cm s Ns Op Cm ubstitute
.Sm off
.Op / Ar pattern No / Ar replace No /
.Sm on
.Pf \ \& Op Ar options
.Op Ar count
.Op Ar flags
.Xc
.It Xo
.Op Ar range
.Cm &
.Op Ar options
.Op Ar count
.Op Ar flags
.Xc
.It Xo
.Op Ar range
.Cm ~
.Op Ar options
.Op Ar count
.Op Ar flags
.Xc
Make substitutions.
.Pp
.It Xo
.Cm su Ns Op Cm spend Ns
.Op Cm !\&
.Xc
.It Xo
.Cm st Ns Op Cm op Ns
.Op Cm !\&
.Xc
.It Aq Cm suspend
Suspend the edit session.
The
.Aq suspend
character is usually
.Aq control-Z .
.Pp
.It Xo
.Op Cm Tt Ns
.Cm a Ns Op Cm g Ns
.Op Cm !\&
.Ar tagstring
.Xc
Edit the file containing the specified tag.
.Pp
.It Xo
.Op Cm Tt Ns
.Cm agn Ns Op Cm ext Ns
.Op Cm !\&
.Xc
Edit the file containing the next context for the current tag.
.Pp
.It Xo
.Cm tagp Ns Op Cm op Ns
.Op Cm !\&
.Op Ar file | number
.Xc
Pop to the specified tag in the tags stack.
.Pp
.It Xo
.Op Cm Tt Ns
.Cm agp Ns Op Cm rev Ns
.Op Cm !\&
.Xc
Edit the file containing the previous context for the current tag.
.Pp
.It Xo
.Cm tagt Ns Op Cm op Ns
.Op Cm !\&
.Xc
Pop to the least recent tag on the tags stack, clearing the stack.
.Pp
.It Xo
.Cm una Ns Op Cm bbreviate
.Ar lhs
.Xc
.Nm vi
only.
Delete an abbreviation.
.Pp
.It Cm u Ns Op Cm ndo
Undo the last change made to the file.
.Pp
.It Xo
.Cm unm Ns Op Cm ap Ns
.Op Cm !\&
.Ar lhs
.Xc
Unmap a mapped string.
.Pp
.It Cm ve Ns Op Cm rsion
Display the version of the
.Nm ex Ns / Ns Nm vi
editor.
.Pp
.It Xo
.Op Ar line
.Cm vi Ns Op Cm sual
.Op Ar type
.Op Ar count
.Op Ar flags
.Xc
.Nm ex
mode only.
Enter
.Nm vi .
.Pp
.It Xo
.Op Cm Vi Ns
.Cm i Ns Op Cm sual Ns
.Op Cm !\&
.Op Ar +cmd
.Op Ar file
.Xc
.Nm vi
mode only.
Edit a new file.
.Pp
.It Xo
.Cm viu Ns Op Cm sage
.Op Ar command
.Xc
Display usage for a
.Nm vi
command.
.Pp
.It Xo
.Op Ar range
.Cm w Ns Op Cm rite Ns
.Op Cm !\&
.Op >>
.Op Ar file
.Xc
.It Xo
.Op Ar range
.Cm w Ns Op Cm rite
.Op Cm !\&
.Op Ar file
.Xc
.It Xo
.Op Ar range
.Cm wn Ns Op Cm !\&
.Op >>
.Op Ar file
.Xc
.It Xo
.Op Ar range
.Cm wq Ns Op Cm !\&
.Op >>
.Op Ar file
.Xc
Write the file.
.Pp
.It Xo
.Op Ar range
.Cm x Ns Op Cm it Ns
.Op Cm !\&
.Op Ar file
.Xc
Exit the editor,
writing the file if it has been modified.
.Pp
.It Xo
.Op Ar range
.Cm ya Ns Op Cm nk
.Op Ar buffer
.Op Ar count
.Xc
Copy the specified lines to a buffer.
.Pp
.It Xo
.Op Ar line
.Cm z
.Op Ar type
.Op Ar count
.Op Ar flags
.Xc
Adjust the window.
.El
.Sh SET OPTIONS
There are a large number of options that may be set
.Pq 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.
.Bl -tag -width Ds
.It Cm altwerase Bq off
.Nm vi
only.
Select an alternate word erase algorithm.
.It Cm autoindent , ai Bq off
Automatically indent new lines.
.It Cm autoprint , ap Bq on
.Nm ex
only.
Display the current line automatically.
.It Cm autowrite , aw Bq off
Write modified files automatically when changing files.
.It Cm backup Bq \&"\&"
Back up files before they are overwritten.
.It Cm beautify , bf Bq off
Discard control characters.
.It Cm cdpath Bq "environment variable CDPATH, or current directory"
The directory paths used as path prefixes for the
.Cm cd
command.
.It Cm cedit Bq no default
Set the character to edit the colon command-line history.
.It Cm columns , co Bq 80
Set the number of columns in the screen.
.It Cm comment Bq off
.Nm vi
only.
Skip leading comments in shell, C and C++ language files.
.It Cm directory , dir Bq "environment variable TMPDIR, or /tmp"
The directory where temporary files are created.
.It Cm edcompatible , ed Bq off
Remember the values of the
.Sq c
and
.Sq g
suffixes to the
.Cm substitute
commands, instead of initializing them as unset for each new command.
.It Cm escapetime Bq 1
The 10th's of a second
.Nm ex Ns / Ns Nm vi
waits for a subsequent key to complete an
.Aq escape
key mapping.
.It Cm errorbells , eb Bq off
.Nm ex
only.
Announce error messages with a bell.
.It Cm exrc , ex Bq off
Read the startup files in the local directory.
.It Cm extended Bq off
Regular expressions are extended (i.e.\&
.Xr egrep 1
style) expressions.
.It Cm filec Bq no default
Set the character to perform file path completion on the colon command line.
.It Cm flash Bq on
Flash the screen instead of beeping the keyboard on error.
.It Cm hardtabs , ht Bq 0
Set the spacing between hardware tab settings.
This option currently has no effect.
.It Cm iclower Bq off
Makes all regular expressions case-insensitive,
as long as an upper-case letter does not appear in the search string.
.It Cm ignorecase , ic Bq off
Ignore case differences in regular expressions.
.It Cm keytime Bq 6
The 10th's of a second
.Nm ex Ns / Ns Nm vi
waits for a subsequent key to complete a key mapping.
.It Cm leftright Bq off
.Nm vi
only.
Do left-right scrolling.
.It Cm lines , li Bq 24
.Nm vi
only.
Set the number of lines in the screen.
.It Cm lisp Bq off
.Nm vi
only.
Modify various search commands and options to work with Lisp.
This option is not yet implemented.
.It Cm list Bq off
Display lines in an unambiguous fashion.
.It Cm lock Bq on
Attempt to get an exclusive lock on any file being edited, read or written.
.It Cm magic Bq on
Treat certain characters specially in regular expressions.
.It Cm matchtime Bq 7
.Nm vi
only.
The 10th's of a second
.Nm ex Ns / Ns Nm vi
pauses on the matching character when the
.Cm showmatch
option is set.
.It Cm mesg Bq on
Permit messages from other users.
.It Cm mesgcat Bq /usr/share/vi/catalog/
Selects a message catalog to be used to display error and informational
messages in a specified language.
.It Cm modelines , modeline Bq off
Read the first and last few lines of each file for
.Nm ex
commands.
This option will never be implemented.
.It Cm noprint Bq \&"\&"
Characters that are never handled as printable characters.
.It Cm number, nu Bq off
Precede each line displayed with its current line number.
.It Cm octal Bq off
Display unknown characters as octal numbers, instead of the default
hexadecimal.
.It Cm open Bq on
.Nm ex
only.
If this option is not set, the
.Cm open
and
.Cm visual
commands are disallowed.
.It Cm optimize , opt Bq on
.Nm vi
only.
Optimize text throughput to dumb terminals.
This option is not yet implemented
.It Cm paragraphs , para Bq "IPLPPPQPP LIpplpipbp"
.Nm vi
only.
Define additional paragraph boundaries for the
.Cm {\&
and
.Cm }\&
commands.
.It Cm path Bq \&"\&"
Define additional directories to search for files being edited.
.It Cm print Bq \&"\&"
Characters that are always handled as printable characters.
.It Cm prompt Bq on
.Nm ex
only.
Display a command prompt.
.It Cm readonly , ro Bq off
Mark the file and session as read-only.
.It Cm recdir Bq /var/tmp/vi.recover
The directory where recovery files are stored.
.It Cm redraw , re Bq off
.Nm vi
only.
Simulate an intelligent terminal on a dumb one.
This option is not yet implemented.
.It Cm remap Bq on
Remap keys until resolved.
.It Cm report Bq 5
Set the number of lines about which the editor reports changes or yanks.
.It Cm ruler Bq off
.Nm vi
only.
Display a row/column ruler on the colon command line.
.It Cm scroll , scr Bq "($LINES \- 1) / 2"
Set the number of lines scrolled.
.It Cm searchincr Bq off
Makes the
.Cm /
and
.Cm ?\&
commands incremental.
.It Cm sections , sect Bq "NHSHH HUnhsh"
.Nm vi
only.
Define additional section boundaries for the
.Cm [[
and
.Cm ]]
commands.
.It Cm secure Bq off
Turns off all access to external programs.
.It Cm shell , sh Bq "environment variable SHELL, or /bin/sh"
Select the shell used by the editor.
.It Cm shellmeta Bq ~{[*?$`'\&"\e
Set the meta characters checked to determine if file name expansion
is necessary.
.It Cm shiftwidth , sw Bq 8
Set the autoindent and shift command indentation width.
.It Cm showmatch , sm Bq off
.Nm vi
only.
Note matching
.Sq {
and
.Sq (
for
.Sq }
and
.Sq )\&
characters.
.It Cm showmode , smd Bq off
.Nm vi
only.
Display the current editor mode and a
.Dq modified
flag.
.It Cm sidescroll Bq 16
.Nm vi
only.
Set the amount a left-right scroll will shift.
.It Cm slowopen , slow Bq off
Delay display updating during text input.
This option is not yet implemented.
.It Cm sourceany Bq off
Read startup files not owned by the current user.
This option will never be implemented.
.It Cm tabstop , ts Bq 8
This option sets tab widths for the editor display.
.It Cm taglength , tl Bq 0
Set the number of significant characters in tag names.
.It Cm tags, tag Bq tags
Set the list of tags files.
.It Xo
.Cm term , ttytype , tty
.Bq "environment variable TERM"
.Xc
Set the terminal type.
.It Cm terse Bq off
This option has historically made editor messages less verbose.
It has no effect in this implementation.
.It Cm tildeop Bq off
Modify the
.Cm ~
command to take an associated motion.
.It Cm timeout , to Bq on
Time out on keys which may be mapped.
.It Cm ttywerase Bq off
.Nm vi
only.
Select an alternate erase algorithm.
.It Cm verbose Bq off
.Nm vi
only.
Display an error message for every error.
.It Cm w300 Bq no default
.Nm vi
only.
Set the window size if the baud rate is less than 1200 baud.
.It Cm w1200 Bq no default
.Nm vi
only.
Set the window size if the baud rate is equal to 1200 baud.
.It Cm w9600 Bq no default
.Nm vi
only.
Set the window size if the baud rate is greater than 1200 baud.
.It Cm warn Bq on
.Nm ex
only.
This option causes a warning message to be printed on the terminal
if the file has been modified since it was last written, before a
.Cm !\&
command.
.It Xo
.Cm window , w , wi
.Bq "environment variable LINES \- 1"
.Xc
Set the window size for the screen.
.It Cm windowname Bq off
Change the icon/window name to the current file name even if it can't
be restored on editor exit.
.It Cm wraplen , wl Bq 0
.Nm vi
only.
Break lines automatically,
the specified number of columns from the left-hand margin.
If both the
.Cm wraplen
and
.Cm wrapmargin
edit options are set, the
.Cm wrapmargin
value is used.
.It Cm wrapmargin , wm Bq 0
.Nm vi
only.
Break lines automatically,
the specified number of columns from the right-hand margin.
If both the
.Cm wraplen
and
.Cm wrapmargin
edit options are set, the
.Cm wrapmargin
value is used.
.It Cm wrapscan , ws Bq on
Set searches to wrap around the end or beginning of the file.
.It Cm writeany , wa Bq off
Turn off file-overwriting checks.
.El
.Sh ENVIRONMENT
.Bl -tag -width "COLUMNS"
.It Ev COLUMNS
The number of columns on the screen.
This value overrides any system or terminal specific values.
If the
.Ev COLUMNS
environment variable is not set when
.Nm ex Ns / Ns Nm vi
runs, or the
.Cm columns
option is explicitly reset by the user,
.Nm ex Ns / Ns Nm 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
.Cm cd
command.
.It Ev LINES
The number of rows on the screen.
This value overrides any system or terminal specific values.
If the
.Ev LINES
environment variable is not set when
.Nm ex Ns / Ns Nm vi
runs, or the
.Cm lines
option is explicitly reset by the user,
.Nm ex Ns / Ns Nm 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
.Cm shell
option).
.It Ev TERM
The user's terminal type.
The default is the type
.Dq unknown .
If the
.Ev TERM
environment variable is not set when
.Nm ex Ns / Ns Nm vi
runs, or the
.Cm term
option is explicitly reset by the user,
.Nm ex Ns / Ns Nm vi
enters the value into the environment.
.It Ev TMPDIR
The location used to stored temporary files (see also the
.Cm directory
edit option).
.El
.Sh ASYNCHRONOUS EVENTS
.Bl -tag -width "SIGWINCH" -compact
.It Dv SIGALRM
.Nm vi Ns / Ns Nm 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.
.Pp
.It Dv SIGHUP
.It Dv 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 Ns / Ns Nm ex
reference manual section
.Sx Recovery
for more information.
.Pp
.It Dv 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.
.Pp
.It Dv SIGWINCH
The screen is resized.
See the
.Nm vi Ns / Ns Nm ex
reference manual section
.Sx Sizing the Screen
for more information.
.\" .Pp
.\" .It Dv SIGCONT
.\" .It Dv SIGTSTP
.\" .Nm vi Ns / Ns Nm ex
.\" ignores these signals.
.El
.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
.Nm vi
startup file.
.It Pa /tmp
Temporary file directory.
.It Pa /var/tmp/vi.recover
The default recovery file directory.
.It Pa $HOME/.nexrc
First choice for user's home directory startup file.
.It Pa $HOME/.exrc
Second choice for user's home directory startup file.
.It Pa .nexrc
First choice for local directory startup file.
.It Pa .exrc
Second choice for local directory startup file.
.El
.Sh SEE ALSO
.Xr ctags 1 ,
.Xr egrep 1
.Pp
The
.Qq Vi Quick Reference
card,
.Pa /usr/share/doc/usd/12.vi/vi.summary .
.Pp
.Qq \&An Introduction to Display Editing with Vi ,
.Pa /usr/share/doc/usd/12.vi/ .
This document is the closest thing available to an introduction to the
.Nm vi
screen editor.
.Pp
.Qq \&Ex Reference Manual ,
.Pa /usr/share/doc/usd/13.ex/ .
This document is the final reference for the
.Nm ex
editor.
.Pp
.Qq Ex: A Tutorial ,
.Pa /usr/share/doc/usd/11.edit/ .
This document is the closest thing available to an introduction to the
.Nm ex
editor.
.Pp
.Qq Vi/Ex Reference Manual ,
.Pa /usr/share/doc/usd/13.viref/ .
This document is the final reference for the
.Nm nex Ns / Ns Nm nvi
text editors.
.Pp
Roff source for all of these documents is distributed with
.Nm nex Ns / Ns Nm nvi
in the
.Pa vi/docs/USD.doc
directory of the
.Nm nex Ns / Ns Nm nvi
source code.
.Pp
The files
.Pa autowrite ,
.Pa input ,
.Pa quoting ,
and
.Pa structures
found in the
.Pa vi/docs/internals
directory of the
.Nm nex Ns / Ns Nm nvi
source code.
.Sh STANDARDS
.Nm nex Ns / Ns Nm nvi
is close to
.St -p1003.2 .
That document differs from historical
.Nm ex Ns / Ns Nm vi
practice in several places; there are changes to be made on both sides.
.Sh HISTORY
The
.Nm nex Ns / Ns Nm nvi
replacements for the
.Nm ex Ns / Ns Nm vi
editor first appeared in
.Bx 4.4 .
.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.
|