~martanne/vis

ref: scintillua vis/man/vis.1 -rw-r--r-- 32.2 KiB
c3cfeaccMarc André Tanner lexers/typescript: add new upstream lexer revision 28e2b60 1 year, 1 month ago
                                                                                
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
.Dd January 14, 2017
.Dt VIS 1
.Os Vis VERSION
.
.Sh NAME
.
.Nm vis
.Nd a highly efficient text editor
.
.Sh SYNOPSIS
.
.Nm
.Op Fl v
.Op Cm + Ns Ar command
.Op Fl -
.Op Ar files ...
.
.Sh DESCRIPTION
.
.Nm
is a highly efficient screen-oriented text editor combining the strengths of
both
.Nm vi(m)
and
.Nm sam .
.
This manual page is intended for users already familiar with
.Nm vi Ns / Ns Nm sam .
Anyone else should almost certainly read a good tutorial on either editor
before this manual page.
The following options are available:
.Bl -tag -width indent
.It Fl v
Print version information and exit.
.It Cm + Ns Ar command
Execute
.Ar command
after loading file.
.
.It Fl -
Denotes the end of the options.
Arguments after this will be handled as a
file name.
.El
.Pp
The special file
.Cm -
instructs
.Nm
to read from standard input in which case
.Ic :wq
will write to standard output, thereby enabling usage as an interactive filter.
.Pp
If standard input is redirected and all input is consumed,
.Nm
will open
.Pa /dev/tty
to gather further commands.
Failure to do so results in program termination.
.
.Ss Selections
.
.Nm
uses selections as core editing primitives.
A selection is a non-empty, directed range with two endpoints called
.Em cursor
and
.Em anchor .
A selection can be anchored in which case the anchor remains fixed while
only the position of the cursor is adjusted.
For non-anchored selections both endpoints are updated.
A singleton selection covers one character on which both cursor and
anchor reside.
There always exists a primary selection which remains visible
(i.e. changes to its position will adjust the viewport).
.
.Ss Modes
.
.Nm
employs the same
.Em modal
editing approach as
.Nm vi .
It supports a
.Sq normal ,
.Sq operator pending ,
.Sq insert ,
.Sq replace
and
.Sq visual
(in both line and character wise variants) mode.
The visual block and ex modes are deliberately not implemented,
instead
.Nm
has built in support for multiple selections and an
.Em interactive
variant of the structural regular expression based command language of
.Nm sam .
.Pp
In normal mode all selections are non-anchored and reduced to a single character.
.
.Ss Undo/Redo
.
.Nm
uses an undo tree to keep track of text revisions.
The
.Ic u
.Pq undo
and
.Aq Ic C-r
.Pq redo
commands can be used to traverse the tree along the main branch.
.Ic g+
and
.Ic g-
traverse the history in chronological order.
The
.Ic :earlier
and
.Ic :later
commands provide means to restore the text to an arbitrary state.
.
.Ss Marks
.
A mark associates a symbolic name to a set of selections.
A stored selection becomes invalid when its delimiting boundaries change
in the underlying buffer.
If said changes are later undone the mark becomes valid again.
.Ic m
sets a mark,
.Ic M
restores it.
For example,
.Ic ' Ns Ar a Ns Ic m
sets the mark
.Ar a
while
.Ic ' Ns Ar a Ns Ic M
restores it.
.Pp
Available marks are:
.Bl -tag -width indent
.It Ic ''
default mark
.It Ic '^
active selections when leaving visual mode
.It Ic 'a Ns \(en Ns Ic 'z
general purpose marks
.El
.Pp
No marks across files are supported.
Marks are not preserved over editing sessions.
.
.Ss Jump list
.
A per window, fixed sized file local jump list exists which stores marks
(i.e. set of selections).
.Bl -tag -width indent
.It Ic g<
jump backward
.It Ic g>
jump forward
.It Ic gs
save currently active selections
.El
.
.Ss Registers
.
Registers are named lists of text.
Uninitialized register slots default to the empty string.
Available registers are:
.Bl -tag -width indent
.It Ic \(dq\(dq
default register
.It Ic \(dqa Ns \(en Ns Ic \(dqz
general purpose registers
.It Ic \(dqA Ns \(en Ns Ic \(dqZ
append to corresponding general purpose register
.It Ic \(dq* , Ic \(dq+
system clipboard integration via shell script
.Xr vis-clipboard 1
.It Ic \(dq0
yank register, most recently yanked range
.It Ic \(dq1 Ns \(en Ns Ic \(dq9
.It Ic \(dq&
sub expression matches of most recent
.Ic x
or
.Ic y
command
.It Ic \(dq/
search register, most recently used search pattern
.It Ic \(dq\&:
command register, most recently executed command
.It Ic \(dq_
black hole
.Pq Pa /dev/null
register, ignore content is always empty
.It Ic \(dq#
selection number (readonly)
.El
.Pp
If no explicit register is specified the default register is used.
.
.Ss Macros
.
The general purpose registers
.Ic \(dqa Ns \(en Ns Ic \(dqz
can be used to record macros.
Use one of
.Ic \(dqA Ns \(en Ns Ic \(dqZ
to append to an existing macro.
.Ic q
starts a recording,
.Ic @
plays it back.
.Ic @@
refers to the most recently recorded macro.
.Ic @:
repeats the last
.Ic \&: Ns -command.
.Ic @/
is equivalent to
.Ic n
in normal mode.
.
These operations always use the first register slot.
.
.Ss Encoding, Tab and Newline handling
.
.Nm
always assumes the input file to be UTF-8 encoded with
.Li \[rs]n
line endings.
If you wish to edit files with legacy encodings or non-Unix line endings,
use
.Xr iconv 1
and
.Xr dos2unix 1
to convert them as needed.
.Aq Ic Tab
can optionally be expanded to a configurable number of spaces (see
.Sx "SET OPTIONS" ) .
.
.Ss Mouse support
.
The mouse is currently not used at all.
.
.Sh SAM COMMANDS
.
.Nm
supports an interactive variant of the structural regular expression based
command language introduced by
.Xr sam 1 .
.
.Ss Regular expressions
.
.Nm
currently defers regular expression matching to the underlying C library.
It uses what POSIX refers to as
.Dq Extended Regular Expressions
as described in
.Xr regex 7 .
The anchors
.Ic ^
and
.Ic $
match the beginning / end of the range they are applied to.
Additionally
.Li \[rs]n
and
.Li \[rs]t
may be used to refer to newlines and tabs,
respectively.
The
.Ic \&.
atom matches any character except newline.
The empty regular expression stands for the last complete expression
encountered.
.
.Ss Addresses
.
An address identifies a substring (or range) in a file.
In the following
.Do
character
.Ar n
.Dc
means the null string after the
.Ar n Ns -th
character in the file, with 1 the first character in the file.
.Do
Line
.Ar n
.Dc
means the
.Ar n Ns -th
match, starting at the beginning of the file, of the regular expression
.Dq Li .*\[rs]n\&? .
.Pp
All windows always have at least one current substring which is the default
address.
In sam this is referred to as
.Sy dot .
In
.Nm
multiple
.Dq dots
(or selections) can exist at the same time.
.
.Ss Simple addresses
.
.Bl -tag -width indent
.It Ic # Ns Ar n
The empty string after character
.Ar n ;
.Ic #0
is the beginning of the file.
.It Ar n
Line
.Ar n .
.It Ic / Ns Ar regexp Ns Ic /
.It Ic \&? Ns Ar regexp Ns Ic \&?
The substring that matches the regular expression, found by looking
towards the end
.Pq Ic /
or beginning
.Pq Ic \&?
of the file.
The search does not wrap around when hitting the end
.Pq start
of the file.
.It Ic 0
The string before the first full line.
This is not necessarily the null string; see
.Ic +
and
.Ic -
below.
.It Ic $
The null string at the end of the file.
.It Ic \&.
Dot, the current range.
.It Ic ' Ns Ar m
The mark
.Ar m
in the file.
.El
.
.Ss Compound addresses
.
In the following,
.Ar a1
and
.Ar a2
are addresses.
.Bl -tag -width indent
.It Ar a1 Ns Ic + Ns Ar a2
The address
.Ar a2
evaluated starting at the end of
.Ar a1 .
.It Ar a1 Ns Ic - Ns Ar a2
The address
.Ar a2
evaluated looking the reverse direction starting at the beginning of
.Ar a1 .
.It Ar a1 Ns Ic \&, Ns Ar a2
The substring from the beginning of
.Ar a1
to the end of
.Ar a2 .
If
.Ar a1
is missing,
.Ic 0
is substituted.
If
.Ar a2
is missing,
.Ic $
is substituted.
.It Ar a1 Ns Ic \&; Ns Ar a2
Like
.Ar a1 Ns Ic \&, Ns Ar a2
but with
.Ar a2
evaluated at the end of, and range set to,
.Ar a1 .
.El
.Pp
The operators
.Ic +
and
.Ic -
are high precedence, while
.Ic \&,
and
.Ic \&;
are low precedence.
.Pp
In both
.Ic +
and
.Ic -
forms, if
.Ar a2
is a line or character address with a missing number, the number defaults to 1.
If
.Ar a1
is missing,
.Ic \&.
is substituted.
If both
.Ar a1
and
.Ar a2
are present and distinguishable,
.Ic +
may be elided.
.Ar a2
may be a regular expression; if it is delimited by
.Li \&?
characters, the effect of the
.Ic +
or
.Ic -
is reversed.
.
The
.Ic %
sign is an alias for
.Ic \&,
and hence
.Ic 0,$ .
.
It is an error for a compound address to represent a malformed substring.
.
.Ss Commands
.
In the following, text demarcated by slashes represents text delimited
by any printable ASCII character except alphanumerics.
Any number of trailing delimiters may be elided, with multiple elisions then
representing null strings, but the first delimiter must always be present.
In any delimited text, newline may not appear literally;
.Li \[rs]n
and
.Li \[rs]t
may be typed for newline and tab;
.Li \[rs]/
quotes the delimiter, here
.Li / .
An ampersand
.Li &
and
.Li \[rs] Ns Ar n ,
where
.Ar n
is a digit (1\(en9) are replaced by the corresponding register.
Backslash is otherwise interpreted literally.
.Pp
Most commands may be prefixed with an address to indicate their range of
operation.
If a command takes an address and none is supplied, a default address is used.
In normal mode this equates to the character the selection is currently over.
If only one selection exists
.Ic x
and
.Ic y
default to the whole file
.Ic 0,$ .
In normal mode the write commands
.Ic w
and
.Ic wq
always apply to the whole file.
Commands are executed once for every selection.
In visual mode the commands are applied to every selection
as if an implicit
.Ic x
command, matching the existing selections, was present.
.
.Pp
In the description,
.Dq range
is used to represent whatever address is supplied.
.Pp
Many commands create new selections as a side effect when issued from a visual
mode.
If so, it is always to the “result” of the change: the new text for an
insertion, the empty string for a deletion, the command output of a filter etc.
If after a successful command execution no selections remain,
the editor will switch to normal mode, otherwise it remains in
visual mode.
This allows
.Em interactive
refinements of ranges.
.
.\" Many commands set the value of dot as a side effect.
.\" If so, it is always to the
.\" .Dq result
.\" of the change: the empty string for a deletion, the new text for an
.\" insertion, etc.
.\" .Po
.\" but see the
.\" .Sy s
.\" and
.\" .Sy e
.\" commands
.\" .Pc .
.
.Ss Text commands
.
.Bl -tag -width indent
.It Ic a Ns [ Ar count ] Ns / Ns Ar text Ns Ic /
Insert the
.Ar text
.Ar count
times into the file after the range.
.\" Set dot.
.Pp
May also be written as
.Bd -literal -offset indent
 a
 lines
 of
 text
 .
.Ed
.
.It Ic c No or Ic i
Same as
.Ic a ,
but
.Ic c
replaces the text, while
.Ic i
inserts
.Em before
the range.
.
.It Ic d
Delete the text in range.
.\" Set dot.
.El
.
.Ss Display commands
.
.Bl -tag -width Ds
.It Ic p
Create a new selection for the range.
.El
.
.Ss I/O commands
.
.Bl -tag -width indent
.It Ic e Ns Oo Cm \&! Oc Op Pa file name
Replace the file by the contents of the named external file.
If no file name is given, reload file from disk.
.
.It Ic r Ar file name
Replace the text in the range by the contents of the named external file.
.\" Set dot.
.
.It Ic w Ns Oo Cm \&! Oc Op Ar file name
Write the range
.Po
default
.Ic 0,$
.Pc
to the named external file.
.
.It Ic wq Ns Oo Cm \&! Oc Op Ar file name
Same as
.Ic w ,
but close file afterwards.
.El
.Pp
If the file name argument is absent from any of these, the current file name is
used.
.
.Ic e
always sets the file name,
.Ic w
will do so if the file has no name.
Forcing the
.Ic e
command with
.Cm \&!
will discard any unsaved changes.
Forcing
.Ic w
will overwrite the file on disk even if it has been externally modified
since loading it.
Write commands with a non-default addresses and no file name are destructive
and need always to be forced.
.Bl -tag -width indent
.
.It Ic < Ar shell command
Replace the range by the standard output of the shell command.
.
.It Ic > Ar shell command
Sends the range to the standard input of the shell command.
.
.It Ic \&| Ar shell command
Send the range to the standard input, and replace it by the standard output, of
the shell command.
.
.It Ic \&! Ar shell command
Run interactive shell command, redirect keyboard input to it.
.
.It Ic cd Ar directory
Change working directory.
If no directory is specified,
.Ev "$HOME"
is used.
.El
.Pp
In any of
.Ic < ,
.Ic > ,
.Ic \&| ,
or
.Ic \&! ,
if the shell command is omitted, the last shell command
.Pq of any type
is substituted.
Unless the file being edited is unnamed, all these external commands
can refer to its absolute path and file name through the
.Ev vis_filepath
and
.Ev vis_filename
environment variables.
.
.Ss Loops and conditionals
.
.Bl -tag -width indent
.It Ic x/ Ns Ar regexp Ns Ic / Op Ar command
For each match of the regular expression in the range, run the command with
range set to the match.
If the regular expression and its slashes are omitted,
.Ar "/.*\[rs]n/"
is assumed.
Null string matches potentially occur before every character of the range and
at the end of the range.
.Pp
The
.Ic \(dq1 Ns \(en Ns Ic \(dq9
and
.Ic \(dq&
registers are updated with the (sub) expression matches of the pattern.
.
.It Ic y/ Ns Ar regexp Ns Ic / Op Ar command
Like
.Ic x ,
but run the command for each substring that lies before, between, or after the
matches that would be generated by
.Ic x .
There is no default behavior.
Null substrings potentially occur before every character in the range.
.
.It Ic X/ Ns Ar regexp Ns Ic "/" Ar command
For each file whose file name matches the regular expression, make that the
current file and run the command.
If the expression is omitted, the command is run in every file.
.
.It Ic Y/ Ns Ar regexp Ns Ic / Ar command
Same as
.Ic X ,
but for files that do not match the regular expression, and the expression is
required.
.\" TODO improve markup, use Op macro, make it actually understandable :/
.It Ic g Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
.It Ic v Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
If the
.Ar count
range contains
.Po
.Ic g
.Pc
or does not contain
.Po
.Ic v
.Pc
a match for the expression, run command on the range.
.Pp
The
.Ar count
specifier has the following format, where
.Ar n
and
.Ar m
are integers denoting the ranges.
.Bl -tag -width indent
.It Ar n Ns Ic \&, Ns Ar m
The closed interval from
.Ar n
to
.Ar m .
If
.Ar n
is missing,
.Ic 1
is substituted.
If
.Ar m
is missing,
.Ic 
is substituted.
Negative values are interpreted relative to the last range.
.It Ic % Ns Ar n
Matches every
.Ar n Ns -th
range.
.El
.
.El
.Pp
These may be nested arbitrarily deeply.
An empty command in an
.Ic x
or
.Ic y
defaults to
.Ic p .
.Ic X ,
.Ic Y ,
.Ic g
and
.Ic v
do not have defaults.
.
.Ss Grouping and multiple changes
.
Commands may be grouped by enclosing them in curly braces.
Semantically, the opening brace is like a command: it takes an
.Pq optional
address and runs each sub-command on the range.
Commands within the braces are executed sequentially, but changes
made by one command are not visible to other commands.
.Pp
When a command makes a number of changes to a file, as in
.Ic x/ Ns Ar re Ns Ic / Ic c/ Ns Ar text Ns Ic / ,
the addresses of all changes are computed based on the initial state.
If the changes are non-overlapping, they are applied in the specified
order.
Conflicting changes are rejected.
.Pp
Braces may be nested arbitrarily.
.
.Sh VI(M) KEY BINDINGS
.
In the following sections angle brackets are used to denote special keys.
The prefixes
.Ic C- ,
.Ic S- ,
and
.Ic M-
are used to refer to the
.Aq Ctrl ,
.Aq Shift
and
.Aq Alt
modifiers, respectively.
.Pp
All active key bindings can be listed at runtime using the
.Ic :help
command.
.
.Ss Operators
.
Operators perform a certain operation on a text range indicated by either a
motion, a text object or an existing selection.
.Pp
When used in normal mode, the following operators wait for a motion, putting
vis into operator pending mode.
.Bl -tag -width XXXXXXXXXX -compact
.It Ic c
change, delete range and enter insert mode
.
.It Ic d
delete, cut range to register
.
.It Ic <
shift-left, decrease indent
.
.It Ic >
shift-right, increase indent
.
.It Ic y
yank, copy range to register
.El
.Pp
When used in normal mode, the following actions take effect immediately.
.Bl -tag -width XXXXXXXXXX -compact
.It Ic =
format, filter range through
.Xr fmt 1
.
.It Ic gu
make lowercase
.
.It Ic gU
make uppercase
.
.It Ic g~
swap case
.
.It Ic J
join lines, insert spaces in between
.
.It Ic gJ
join lines remove any delimiting white spaces
.
.It Ic p
put register content after cursor
.
.It Ic P
put register content before cursor
.
.El
.
.Ss Motions
.
.\" TODO? more formal definition: pos -> [min(pos, f(pos)), max(pos, f(pos))]
Motions take an initial file position and transform it to a destination file
position,
thereby defining a range.
.\" TODO define word/WORD
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.It Ic 0
start of line
.
.It Ic b
previous start of a word
.
.It Ic B
previous start of a WORD
.
.It Ic $
end of line
.
.It Ic e
next end of a word
.
.It Ic E
next end of a WORD
.
.It Ic F Ns Aq Ar char
to next occurrence of
.Aq Ar char
to the left
.
.It Ic f Ns Aq Ar char
to next occurrence of
.Aq Ar char
to the right
.
.It Ic ^
first non-blank of line
.
.It Ic g0
begin of display line
.
.It Ic g$
end of display line
.
.It Ic ge
previous end of a word
.
.It Ic gE
previous end of a WORD
.
.It Ic gg
begin of file
.
.It Ic G
goto line or end of file
.
.It Ic gj
display line down
.
.It Ic gk
display line up
.
.It Ic gh
codepoint left
.
.It Ic gl
codepoint right
.
.It Ic gH
byte left
.
.It Ic gL
byte right
.It Ic g_
last non-blank of line
.
.It Ic gm
middle of display line
.
.It Ic g\&|
goto column
.
.It Ic h
char left
.
.It Ic H
goto top/home line of window
.
.It Ic j
line down
.
.It Ic k
line up
.
.It Ic l
char right
.
.It Ic L
goto bottom/last line of window
.
.It Ic %
match bracket, quote or backtick
.
.It Ic }
next paragraph
.
.It Ic \&)
next sentence
.
.It Ic N
repeat last search backwards
.
.It Ic n
repeat last search forward
.
.It Ic [{
previous start of block
.
.It Ic ]}
next start of block
.
.It Ic [(
previous start of parentheses pair
.
.It Ic ])
next start of parentheses pair
.
.It Ic {
previous paragraph
.
.It Ic \&(
previous sentence
.
.It Ic \&;
repeat last to/till movement
.
.It Ic \&,
repeat last to/till movement but in opposite direction
.
.It Ic #
search word under selection backwards
.
.It Ic *
search word under selection forwards
.
.It Ic T Ns Aq Ar char
till before next occurrence of
.Aq Ar char
to the left
.
.It Ic t Ns Aq Ar char
till before next occurrence of
.Aq Ar char
to the right
.
.It Ic \&? Ns Ar pattern
to next match of
.Ar pattern
in backward direction
.
.It Ic / Ns Ar pattern
to next match of
.Ar pattern
in forward direction
.
.It Ic w
next start of a word
.
.It Ic W
next start of a WORD
.El
.
.Ss Text objects
.
.\" TODO? more formal definition: text-object: pos -> [a, b]
Text objects take an initial file position and transform it to a range
where the former does not necessarily have to be contained in the latter.
.
All of the following text objects are implemented in an inner variant
(prefixed with
.Ic i )
where the surrounding white space or delimiting characters are not part
of the resulting range and a normal variant (prefixed with
.Ic a )
where they are.
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.
.It Ic w
word
.
.It Ic W
WORD
.
.It Ic s
sentence
.
.It Ic p
paragraph
.
.It Ic [, ], (, ), {, }, <, >, \(dq, ', `
block enclosed by these symbols
.El
.Pp
Further available text objects include:
.Bl -tag -width XXXXXXXXXX -compact
.
.It Ic gn
matches the last used search term in forward direction
.
.It Ic gN
matches the last used search term in backward direction
.
.It Ic al
current line
.
.It Ic il
current line without leading and trailing white spaces
.El
.
.Ss Multiple Selections
.
.Nm
supports multiple selections with immediate visual feedback.
There always exists one primary selection located within the current
view port.
Additional selections can be created as needed.
If more than one selection exists, the primary one is styled differently.
.Pp
To manipulate selections use in normal mode:
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.It Aq Ic C-k
create count new selections on the lines above
.
.It Aq Ic C-M-k
create count new selections on the lines above the first selection
.
.It Aq Ic C-j
create count new selections on the lines below
.
.It Aq Ic C-M-j
create count new selections on the lines below the last selection
.
.It Aq Ic C-p
remove primary selection
.
.It Aq Ic C-n
select word the selection is currently over, switch to visual mode
.
.It Aq Ic C-u
make the count previous selection primary
.
.It Aq Ic C-d
make the count next selection primary
.
.It Aq Ic C-c
remove the count selection column
.
.It Aq Ic C-l
remove all but the count selection column
.
.It Aq Ic Tab
try to align all selections on the same column
.
.It Aq Ic Escape
dispose all but the primary selection
.El
.Pp
The visual modes were enhanced to recognize:
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.It Ic I
create a selection at the start of every selected line
.
.It Ic A
create a selection at the end of every selected line
.
.It Aq Ic Tab
left align selections by inserting spaces
.
.It Aq Ic S-Tab
right align selections by inserting spaces
.
.It Aq Ic C-a
create new selections everywhere matching current word or selection
.
.It Aq Ic C-n
create new selection and select next word matching current selection
.
.It Aq Ic C-x
clear (skip) current selection, but select next matching word
.
.It Aq Ic C-p
remove primary selection
.
.It Aq Ic C-u
.It Aq Ic C-k
make the count previous selection primary
.
.It Aq Ic C-d
.It Aq Ic C-j
make the count next selection primary
.
.It Aq Ic C-c
remove the count selection column
.
.It Aq Ic C-l
remove all but the count selection column
.
.It Ic +
rotate selections rightwards count times
.
.It Ic -
rotate selections leftwards count times
.
.It Ic _
trim selections, remove leading and trailing white space
.
.It Ic o
flip selection direction, swap cursor and anchor
.
.It Aq Ic Escape
clear all selections, switch to normal mode
.El
.Pp
In insert and replace mode:
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.It Aq Ic S-Tab
align all selections by inserting spaces
.El
.Pp
Selections can be manipulated using set operations.
The first operand is the currently active selections while the second
can be specified as a mark.
.Pp
.Bl -tag -width XXXXXXXXXX -compact
.It Ic \&|
set union
.It Ic &
set intersection
.It Ic \e
set minus
.It Ic ~
set complement
.El
.
.Sh VI(M) COMMANDS
.
Any unique prefix can be used to abbreviate a command.
.
.Ss File and Window management
.
A file must be opened in at least one window.
If the last window displaying a certain file is closed all unsaved changes are
discarded.
Windows are equally sized and can be displayed in either horizontal or vertical
fashion.
The
.Aq Ic C-w
.Ic h ,
.Aq Ic C-w
.Ic j ,
.Aq Ic C-w
.Ic k
and
.Aq Ic C-w
.Ic l
key mappings can be used to switch between windows.
.Bl -tag -width indent
.It Ic :new
open an empty window, arrange horizontally
.
.It Ic :vnew
open an empty window, arrange vertically
.
.It Ic :open Ns Oo Cm \&! Oc Op Ar file name
open a new window, displaying file name if given
.
.It Ic :split Op Ar file name
split window horizontally
.
.It Ic :vsplit Op Ar file name
split window vertically
.
.It Ic :q Ns Oo Cm \&! Oc Op Ar exit code
close currently focused window
.
.It Ic :qall Ns Oo Cm \&! Oc Op Ar exit code
close all windows, terminate editor with exit code (defaults to 0)
.El
.Pp
Commands taking a file name will invoke the
.Xr vis-open 1
utility, if given a file pattern or directory.
.
.Ss Runtime key mappings
.
.Nm
supports global as well as window local run time key mappings which are
always evaluated recursively.
.
.Bl -tag -width indent
.It Ic :map Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
add a global key mapping
.
.It Ic :map-window Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
add a window local key mapping
.
.It Ic :unmap Ar mode Ar lhs
remove a global key mapping
.
.It Ic :unmap-window Ar mode Ar lhs
remove a window local key mapping
.El
.Pp
In the above
.Ar mode
refers to one of
.Ql normal ,
.Ql insert ,
.Ql replace ,
.Ql visual ,
.Ql visual-line
or
.Ql operator-pending ;
.Ar lhs
refers to the key to map and
.Ar rhs
is a key action or alias.
An existing mapping may be overridden by forcing the map command by specifying
.Cm \&! .
.Pp
Because key mappings are always recursive, doing something like:
.Pp
.Dl :map! normal j 2j
.Pp
will not work because it would enter an endless loop.
Instead,
.Nm
uses pseudo keys referred to as key actions which can be used to invoke
a set of available editor functions.
.Ic :help
lists all currently active key bindings as well as all available symbolic
keys.
.
.Ss Keyboard Layout Specific Mappings
.
In order to facilitate usage of non-latin keyboard layouts,
.Nm
allows one to map locale specific keys to their latin equivalents by means of the
.Pp
.D1 Ic :langmap Ar locale-keys Ar latin-keys
.Pp
command.
As an example, the following maps the movement keys in Russian layout:
.Pp
.Dl :langmap ролд hjkl
.Pp
If the key sequences have not the same length, the remainder of the longer
sequence will be discarded.
.Pp
The defined mappings take effect
in all non-input modes, i.e. everywhere except in insert and replace mode.
.
.Ss Undo/Redo
.
.Bl -tag -width indent
.It Ic :earlier Op Ar count
revert to older text state
.It Ic :later Op Ar count
revert to newer text state
.El
.Pp
If count is suffixed by either of
.Sy d
.Pq days ,
.Sy h
.Pq hours ,
.Sy m
.Pq minutes
or
.Sy s
.Pq seconds
it is interpreted as an offset from the current system time and the closest
available text state is restored.
.
.Sh SET OPTIONS
.
There are a small number of options that may be set
.Pq or unset
to change the editor's behavior using the
.Ic :set
command.
This section describes the options, their abbreviations and their
default values.
Boolean options can be toggled by appending
.Sy \&!
to the option name.
.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.
.Bl -tag -width indent
.It Ic shell Op Dq Pa /bin/sh
User shell to use for external commands, overrides
.Ev SHELL
and shell field of password database
.Pa /etc/passwd
.
.It Ic escdelay Op Ar 50
Milliseconds to wait before deciding whether an escape sequence should
be treated as an
.Aq Cm Escape
key.
.
.It Ic tabwidth , Ic tw Op Ar 8
Display width of a tab and number of spaces to use if
.Ic expandtab
is enabled.
.
.It Ic autoindent , Cm ai Op Cm off
Automatically indent new lines by copying white space from previous line.
.
.It Ic expandtab , Ic et Op Cm off
Whether
.Aq Ic Tab
should be expanded to
.Ic tabwidth
spaces.
.
.It Ic number , Ic nu Op Cm off
Display absolute line numbers.
.
.It Ic relativenumbers , Ic rnu Op Cm off
Display relative line numbers.
.
.It Ic cursorline , Ic cul Op Cm off
Highlight line primary cursor resides on.
.
.It Ic colorcolumn , Ic cc Op Ar 0
Highlight a fixed column.
.
.It Ic horizon Op Ar 32768
How many bytes back the lexer will look to synchronize parsing.
.
.It Ic redrawtime Op Ar 1.0
Maximum time (in seconds) to wait for syntax highlighting before aborting it.
.
.It Ic theme Op Do default-16 Dc or Do default-256 Dc
Color theme to use, name without file extension.
Loaded from a
.Pa themes/
sub directory of the paths listed in the
.Sx FILES
section.
.
.It Cm syntax Op Cm off
Syntax highlighting lexer to use, name without file extension.
.
.It Cm show-tabs Op Cm off
Whether to display replacement symbol instead of tabs.
.
.It Cm show-newlines Op Cm off
Whether to display replacement symbol instead of newlines.
.
.It Cm show-spaces Op Cm off
Whether to display replacement symbol instead of blank cells.
.
.It Cm show-eof Op Cm on
Whether to display replacement symbol for lines after the end of the file.
.
.It Cm savemethod Op Ar auto
How the current file should be saved,
.Ar atomic
which uses
.Xr rename 2
to atomically replace the file,
.Ar inplace
which truncates the file and then rewrites it or
.Ar auto
which tries the former before falling back to the latter.
The rename method fails for symlinks, hardlinks, in case of insufficient
directory permissions or when either the file owner, group, POSIX ACL or
SELinux labels can not be restored.
.It Cm loadmethod Op Ar auto
How existing files should be loaded,
.Ar read
which copies the file content to an independent in-memory buffer,
.Ar mmap
which memory maps the file from disk and uses OS capabilities as
caching layer or
.Ar auto
which tries the former for files smaller than 8Mb and the latter for
lager ones.
WARNING: modifying a memory mapped file in-place will cause data loss.
.It Ic layout Op Do v Dc or Do h Dc
Whether to use vertical or horizontal layout.
.It Cm ignorecase , Cm ic Op Cm off
Whether to ignore case when searching.
.El
.
.Sh COMMAND and SEARCH PROMPT
.
The command and search prompt as opened by
.Ic \&: ,
.Ic / ,
or
.Ic \&?
is implemented as a single line height window, displaying a regular file
whose editing starts in insert mode.
.Aq Ic Escape
switches to normal mode, a second
.Aq Ic Escape
cancels the prompt.
.Aq Ic Up
enlarges the window, giving access to the command history.
.Aq Ic C-v
.Aq Ic Enter
inserts a literal new line thus enabling multiline commands.
.Aq Ic Enter
executes the visual selection if present, or else everything in the
region spawned by the selection position and the delimiting prompt symbols
at the start of adjacent lines.
.
.Sh CONFIGURATION
.
.Nm
uses Lua for configuration and scripting purposes.
During startup
.Pa visrc.lua
(see the
.Sx FILES
section) is sourced which can be used to set personal configuration options.
As an example the following will enable the display of line numbers:
.Pp
.Dl vis:command('set number')
.
.Sh ENVIRONMENT
.
.Bl -tag -width indent
.It Ev VIS_PATH
The default path to use to load Lua support files.
.It Ev HOME
The home directory used for the
.Ic cd
command if no argument is given.
.It Ev TERM
The terminal type to use to initialize the curses interface, defaults to
.Sy xterm
if unset.
.It Ev SHELL
The command shell to use for I/O related commands like
.Ic \&! ,
.Ic > ,
.Ic <
and
.Ic \&| .
.It Ev XDG_CONFIG_HOME
The configuration directory to use, defaults to
.Pa $HOME/.config
if unset.
.El
.
.Sh ASYNCHRONOUS EVENTS
.
.Bl -tag -width indent
.It Dv SIGSTOP
Suspend editor.
.It Dv SIGCONT
Resume editor.
.It Dv SIGBUS
An
.Xr mmap 2
ed file got truncated, unsaved file contents will be lost.
.It Dv SIGHUP
.It Dv SIGTERM
Restore initial terminal state.
Unsaved file contents will be lost.
.It Dv SIGINT
When an interrupt occurs while an external command is being run it is terminated.
.It Dv SIGWINCH
The screen is resized.
.El
.
.Sh FILES
.
Upon startup
.Nm
will source the first
.Pa visrc.lua
configuration file found from these locations.
All actively used paths can be listed at runtime using the
.Cm :help
command.
.Bl -bullet
.It
.Pa $VIS_PATH
.It
The location of the
.Nm
binary (on systems where
.Pa /proc/self/exe
is available).
.It
.Pa $XDG_CONFIG_HOME/vis
where
.Ev XDG_CONFIG_HOME
refers to
.Pa $HOME/.config
if unset.
.
.It
.Pa /etc/vis
for a system-wide configuration provided by administrator.
.It
.Pa /usr/local/share/vis
or
.Pa /usr/share/vis
depending on the build configuration.
.
.Pp
When creating a new
.Pa visrc.lua
be sure to copy the structure from here.
.El
.
.Sh EXIT STATUS
.
.Ex -std
.
.Sh EXAMPLES
.
Use
.Nm
as an interactive filter.
.Pp
.Dl $ { echo Pick your number; seq 1 10; } | vis - > choice
.Pp
Use the
.Xr vis-open 1
based file browser to list all C language source files:
.Pp
.Dl :e *.c
.Pp
Spawn background process and pipe range to its standard input:
.Pp
.Dl :> { plumber <&3 3<&- & } 3<&0 1>&- 2>&-
.
.Sh SEE ALSO
.
.Xr sam 1 ,
.Xr vi 1 ,
.Xr vis-clipboard 1 ,
.Xr vis-complete 1 ,
.Xr vis-digraph 1 ,
.Xr vis-menu 1 ,
.Xr vis-open 1
.Pp
.Lk http://doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pdf "A Tutorial for the Sam Command Language"
by
.An Rob Pike
.Pp
.Lk http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ "The Text Editor sam"
by
.An Rob Pike
.Pp
.Lk http://man.cat-v.org/plan_9/1/sam "Plan 9 manual page for sam(1)"
.Pp
.Lk http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf "Structural Regular Expressions"
by
.An Rob Pike
.Pp
.Lk http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html "vi - screen-oriented (visual) display editor"
.St -p1003.1
.
.Sh STANDARDS
.
.Nm
does not strive to be
.St -p1003.1
compatible, but shares obvious similarities with the
.Nm vi
utility.
.
.\" .Sh HISTORY
.\" TODO something about vi(m) and sam history
.
.Sh AUTHORS
.
.Nm
is written by
.An Marc André Tanner Aq mat at brain-dump.org
.
.Sh BUGS
.
On some systems there already exists a
.Nm
binary, thus causing a name conflict.