vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
vis.1
(33327B)
1 .Dd January 14, 2017
2 .Dt VIS 1
3 .Os Vis VERSION
4 .
5 .Sh NAME
6 .
7 .Nm vis
8 .Nd a highly efficient text editor
9 .
10 .Sh SYNOPSIS
11 .
12 .Nm
13 .Op Fl v
14 .Op Cm + Ns Ar command
15 .Op Fl -
16 .Op Ar files ...
17 .
18 .Sh DESCRIPTION
19 .
20 .Nm
21 is a highly efficient screen-oriented text editor combining the strengths of
22 both
23 .Nm vi(m)
24 and
25 .Nm sam .
26 .
27 This manual page is intended for users already familiar with
28 .Nm vi Ns / Ns Nm sam .
29 Anyone else should almost certainly read a good tutorial on either editor
30 before this manual page.
31 The following options are available:
32 .Bl -tag -width indent
33 .It Fl v
34 Print version information and exit.
35 .It Cm + Ns Ar command
36 Execute
37 .Ar command
38 after loading file.
39 .
40 .It Fl -
41 Denotes the end of the options.
42 Arguments after this will be handled as a
43 file name.
44 .El
45 .Pp
46 The special file
47 .Cm -
48 instructs
49 .Nm
50 to read from standard input in which case
51 .Ic :wq
52 will write to standard output, thereby enabling usage as an interactive filter.
53 .Pp
54 If standard input is redirected and all input is consumed,
55 .Nm
56 will open
57 .Pa /dev/tty
58 to gather further commands.
59 Failure to do so results in program termination.
60 .
61 .Ss Selections
62 .
63 .Nm
64 uses selections as core editing primitives.
65 A selection is a non-empty, directed range with two endpoints called
66 .Em cursor
67 and
68 .Em anchor .
69 A selection can be anchored in which case the anchor remains fixed while
70 only the position of the cursor is adjusted.
71 For non-anchored selections both endpoints are updated.
72 A singleton selection covers one character on which both cursor and
73 anchor reside.
74 There always exists a primary selection which remains visible
75 (i.e. changes to its position will adjust the viewport).
76 .
77 .Ss Modes
78 .
79 .Nm
80 employs the same
81 .Em modal
82 editing approach as
83 .Nm vi .
84 It supports a
85 .Sq normal ,
86 .Sq operator pending ,
87 .Sq insert ,
88 .Sq replace
89 and
90 .Sq visual
91 (in both line and character wise variants) mode.
92 The visual block and ex modes are deliberately not implemented,
93 instead
94 .Nm
95 has built in support for multiple selections and an
96 .Em interactive
97 variant of the structural regular expression based command language of
98 .Nm sam .
99 .Pp
100 In normal mode all selections are non-anchored and reduced to a single character.
101 .
102 .Ss Undo/Redo
103 .
104 .Nm
105 uses an undo tree to keep track of text revisions.
106 The
107 .Ic u
108 .Pq undo
109 and
110 .Aq Ic C-r
111 .Pq redo
112 commands can be used to traverse the tree along the main branch.
113 .Ic g+
114 and
115 .Ic g-
116 traverse the history in chronological order.
117 The
118 .Ic :earlier
119 and
120 .Ic :later
121 commands provide means to restore the text to an arbitrary state.
122 .
123 .Ss Marks
124 .
125 A mark associates a symbolic name to a set of selections.
126 A stored selection becomes invalid when its delimiting boundaries change
127 in the underlying buffer.
128 If said changes are later undone the mark becomes valid again.
129 .Ic m
130 sets a mark,
131 .Ic M
132 restores it.
133 For example,
134 .Ic ' Ns Ar a Ns Ic m
135 sets the mark
136 .Ar a
137 while
138 .Ic ' Ns Ar a Ns Ic M
139 restores it.
140 Use of
141 .Ic m
142 or
143 .Ic M
144 without specifying a mark uses the default mark.
145 .Pp
146 Available marks are:
147 .Bl -tag -width indent
148 .It Ic ''
149 default mark
150 .It Ic '^
151 active selections when leaving visual mode
152 .It Ic 'a Ns \(en Ns Ic 'z
153 general purpose marks
154 .El
155 .Pp
156 No marks across files are supported.
157 Marks are not preserved over editing sessions.
158 .
159 .Ss Jump list
160 .
161 A per window, fixed sized file local jump list exists which stores marks
162 (i.e. set of selections).
163 .Bl -tag -width indent
164 .It Ic g<
165 jump backward
166 .It Ic g>
167 jump forward
168 .It Ic gs
169 save currently active selections
170 .El
171 .
172 .Ss Registers
173 .
174 Registers are named lists of text.
175 Uninitialized register slots default to the empty string.
176 Available registers are:
177 .Bl -tag -width indent
178 .It Ic \(dq\(dq
179 default register
180 .It Ic \(dqa Ns \(en Ns Ic \(dqz
181 general purpose registers
182 .It Ic \(dqA Ns \(en Ns Ic \(dqZ
183 append to corresponding general purpose register
184 .It Ic \(dq* , Ic \(dq+
185 system clipboard integration via shell script
186 .Xr vis-clipboard 1
187 .It Ic \(dq0
188 yank register, most recently yanked range
189 .It Ic \(dq1 Ns \(en Ns Ic \(dq9
190 .It Ic \(dq&
191 sub expression matches of most recent
192 .Ic x
193 or
194 .Ic y
195 command
196 .It Ic \(dq/
197 search register, most recently used search pattern
198 .It Ic \(dq\&:
199 command register, most recently executed command
200 .It Ic \(dq_
201 black hole
202 .Pq Pa /dev/null
203 register, ignore content is always empty
204 .It Ic \(dq#
205 selection number (readonly)
206 .El
207 .Pp
208 If no explicit register is specified the default register is used.
209 .
210 .Ss Macros
211 .
212 The general purpose registers
213 .Ic \(dqa Ns \(en Ns Ic \(dqz
214 can be used to record macros.
215 Use one of
216 .Ic \(dqA Ns \(en Ns Ic \(dqZ
217 to append to an existing macro.
218 .Ic q
219 starts a recording,
220 .Ic @
221 plays it back.
222 .Ic @@
223 refers to the most recently recorded macro.
224 .Ic @:
225 repeats the last
226 .Ic \&: Ns -command.
227 .Ic @/
228 is equivalent to
229 .Ic n
230 in normal mode.
231 .
232 These operations always use the first register slot.
233 .
234 .Ss Encoding, Tab and Newline handling
235 .
236 .Nm
237 always assumes the input file to be UTF-8 encoded with
238 .Li \[rs]n
239 line endings.
240 If you wish to edit files with legacy encodings or non-Unix line endings,
241 use
242 .Xr iconv 1
243 and
244 .Xr dos2unix 1
245 to convert them as needed.
246 .Aq Ic Tab
247 can optionally be expanded to a configurable number of spaces (see
248 .Sx "SET OPTIONS" ) .
249 .
250 .Ss Mouse support
251 .
252 The mouse is currently not used at all.
253 .
254 .Sh SAM COMMANDS
255 .
256 .Nm
257 supports an interactive variant of the structural regular expression based
258 command language introduced by
259 .Xr sam 1 .
260 .
261 .Ss Regular expressions
262 .
263 .Nm
264 currently defers regular expression matching to the underlying C library.
265 It uses what POSIX refers to as
266 .Dq Extended Regular Expressions
267 as described in
268 .Xr regex 7 .
269 The anchors
270 .Ic ^
271 and
272 .Ic $
273 match the beginning / end of the range they are applied to.
274 Additionally
275 .Li \[rs]n
276 and
277 .Li \[rs]t
278 may be used to refer to newlines and tabs,
279 respectively.
280 The
281 .Ic \&.
282 atom matches any character except newline.
283 The empty regular expression stands for the last complete expression
284 encountered.
285 .
286 .Ss Addresses
287 .
288 An address identifies a substring (or range) in a file.
289 In the following
290 .Do
291 character
292 .Ar n
293 .Dc
294 means the null string after the
295 .Ar n Ns -th
296 character in the file, with 1 the first character in the file.
297 .Do
298 Line
299 .Ar n
300 .Dc
301 means the
302 .Ar n Ns -th
303 match, starting at the beginning of the file, of the regular expression
304 .Dq Li .*\[rs]n\&? .
305 .Pp
306 All windows always have at least one current substring which is the default
307 address.
308 In sam this is referred to as
309 .Sy dot .
310 In
311 .Nm
312 multiple
313 .Dq dots
314 (or selections) can exist at the same time.
315 .
316 .Ss Simple addresses
317 .
318 .Bl -tag -width indent
319 .It Ic # Ns Ar n
320 The empty string after character
321 .Ar n ;
322 .Ic #0
323 is the beginning of the file.
324 .It Ar n
325 Line
326 .Ar n .
327 .It Ic / Ns Ar regexp Ns Ic /
328 .It Ic \&? Ns Ar regexp Ns Ic \&?
329 The substring that matches the regular expression, found by looking
330 towards the end
331 .Pq Ic /
332 or beginning
333 .Pq Ic \&?
334 of the file.
335 The search does not wrap around when hitting the end
336 .Pq start
337 of the file.
338 .It Ic 0
339 The string before the first full line.
340 This is not necessarily the null string; see
341 .Ic +
342 and
343 .Ic -
344 below.
345 .It Ic $
346 The null string at the end of the file.
347 .It Ic \&.
348 Dot, the current range.
349 .It Ic ' Ns Ar m
350 The mark
351 .Ar m
352 in the file.
353 .El
354 .
355 .Ss Compound addresses
356 .
357 In the following,
358 .Ar a1
359 and
360 .Ar a2
361 are addresses.
362 .Bl -tag -width indent
363 .It Ar a1 Ns Ic + Ns Ar a2
364 The address
365 .Ar a2
366 evaluated starting at the end of
367 .Ar a1 .
368 .It Ar a1 Ns Ic - Ns Ar a2
369 The address
370 .Ar a2
371 evaluated looking the reverse direction starting at the beginning of
372 .Ar a1 .
373 .It Ar a1 Ns Ic \&, Ns Ar a2
374 The substring from the beginning of
375 .Ar a1
376 to the end of
377 .Ar a2 .
378 If
379 .Ar a1
380 is missing,
381 .Ic 0
382 is substituted.
383 If
384 .Ar a2
385 is missing,
386 .Ic $
387 is substituted.
388 .It Ar a1 Ns Ic \&; Ns Ar a2
389 Like
390 .Ar a1 Ns Ic \&, Ns Ar a2
391 but with
392 .Ar a2
393 evaluated at the end of, and range set to,
394 .Ar a1 .
395 .El
396 .Pp
397 The operators
398 .Ic +
399 and
400 .Ic -
401 are high precedence, while
402 .Ic \&,
403 and
404 .Ic \&;
405 are low precedence.
406 .Pp
407 In both
408 .Ic +
409 and
410 .Ic -
411 forms, if
412 .Ar a2
413 is a line or character address with a missing number, the number defaults to 1.
414 If
415 .Ar a1
416 is missing,
417 .Ic \&.
418 is substituted.
419 If both
420 .Ar a1
421 and
422 .Ar a2
423 are present and distinguishable,
424 .Ic +
425 may be elided.
426 .Ar a2
427 may be a regular expression; if it is delimited by
428 .Li \&?
429 characters, the effect of the
430 .Ic +
431 or
432 .Ic -
433 is reversed.
434 .
435 The
436 .Ic %
437 sign is an alias for
438 .Ic \&,
439 and hence
440 .Ic 0,$ .
441 .
442 It is an error for a compound address to represent a malformed substring.
443 .
444 .Ss Commands
445 .
446 In the following, text demarcated by slashes represents text delimited
447 by any printable ASCII character except alphanumerics.
448 Any number of trailing delimiters may be elided, with multiple elisions then
449 representing null strings, but the first delimiter must always be present.
450 In any delimited text, newline may not appear literally;
451 .Li \[rs]n
452 and
453 .Li \[rs]t
454 may be typed for newline and tab;
455 .Li \[rs]/
456 quotes the delimiter, here
457 .Li / .
458 An ampersand
459 .Li &
460 and
461 .Li \[rs] Ns Ar n ,
462 where
463 .Ar n
464 is a digit (1\(en9) are replaced by the corresponding register.
465 Backslash is otherwise interpreted literally.
466 .Pp
467 Most commands may be prefixed with an address to indicate their range of
468 operation.
469 If a command takes an address and none is supplied, a default address is used.
470 In normal mode this equates to the character the selection is currently over.
471 If only one selection exists
472 .Ic x
473 and
474 .Ic y
475 default to the whole file
476 .Ic 0,$ .
477 In normal mode the write commands
478 .Ic w
479 and
480 .Ic wq
481 always apply to the whole file.
482 Commands are executed once for every selection.
483 In visual mode the commands are applied to every selection
484 as if an implicit
485 .Ic x
486 command, matching the existing selections, was present.
487 .
488 .Pp
489 In the description,
490 .Dq range
491 is used to represent whatever address is supplied.
492 .Pp
493 Many commands create new selections as a side effect when issued from a visual
494 mode.
495 If so, it is always to the “result” of the change: the new text for an
496 insertion, the empty string for a deletion, the command output of a filter etc.
497 If after a successful command execution no selections remain,
498 the editor will switch to normal mode, otherwise it remains in
499 visual mode.
500 This allows
501 .Em interactive
502 refinements of ranges.
503 .
504 .\" Many commands set the value of dot as a side effect.
505 .\" If so, it is always to the
506 .\" .Dq result
507 .\" of the change: the empty string for a deletion, the new text for an
508 .\" insertion, etc.
509 .\" .Po
510 .\" but see the
511 .\" .Sy s
512 .\" and
513 .\" .Sy e
514 .\" commands
515 .\" .Pc .
516 .
517 .Ss Text commands
518 .
519 .Bl -tag -width indent
520 .It Ic a Ns [ Ar count ] Ns / Ns Ar text Ns Ic /
521 Insert the
522 .Ar text
523 .Ar count
524 times into the file after the range.
525 .\" Set dot.
526 .Pp
527 May also be written as
528 .Bd -literal -offset indent
529 a
530 lines
531 of
532 text
533 .
534 .Ed
535 .
536 .It Ic c No or Ic i
537 Same as
538 .Ic a ,
539 but
540 .Ic c
541 replaces the text, while
542 .Ic i
543 inserts
544 .Em before
545 the range.
546 .
547 .It Ic d
548 Delete the text in range.
549 .\" Set dot.
550 .El
551 .
552 .Ss Display commands
553 .
554 .Bl -tag -width Ds
555 .It Ic p
556 Create a new selection for the range.
557 .El
558 .
559 .Ss I/O commands
560 .
561 .Bl -tag -width indent
562 .It Ic e Ns Oo Cm \&! Oc Op Pa file name
563 Replace the file by the contents of the named external file.
564 If no file name is given, reload file from disk.
565 .
566 .It Ic r Ar file name
567 Replace the text in the range by the contents of the named external file.
568 .\" Set dot.
569 .
570 .It Ic w Ns Oo Cm \&! Oc Op Ar file name
571 Write the range
572 .Po
573 default
574 .Ic 0,$
575 .Pc
576 to the named external file.
577 .
578 .It Ic wq Ns Oo Cm \&! Oc Op Ar file name
579 Same as
580 .Ic w ,
581 but close file afterwards.
582 .El
583 .Pp
584 If the file name argument is absent from any of these, the current file name is
585 used.
586 .
587 .Ic e
588 always sets the file name,
589 .Ic w
590 will do so if the file has no name.
591 Forcing the
592 .Ic e
593 command with
594 .Cm \&!
595 will discard any unsaved changes.
596 Forcing
597 .Ic w
598 will overwrite the file on disk even if it has been externally modified
599 since loading it.
600 Write commands with a non-default addresses and no file name are destructive
601 and need always to be forced.
602 .Bl -tag -width indent
603 .
604 .It Ic < Ar shell command
605 Replace the range by the standard output of the shell command.
606 .
607 .It Ic > Ar shell command
608 Sends the range to the standard input of the shell command.
609 .
610 .It Ic \&| Ar shell command
611 Send the range to the standard input, and replace it by the standard output, of
612 the shell command.
613 .
614 .It Ic \&! Ar shell command
615 Run interactive shell command, redirect keyboard input to it.
616 .
617 .It Ic cd Ar directory
618 Change working directory.
619 If no directory is specified,
620 .Ev "$HOME"
621 is used.
622 .El
623 .Pp
624 In any of
625 .Ic < ,
626 .Ic > ,
627 .Ic \&| ,
628 or
629 .Ic \&! ,
630 if the shell command is omitted, the last shell command
631 .Pq of any type
632 is substituted.
633 Unless the file being edited is unnamed, all these external commands
634 can refer to its absolute path and file name through the
635 .Ev vis_filepath
636 and
637 .Ev vis_filename
638 environment variables.
639 .
640 .Ss Loops and conditionals
641 .
642 .Bl -tag -width indent
643 .It Ic x/ Ns Ar regexp Ns Ic / Op Ar command
644 For each match of the regular expression in the range, run the command with
645 range set to the match.
646 If the regular expression and its slashes are omitted,
647 .Ar "/.*\[rs]n/"
648 is assumed.
649 Null string matches potentially occur before every character of the range and
650 at the end of the range.
651 .Pp
652 The
653 .Ic \(dq1 Ns \(en Ns Ic \(dq9
654 and
655 .Ic \(dq&
656 registers are updated with the (sub) expression matches of the pattern.
657 .
658 .It Ic y/ Ns Ar regexp Ns Ic / Op Ar command
659 Like
660 .Ic x ,
661 but run the command for each substring that lies before, between, or after the
662 matches that would be generated by
663 .Ic x .
664 There is no default behavior.
665 Null substrings potentially occur before every character in the range.
666 .
667 .It Ic X/ Ns Ar regexp Ns Ic "/" Ar command
668 For each file whose file name matches the regular expression, make that the
669 current file and run the command.
670 If the expression is omitted, the command is run in every file.
671 .
672 .It Ic Y/ Ns Ar regexp Ns Ic / Ar command
673 Same as
674 .Ic X ,
675 but for files that do not match the regular expression, and the expression is
676 required.
677 .\" TODO improve markup, use Op macro, make it actually understandable :/
678 .It Ic g Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
679 .It Ic v Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
680 If the
681 .Ar count
682 range contains
683 .Po
684 .Ic g
685 .Pc
686 or does not contain
687 .Po
688 .Ic v
689 .Pc
690 a match for the expression, run command on the range.
691 .Pp
692 The
693 .Ar count
694 specifier has the following format, where
695 .Ar n
696 and
697 .Ar m
698 are integers denoting the ranges.
699 .Bl -tag -width indent
700 .It Ar n Ns Ic \&, Ns Ar m
701 The closed interval from
702 .Ar n
703 to
704 .Ar m .
705 If
706 .Ar n
707 is missing,
708 .Ic 1
709 is substituted.
710 If
711 .Ar m
712 is missing,
713 .Ic ∞
714 is substituted.
715 Negative values are interpreted relative to the last range.
716 .It Ic % Ns Ar n
717 Matches every
718 .Ar n Ns -th
719 range.
720 .El
721 .
722 .El
723 .Pp
724 These may be nested arbitrarily deeply.
725 An empty command in an
726 .Ic x
727 or
728 .Ic y
729 defaults to
730 .Ic p .
731 .Ic X ,
732 .Ic Y ,
733 .Ic g
734 and
735 .Ic v
736 do not have defaults.
737 .
738 .Ss Grouping and multiple changes
739 .
740 Commands may be grouped by enclosing them in curly braces.
741 Semantically, the opening brace is like a command: it takes an
742 .Pq optional
743 address and runs each sub-command on the range.
744 Commands within the braces are executed sequentially, but changes
745 made by one command are not visible to other commands.
746 .Pp
747 When a command makes a number of changes to a file, as in
748 .Ic x/ Ns Ar re Ns Ic / Ic c/ Ns Ar text Ns Ic / ,
749 the addresses of all changes are computed based on the initial state.
750 If the changes are non-overlapping, they are applied in the specified
751 order.
752 Conflicting changes are rejected.
753 .Pp
754 Braces may be nested arbitrarily.
755 .
756 .Sh VI(M) KEY BINDINGS
757 .
758 In the following sections angle brackets are used to denote special keys.
759 The prefixes
760 .Ic C- ,
761 .Ic S- ,
762 and
763 .Ic M-
764 are used to refer to the
765 .Aq Ctrl ,
766 .Aq Shift
767 and
768 .Aq Alt
769 modifiers, respectively.
770 .Pp
771 All active key bindings can be listed at runtime using the
772 .Ic :help
773 command.
774 .
775 .Ss Operators
776 .
777 Operators perform a certain operation on a text range indicated by either a
778 motion, a text object or an existing selection.
779 .Pp
780 When used in normal mode, the following operators wait for a motion, putting
781 vis into operator pending mode.
782 .Bl -tag -width XXXXXXXXXX -compact
783 .It Ic c
784 change, delete range and enter insert mode
785 .
786 .It Ic d
787 delete, cut range to register
788 .
789 .It Ic <
790 shift-left, decrease indent
791 .
792 .It Ic >
793 shift-right, increase indent
794 .
795 .It Ic y
796 yank, copy range to register
797 .El
798 .Pp
799 When used in normal mode, the following actions take effect immediately.
800 .Bl -tag -width XXXXXXXXXX -compact
801 .It Ic =
802 format, filter range through
803 .Xr fmt 1
804 .
805 .It Ic gu
806 make lowercase
807 .
808 .It Ic gU
809 make uppercase
810 .
811 .It Ic g~
812 swap case
813 .
814 .It Ic J
815 join lines, insert spaces in between
816 .
817 .It Ic gJ
818 join lines remove any delimiting white spaces
819 .
820 .It Ic p
821 put register content after cursor
822 .
823 .It Ic P
824 put register content before cursor
825 .
826 .El
827 .
828 .Ss Motions
829 .
830 .\" TODO? more formal definition: pos -> [min(pos, f(pos)), max(pos, f(pos))]
831 Motions take an initial file position and transform it to a destination file
832 position,
833 thereby defining a range.
834 .\" TODO define word/WORD
835 .Pp
836 .Bl -tag -width XXXXXXXXXX -compact
837 .It Ic 0
838 start of line
839 .
840 .It Ic b
841 previous start of a word
842 .
843 .It Ic B
844 previous start of a WORD
845 .
846 .It Ic $
847 end of line
848 .
849 .It Ic e
850 next end of a word
851 .
852 .It Ic E
853 next end of a WORD
854 .
855 .It Ic F Ns Aq Ar char
856 to next occurrence of
857 .Aq Ar char
858 to the left
859 .
860 .It Ic f Ns Aq Ar char
861 to next occurrence of
862 .Aq Ar char
863 to the right
864 .
865 .It Ic ^
866 first non-blank of line
867 .
868 .It Ic g0
869 begin of display line
870 .
871 .It Ic g$
872 end of display line
873 .
874 .It Ic ge
875 previous end of a word
876 .
877 .It Ic gE
878 previous end of a WORD
879 .
880 .It Ic gg
881 begin of file
882 .
883 .It Ic G
884 goto line or end of file
885 .
886 .It Ic gj
887 display line down
888 .
889 .It Ic gk
890 display line up
891 .
892 .It Ic gh
893 codepoint left
894 .
895 .It Ic gl
896 codepoint right
897 .
898 .It Ic gH
899 byte left
900 .
901 .It Ic gL
902 byte right
903 .It Ic g_
904 last non-blank of line
905 .
906 .It Ic gm
907 middle of display line
908 .
909 .It Ic g\&|
910 goto column
911 .
912 .It Ic h
913 char left
914 .
915 .It Ic H
916 goto top/home line of window
917 .
918 .It Ic j
919 line down
920 .
921 .It Ic k
922 line up
923 .
924 .It Ic l
925 char right
926 .
927 .It Ic L
928 goto bottom/last line of window
929 .
930 .It Ic %
931 match bracket, quote or backtick
932 .
933 .It Ic }
934 next paragraph
935 .
936 .It Ic \&)
937 next sentence
938 .
939 .It Ic N
940 repeat last search backwards
941 .
942 .It Ic n
943 repeat last search forward
944 .
945 .It Ic [{
946 previous start of block
947 .
948 .It Ic ]}
949 next start of block
950 .
951 .It Ic [(
952 previous start of parentheses pair
953 .
954 .It Ic ])
955 next start of parentheses pair
956 .
957 .It Ic {
958 previous paragraph
959 .
960 .It Ic \&(
961 previous sentence
962 .
963 .It Ic \&;
964 repeat last to/till movement
965 .
966 .It Ic \&,
967 repeat last to/till movement but in opposite direction
968 .
969 .It Ic #
970 search word under selection backwards
971 .
972 .It Ic *
973 search word under selection forwards
974 .
975 .It Ic T Ns Aq Ar char
976 till before next occurrence of
977 .Aq Ar char
978 to the left
979 .
980 .It Ic t Ns Aq Ar char
981 till before next occurrence of
982 .Aq Ar char
983 to the right
984 .
985 .It Ic \&? Ns Ar pattern
986 to next match of
987 .Ar pattern
988 in backward direction
989 .
990 .It Ic / Ns Ar pattern
991 to next match of
992 .Ar pattern
993 in forward direction
994 .
995 .It Ic w
996 next start of a word
997 .
998 .It Ic W
999 next start of a WORD
1000 .El
1001 .
1002 .Ss Text objects
1003 .
1004 .\" TODO? more formal definition: text-object: pos -> [a, b]
1005 Text objects take an initial file position and transform it to a range
1006 where the former does not necessarily have to be contained in the latter.
1007 .
1008 All of the following text objects are implemented in an inner variant
1009 (prefixed with
1010 .Ic i )
1011 where the surrounding white space or delimiting characters are not part
1012 of the resulting range and a normal variant (prefixed with
1013 .Ic a )
1014 where they are.
1015 .Pp
1016 .Bl -tag -width XXXXXXXXXX -compact
1017 .
1018 .It Ic w
1019 word
1020 .
1021 .It Ic W
1022 WORD
1023 .
1024 .It Ic s
1025 sentence
1026 .
1027 .It Ic p
1028 paragraph
1029 .
1030 .It Ic [, ], (, ), {, }, <, >, \(dq, ', `
1031 block enclosed by these symbols
1032 .El
1033 .Pp
1034 Further available text objects include:
1035 .Bl -tag -width XXXXXXXXXX -compact
1036 .
1037 .It Ic gn
1038 matches the last used search term in forward direction
1039 .
1040 .It Ic gN
1041 matches the last used search term in backward direction
1042 .
1043 .It Ic al
1044 current line
1045 .
1046 .It Ic il
1047 current line without leading and trailing white spaces
1048 .El
1049 .
1050 .Ss Multiple Selections
1051 .
1052 .Nm
1053 supports multiple selections with immediate visual feedback.
1054 There always exists one primary selection located within the current
1055 view port.
1056 Additional selections can be created as needed.
1057 If more than one selection exists, the primary one is styled differently.
1058 .Pp
1059 To manipulate selections use in normal mode:
1060 .Pp
1061 .Bl -tag -width XXXXXXXXXX -compact
1062 .It Aq Ic C-k
1063 create count new selections on the lines above
1064 .
1065 .It Aq Ic C-M-k
1066 create count new selections on the lines above the first selection
1067 .
1068 .It Aq Ic C-j
1069 create count new selections on the lines below
1070 .
1071 .It Aq Ic C-M-j
1072 create count new selections on the lines below the last selection
1073 .
1074 .It Aq Ic C-p
1075 remove primary selection
1076 .
1077 .It Aq Ic C-n
1078 select word the selection is currently over, switch to visual mode
1079 .
1080 .It Aq Ic C-u
1081 make the count previous selection primary
1082 .
1083 .It Aq Ic C-d
1084 make the count next selection primary
1085 .
1086 .It Aq Ic C-c
1087 remove the count selection column
1088 .
1089 .It Aq Ic C-l
1090 remove all but the count selection column
1091 .
1092 .It Aq Ic Tab
1093 try to align all selections on the same column
1094 .
1095 .It Aq Ic Escape
1096 dispose all but the primary selection
1097 .El
1098 .Pp
1099 The visual modes were enhanced to recognize:
1100 .Pp
1101 .Bl -tag -width XXXXXXXXXX -compact
1102 .It Ic I
1103 create a selection at the start of every selected line
1104 .
1105 .It Ic A
1106 create a selection at the end of every selected line
1107 .
1108 .It Aq Ic Tab
1109 left align selections by inserting spaces
1110 .
1111 .It Aq Ic S-Tab
1112 right align selections by inserting spaces
1113 .
1114 .It Aq Ic C-a
1115 create new selections everywhere matching current word or selection
1116 .
1117 .It Aq Ic C-n
1118 create new selection and select next word matching current selection
1119 .
1120 .It Aq Ic C-x
1121 clear (skip) current selection, but select next matching word
1122 .
1123 .It Aq Ic C-p
1124 remove primary selection
1125 .
1126 .It Ao Ic C-u Ac Ao Ic C-k Ac
1127 make the count previous selection primary
1128 .
1129 .It Ao Ic C-d Ac Ao Ic C-j Ac
1130 make the count next selection primary
1131 .
1132 .It Aq Ic C-c
1133 remove the count selection column
1134 .
1135 .It Aq Ic C-l
1136 remove all but the count selection column
1137 .
1138 .It Ic +
1139 rotate selections rightwards count times
1140 .
1141 .It Ic -
1142 rotate selections leftwards count times
1143 .
1144 .It Ic _
1145 trim selections, remove leading and trailing white space
1146 .
1147 .It Ic o
1148 flip selection direction, swap cursor and anchor
1149 .
1150 .It Aq Ic Escape
1151 clear all selections, switch to normal mode
1152 .El
1153 .Pp
1154 In insert and replace mode:
1155 .Pp
1156 .Bl -tag -width XXXXXXXXXX -compact
1157 .It Aq Ic S-Tab
1158 align all selections by inserting spaces
1159 .El
1160 .Pp
1161 Selections can be manipulated using set operations.
1162 The first operand is the currently active selections while the second
1163 can be specified as a mark.
1164 For example,
1165 .Ic ' Ns Ar a Ns Ic \&|
1166 produces the union of the mark
1167 .Ar a
1168 and the current selection.
1169 Use of set operations without specifying a mark use the default mark as
1170 the first operand.
1171 .Pp
1172 .Bl -tag -width XXXXXXXXXX -compact
1173 .It Ic \&|
1174 set union
1175 .It Ic &
1176 set intersection
1177 .It Ic \e
1178 set minus
1179 .It Ic ~
1180 set complement
1181 .El
1182 .
1183 .Sh VI(M) COMMANDS
1184 .
1185 Any unique prefix can be used to abbreviate a command.
1186 .
1187 .Ss File and Window management
1188 .
1189 A file must be opened in at least one window.
1190 If the last window displaying a certain file is closed all unsaved changes are
1191 discarded.
1192 Windows are equally sized and can be displayed in rows (horizontally)
1193 or in columns (vertically).
1194 The
1195 .Aq Ic C-w
1196 .Ic h ,
1197 .Aq Ic C-w
1198 .Ic j ,
1199 .Aq Ic C-w
1200 .Ic k
1201 and
1202 .Aq Ic C-w
1203 .Ic l
1204 key mappings can be used to switch between windows.
1205 .Bl -tag -width indent
1206 .It Ic :new
1207 open an empty window, arranged as a new row (horizontally)
1208 .
1209 .It Ic :vnew
1210 open an empty window, arranged as a new column (vertically)
1211 .
1212 .It Ic :open Ns Oo Cm \&! Oc Op Ar file name
1213 open a new window, displaying file name if given
1214 .
1215 .It Ic :split Op Ar file name
1216 split window into rows (horizontally)
1217 .
1218 .It Ic :vsplit Op Ar file name
1219 split window into columns (vertically)
1220 .
1221 .It Ic :q Ns Oo Cm \&! Oc Op Ar exit code
1222 close currently focused window
1223 .
1224 .It Ic :qall Ns Oo Cm \&! Oc Op Ar exit code
1225 close all windows, terminate editor with exit code (defaults to 0)
1226 .El
1227 .Pp
1228 Commands taking a file name will invoke the
1229 .Xr vis-open 1
1230 utility, if given a file pattern or directory.
1231 .
1232 .Ss Runtime key mappings
1233 .
1234 .Nm
1235 supports global as well as window local run time key mappings which are
1236 always evaluated recursively.
1237 .
1238 .Bl -tag -width indent
1239 .It Ic :map Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
1240 add a global key mapping
1241 .
1242 .It Ic :map-window Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
1243 add a window local key mapping
1244 .
1245 .It Ic :unmap Ar mode Ar lhs
1246 remove a global key mapping
1247 .
1248 .It Ic :unmap-window Ar mode Ar lhs
1249 remove a window local key mapping
1250 .El
1251 .Pp
1252 In the above
1253 .Ar mode
1254 refers to one of
1255 .Ql normal ,
1256 .Ql insert ,
1257 .Ql replace ,
1258 .Ql visual ,
1259 .Ql visual-line
1260 or
1261 .Ql operator-pending ;
1262 .Ar lhs
1263 refers to the key to map and
1264 .Ar rhs
1265 is a key action or alias.
1266 An existing mapping may be overridden by forcing the map command by specifying
1267 .Cm \&! .
1268 .Pp
1269 Because key mappings are always recursive, doing something like:
1270 .Pp
1271 .Dl :map! normal j 2j
1272 .Pp
1273 will not work because it would enter an endless loop.
1274 Instead,
1275 .Nm
1276 uses pseudo keys referred to as key actions which can be used to invoke
1277 a set of available editor functions.
1278 .Ic :help
1279 lists all currently active key bindings as well as all available symbolic
1280 keys.
1281 .
1282 .Ss Keyboard Layout Specific Mappings
1283 .
1284 In order to facilitate usage of non-latin keyboard layouts,
1285 .Nm
1286 allows one to map locale specific keys to their latin equivalents by means of the
1287 .Pp
1288 .D1 Ic :langmap Ar locale-keys Ar latin-keys
1289 .Pp
1290 command.
1291 As an example, the following maps the movement keys in Russian layout:
1292 .Pp
1293 .Dl :langmap ролд hjkl
1294 .Pp
1295 If the key sequences have not the same length, the remainder of the longer
1296 sequence will be discarded.
1297 .Pp
1298 The defined mappings take effect
1299 in all non-input modes, i.e. everywhere except in insert and replace mode.
1300 .
1301 .Ss Undo/Redo
1302 .
1303 .Bl -tag -width indent
1304 .It Ic :earlier Op Ar count
1305 revert to older text state
1306 .It Ic :later Op Ar count
1307 revert to newer text state
1308 .El
1309 .Pp
1310 If count is suffixed by either of
1311 .Sy d
1312 .Pq days ,
1313 .Sy h
1314 .Pq hours ,
1315 .Sy m
1316 .Pq minutes
1317 or
1318 .Sy s
1319 .Pq seconds
1320 it is interpreted as an offset from the current system time and the closest
1321 available text state is restored.
1322 .
1323 .Sh SET OPTIONS
1324 .
1325 There are a small number of options that may be set
1326 .Pq or unset
1327 to change the editor's behavior using the
1328 .Ic :set
1329 command.
1330 This section describes the options, their abbreviations and their
1331 default values.
1332 Boolean options can be toggled by appending
1333 .Sy \&!
1334 to the option name.
1335 .Pp
1336 In each entry below, the first part of the tag line is the full name
1337 of the option, followed by any equivalent abbreviations.
1338 The part in square brackets is the default value of the option.
1339 .Bl -tag -width indent
1340 .It Ic shell Op Dq Pa /bin/sh
1341 User shell to use for external commands, overrides
1342 .Ev SHELL
1343 and shell field of password database
1344 .Pa /etc/passwd
1345 .
1346 .It Ic escdelay Op Ar 50
1347 Milliseconds to wait before deciding whether an escape sequence should
1348 be treated as an
1349 .Aq Cm Escape
1350 key.
1351 .
1352 .It Ic tabwidth , Ic tw Op Ar 8
1353 Display width of a tab and number of spaces to use if
1354 .Ic expandtab
1355 is enabled.
1356 .
1357 .It Ic autoindent , Cm ai Op Cm off
1358 Automatically indent new lines by copying white space from previous line.
1359 .
1360 .It Ic expandtab , Ic et Op Cm off
1361 Whether
1362 .Aq Ic Tab
1363 should be expanded to
1364 .Ic tabwidth
1365 spaces.
1366 .
1367 .It Ic number , Ic nu Op Cm off
1368 Display absolute line numbers.
1369 .
1370 .It Ic relativenumbers , Ic rnu Op Cm off
1371 Display relative line numbers.
1372 .
1373 .It Ic cursorline , Ic cul Op Cm off
1374 Highlight line primary cursor resides on.
1375 .
1376 .It Ic colorcolumn , Ic cc Op Ar 0
1377 Highlight a fixed column.
1378 .
1379 .It Ic horizon Op Ar 32768
1380 How many bytes back the lexer will look to synchronize parsing.
1381 .
1382 .It Ic theme Op Do default-16 Dc or Do default-256 Dc
1383 Color theme to use, name without file extension.
1384 Loaded from a
1385 .Pa themes/
1386 sub directory of the paths listed in the
1387 .Sx FILES
1388 section.
1389 .
1390 .It Cm syntax Op Cm auto
1391 Syntax highlighting lexer to use, name without file extension.
1392 .
1393 .It Cm showtabs Op Cm off
1394 Whether to display replacement symbol instead of tabs.
1395 .
1396 .It Cm shownewlines Op Cm off
1397 Whether to display replacement symbol instead of newlines.
1398 .
1399 .It Cm showspaces Op Cm off
1400 Whether to display replacement symbol instead of blank cells.
1401 .
1402 .It Cm showeof Op Cm on
1403 Whether to display replacement symbol for lines after the end of the file.
1404 .
1405 .It Cm savemethod Op Ar auto
1406 How the current file should be saved,
1407 .Ar atomic
1408 which uses
1409 .Xr rename 2
1410 to atomically replace the file,
1411 .Ar inplace
1412 which truncates the file and then rewrites it or
1413 .Ar auto
1414 which tries the former before falling back to the latter.
1415 The rename method fails for symlinks, hardlinks, in case of insufficient
1416 directory permissions or when either the file owner, group, POSIX ACL or
1417 SELinux labels can not be restored.
1418 .It Cm loadmethod Op Ar auto
1419 How existing files should be loaded,
1420 .Ar read
1421 which copies the file content to an independent in-memory buffer,
1422 .Ar mmap
1423 which memory maps the file from disk and uses OS capabilities as
1424 caching layer or
1425 .Ar auto
1426 which tries the former for files smaller than 8Mb and the latter for
1427 larger ones.
1428 WARNING: modifying a memory mapped file in-place will cause data loss.
1429 .It Ic layout Op Do v Dc or Do h Dc
1430 Whether to use vertical or horizontal layout.
1431 .It Cm ignorecase , Cm ic Op Cm off
1432 Whether to ignore case when searching.
1433 .It Ic wrapcolumn , Ic wc Op Ar 0
1434 Wrap lines at minimum of window width and wrapcolumn.
1435 .
1436 .It Ic breakat , brk Op Dq Pa ""
1437 Characters which might cause a word wrap.
1438 .El
1439 .
1440 .Sh COMMAND and SEARCH PROMPT
1441 .
1442 The command and search prompt as opened by
1443 .Ic \&: ,
1444 .Ic / ,
1445 or
1446 .Ic \&?
1447 is implemented as a single line height window, displaying a regular file
1448 whose editing starts in insert mode.
1449 .Aq Ic Escape
1450 switches to normal mode, a second
1451 .Aq Ic Escape
1452 cancels the prompt.
1453 .Aq Ic Up
1454 enlarges the window, giving access to the command history.
1455 .Aq Ic C-v
1456 .Aq Ic Enter
1457 inserts a literal new line thus enabling multiline commands.
1458 .Aq Ic Enter
1459 executes the visual selection if present, or else everything in the
1460 region spawned by the selection position and the delimiting prompt symbols
1461 at the start of adjacent lines.
1462 .
1463 .Sh CONFIGURATION
1464 .
1465 .Nm
1466 uses Lua for configuration and scripting purposes.
1467 During startup
1468 .Pa visrc.lua
1469 (see the
1470 .Sx FILES
1471 section) is sourced which can be used to set personal configuration options.
1472 As an example the following will enable the display of line numbers:
1473 .Pp
1474 .Dl vis:command('set number')
1475 .
1476 .Sh ENVIRONMENT
1477 .
1478 .Bl -tag -width indent
1479 .It Ev VIS_PATH
1480 The default path to use to load Lua support files.
1481 .It Ev HOME
1482 The home directory used for the
1483 .Ic cd
1484 command if no argument is given.
1485 .It Ev TERM
1486 The terminal type to use to initialize the curses interface, defaults to
1487 .Sy xterm
1488 if unset.
1489 .It Ev SHELL
1490 The command shell to use for I/O related commands like
1491 .Ic \&! ,
1492 .Ic > ,
1493 .Ic <
1494 and
1495 .Ic \&| .
1496 .It Ev XDG_CONFIG_HOME
1497 The configuration directory to use, defaults to
1498 .Pa $HOME/.config
1499 if unset.
1500 .El
1501 .
1502 .Sh ASYNCHRONOUS EVENTS
1503 .
1504 .Bl -tag -width indent
1505 .It Dv SIGSTOP
1506 Suspend editor.
1507 .It Dv SIGCONT
1508 Resume editor.
1509 .It Dv SIGBUS
1510 An
1511 .Xr mmap 2
1512 ed file got truncated, unsaved file contents will be lost.
1513 .It Dv SIGHUP
1514 .It Dv SIGTERM
1515 Restore initial terminal state.
1516 Unsaved file contents will be lost.
1517 .It Dv SIGINT
1518 When an interrupt occurs while an external command is being run it is terminated.
1519 .It Dv SIGWINCH
1520 The screen is resized.
1521 .El
1522 .
1523 .Sh FILES
1524 .
1525 Upon startup
1526 .Nm
1527 will source the first
1528 .Pa visrc.lua
1529 configuration file found from these locations.
1530 All actively used paths can be listed at runtime using the
1531 .Cm :help
1532 command.
1533 .Bl -bullet
1534 .It
1535 .Pa $VIS_PATH
1536 .It
1537 The location of the
1538 .Nm
1539 binary (on systems where
1540 .Pa /proc/self/exe
1541 is available).
1542 .It
1543 .Pa $XDG_CONFIG_HOME/vis
1544 where
1545 .Ev XDG_CONFIG_HOME
1546 refers to
1547 .Pa $HOME/.config
1548 if unset.
1549 .
1550 .It
1551 .Pa /etc/vis
1552 for a system-wide configuration provided by administrator.
1553 .It
1554 .Pa /usr/local/share/vis
1555 or
1556 .Pa /usr/share/vis
1557 depending on the build configuration.
1558 .
1559 .Pp
1560 When creating a new
1561 .Pa visrc.lua
1562 be sure to copy the structure from here.
1563 .El
1564 .
1565 .Sh EXIT STATUS
1566 .
1567 .Ex -std
1568 .
1569 .Sh EXAMPLES
1570 .
1571 Use
1572 .Nm
1573 as an interactive filter.
1574 .Pp
1575 .Dl $ { echo Pick your number; seq 1 10; } | vis - > choice
1576 .Pp
1577 Use the
1578 .Xr vis-open 1
1579 based file browser to list all C language source files:
1580 .Pp
1581 .Dl :e *.c
1582 .Pp
1583 Spawn background process and pipe range to its standard input:
1584 .Pp
1585 .Dl :> { plumber <&3 3<&- & } 3<&0 1>&- 2>&-
1586 .
1587 .Sh SEE ALSO
1588 .
1589 .Xr sam 1 ,
1590 .Xr vi 1 ,
1591 .Xr vis-clipboard 1 ,
1592 .Xr vis-complete 1 ,
1593 .Xr vis-digraph 1 ,
1594 .Xr vis-menu 1 ,
1595 .Xr vis-open 1
1596 .Pp
1597 .Lk http://doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pdf "A Tutorial for the Sam Command Language"
1598 by
1599 .An Rob Pike
1600 .Pp
1601 .Lk http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ "The Text Editor sam"
1602 by
1603 .An Rob Pike
1604 .Pp
1605 .Lk http://man.cat-v.org/plan_9/1/sam "Plan 9 manual page for sam(1)"
1606 .Pp
1607 .Lk http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf "Structural Regular Expressions"
1608 by
1609 .An Rob Pike
1610 .Pp
1611 .Lk http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html "vi - screen-oriented (visual) display editor"
1612 .St -p1003.1
1613 .
1614 .Sh STANDARDS
1615 .
1616 .Nm
1617 does not strive to be
1618 .St -p1003.1
1619 compatible, but shares obvious similarities with the
1620 .Nm vi
1621 utility.
1622 .
1623 .\" .Sh HISTORY
1624 .\" TODO something about vi(m) and sam history
1625 .
1626 .Sh AUTHORS
1627 .
1628 .Nm
1629 is written by
1630 .An Marc André Tanner Aq mat at brain-dump.org
1631 .
1632 .Sh BUGS
1633 .
1634 On some systems there already exists a
1635 .Nm
1636 binary, thus causing a name conflict.