filetype: Set "groovy" for Jenkinsfile
[vis.git] / man / vis.1
blob054336637a8fd7efd7d21fadd202dbeeb1c01a51
1 .Dd January 14, 2017
2 .Dt VIS 1
3 .Os Vis VERSION
5 .Sh NAME
7 .Nm vis
8 .Nd a highly efficient text editor
10 .Sh SYNOPSIS
12 .Nm
13 .Op Fl v
14 .Op Cm + Ns Ar command
15 .Op Fl -
16 .Op Ar files ...
18 .Sh DESCRIPTION
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 .
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.
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.
61 .Ss Selections
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).
77 .Ss Modes
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.
102 .Ss Undo/Redo
105 uses an undo tree to keep track of text revisions.
107 .Ic u
108 .Pq undo
110 .Aq Ic C-r
111 .Pq redo
112 commands can be used to traverse the tree along the main branch.
113 .Ic g+
115 .Ic g-
116 traverse the history in chronological order.
118 .Ic :earlier
120 .Ic :later
121 commands provide means to restore the text to an arbitrary state.
123 .Ss Marks
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.
141 Available marks are:
142 .Bl -tag -width indent
143 .It Ic ''
144 default mark
145 .It Ic '^
146 active selections when leaving visual mode
147 .It Ic 'a Ns \(en Ns Ic 'z
148 general purpose marks
151 No marks across files are supported.
152 Marks are not preserved over editing sessions.
154 .Ss Jump list
156 A per window, fixed sized file local jump list exists which stores marks
157 (i.e. set of selections).
158 .Bl -tag -width indent
159 .It Ic g<
160 jump backward
161 .It Ic g>
162 jump forward
163 .It Ic gs
164 save currently active selections
167 .Ss Registers
169 Registers are named lists of text.
170 Uninitialized register slots default to the empty string.
171 Available registers are:
172 .Bl -tag -width indent
173 .It Ic \(dq\(dq
174 default register
175 .It Ic \(dqa Ns \(en Ns Ic \(dqz
176 general purpose registers
177 .It Ic \(dqA Ns \(en Ns Ic \(dqZ
178 append to corresponding general purpose register
179 .It Ic \(dq* , Ic \(dq+
180 system clipboard integration via shell script
181 .Xr vis-clipboard 1
182 .It Ic \(dq0
183 yank register, most recently yanked range
184 .It Ic \(dq1 Ns \(en Ns Ic \(dq9
185 .It Ic \(dq&
186 sub expression matches of most recent
187 .Ic x
189 .Ic y
190 command
191 .It Ic \(dq/
192 search register, most recently used search pattern
193 .It Ic \(dq\&:
194 command register, most recently executed command
195 .It Ic \(dq_
196 black hole
197 .Pq Pa /dev/null
198 register, ignore content is always empty
199 .It Ic \(dq#
200 selection number (readonly)
203 If no explicit register is specified the default register is used.
205 .Ss Macros
207 The general purpose registers
208 .Ic \(dqa Ns \(en Ns Ic \(dqz
209 can be used to record macros.
210 Use one of
211 .Ic \(dqA Ns \(en Ns Ic \(dqZ
212 to append to an existing macro.
213 .Ic q
214 starts a recording,
215 .Ic @
216 plays it back.
217 .Ic @@
218 refers to the most recently recorded macro.
219 .Ic @:
220 repeats the last
221 .Ic \&: Ns -command.
222 .Ic @/
223 is equivalent to
224 .Ic n
225 in normal mode.
227 These operations always use the first register slot.
229 .Ss Encoding, Tab and Newline handling
232 always assumes the input file to be UTF-8 encoded with
233 .Li \[rs]n
234 line endings.
235 If you wish to edit files with legacy encodings or non-Unix line endings,
237 .Xr iconv 1
239 .Xr dos2unix 1
240 to convert them as needed.
241 .Aq Ic Tab
242 can optionally be expanded to a configurable number of spaces (see
243 .Sx "SET OPTIONS" ) .
245 .Ss Mouse support
247 The mouse is currently not used at all.
249 .Sh SAM COMMANDS
252 supports an interactive variant of the structural regular expression based
253 command language introduced by
254 .Xr sam 1 .
256 .Ss Regular expressions
259 currently defers regular expression matching to the underlying C library.
260 It uses what POSIX refers to as
261 .Dq Extended Regular Expressions
262 as described in
263 .Xr regex 7 .
264 The anchors
265 .Ic ^
267 .Ic $
268 match the beginning / end of the range they are applied to.
269 Additionally
270 .Li \[rs]n
272 .Li \[rs]t
273 may be used to refer to newlines and tabs,
274 respectively.
276 .Ic \&.
277 atom matches any character except newline.
278 The empty regular expression stands for the last complete expression
279 encountered.
281 .Ss Addresses
283 An address identifies a substring (or range) in a file.
284 In the following
286 character
287 .Ar n
289 means the null string after the
290 .Ar n Ns -th
291 character in the file, with 1 the first character in the file.
293 Line
294 .Ar n
296 means the
297 .Ar n Ns -th
298 match, starting at the beginning of the file, of the regular expression
299 .Dq Li .*\[rs]n\&? .
301 All windows always have at least one current substring which is the default
302 address.
303 In sam this is referred to as
304 .Sy dot .
307 multiple
308 .Dq dots
309 (or selections) can exist at the same time.
311 .Ss Simple addresses
313 .Bl -tag -width indent
314 .It Ic # Ns Ar n
315 The empty string after character
316 .Ar n ;
317 .Ic #0
318 is the beginning of the file.
319 .It Ar n
320 Line
321 .Ar n .
322 .It Ic / Ns Ar regexp Ns Ic /
323 .It Ic \&? Ns Ar regexp Ns Ic \&?
324 The substring that matches the regular expression, found by looking
325 towards the end
326 .Pq Ic /
327 or beginning
328 .Pq Ic \&?
329 of the file.
330 The search does not wrap around when hitting the end
331 .Pq start
332 of the file.
333 .It Ic 0
334 The string before the first full line.
335 This is not necessarily the null string; see
336 .Ic +
338 .Ic -
339 below.
340 .It Ic $
341 The null string at the end of the file.
342 .It Ic \&.
343 Dot, the current range.
344 .It Ic ' Ns Ar m
345 The mark
346 .Ar m
347 in the file.
350 .Ss Compound addresses
352 In the following,
353 .Ar a1
355 .Ar a2
356 are addresses.
357 .Bl -tag -width indent
358 .It Ar a1 Ns Ic + Ns Ar a2
359 The address
360 .Ar a2
361 evaluated starting at the end of
362 .Ar a1 .
363 .It Ar a1 Ns Ic - Ns Ar a2
364 The address
365 .Ar a2
366 evaluated looking the reverse direction starting at the beginning of
367 .Ar a1 .
368 .It Ar a1 Ns Ic \&, Ns Ar a2
369 The substring from the beginning of
370 .Ar a1
371 to the end of
372 .Ar a2 .
374 .Ar a1
375 is missing,
376 .Ic 0
377 is substituted.
379 .Ar a2
380 is missing,
381 .Ic $
382 is substituted.
383 .It Ar a1 Ns Ic \&; Ns Ar a2
384 Like
385 .Ar a1 Ns Ic \&, Ns Ar a2
386 but with
387 .Ar a2
388 evaluated at the end of, and range set to,
389 .Ar a1 .
392 The operators
393 .Ic +
395 .Ic -
396 are high precedence, while
397 .Ic \&,
399 .Ic \&;
400 are low precedence.
402 In both
403 .Ic +
405 .Ic -
406 forms, if
407 .Ar a2
408 is a line or character address with a missing number, the number defaults to 1.
410 .Ar a1
411 is missing,
412 .Ic \&.
413 is substituted.
414 If both
415 .Ar a1
417 .Ar a2
418 are present and distinguishable,
419 .Ic +
420 may be elided.
421 .Ar a2
422 may be a regular expression; if it is delimited by
423 .Li \&?
424 characters, the effect of the
425 .Ic +
427 .Ic -
428 is reversed.
431 .Ic %
432 sign is an alias for
433 .Ic \&,
434 and hence
435 .Ic 0,$ .
437 It is an error for a compound address to represent a malformed substring.
439 .Ss Commands
441 In the following, text demarcated by slashes represents text delimited
442 by any printable ASCII character except alphanumerics.
443 Any number of trailing delimiters may be elided, with multiple elisions then
444 representing null strings, but the first delimiter must always be present.
445 In any delimited text, newline may not appear literally;
446 .Li \[rs]n
448 .Li \[rs]t
449 may be typed for newline and tab;
450 .Li \[rs]/
451 quotes the delimiter, here
452 .Li / .
453 An ampersand
454 .Li &
456 .Li \[rs] Ns Ar n ,
457 where
458 .Ar n
459 is a digit (1\(en9) are replaced by the corresponding register.
460 Backslash is otherwise interpreted literally.
462 Most commands may be prefixed with an address to indicate their range of
463 operation.
464 If a command takes an address and none is supplied, a default address is used.
465 In normal mode this equates to the character the selection is currently over.
466 If only one selection exists
467 .Ic x
469 .Ic y
470 default to the whole file
471 .Ic 0,$ .
472 In normal mode the write commands
473 .Ic w
475 .Ic wq
476 always apply to the whole file.
477 Commands are executed once for every selection.
478 In visual mode the commands are applied to every selection
479 as if an implicit
480 .Ic x
481 command, matching the existing selections, was present.
484 In the description,
485 .Dq range
486 is used to represent whatever address is supplied.
488 Many commands create new selections as a side effect when issued from a visual
489 mode.
490 If so, it is always to the “result” of the change: the new text for an
491 insertion, the empty string for a deletion, the command output of a filter etc.
492 If after a successful command execution no selections remain,
493 the editor will switch to normal mode, otherwise it remains in
494 visual mode.
495 This allows
496 .Em interactive
497 refinements of ranges.
499 .\" Many commands set the value of dot as a side effect.
500 .\" If so, it is always to the
501 .\" .Dq result
502 .\" of the change: the empty string for a deletion, the new text for an
503 .\" insertion, etc.
504 .\" .Po
505 .\" but see the
506 .\" .Sy s
507 .\" and
508 .\" .Sy e
509 .\" commands
510 .\" .Pc .
512 .Ss Text commands
514 .Bl -tag -width indent
515 .It Ic a Ns [ Ar count ] Ns / Ns Ar text Ns Ic /
516 Insert the
517 .Ar text
518 .Ar count
519 times into the file after the range.
520 .\" Set dot.
522 May also be written as
523 .Bd -literal -offset indent
525  lines
526  of
527  text
531 .It Ic c No or Ic i
532 Same as
533 .Ic a ,
535 .Ic c
536 replaces the text, while
537 .Ic i
538 inserts
539 .Em before
540 the range.
542 .It Ic d
543 Delete the text in range.
544 .\" Set dot.
547 .Ss Display commands
549 .Bl -tag -width Ds
550 .It Ic p
551 Create a new selection for the range.
554 .Ss I/O commands
556 .Bl -tag -width indent
557 .It Ic e Ns Oo Cm \&! Oc Op Pa file name
558 Replace the file by the contents of the named external file.
559 If no file name is given, reload file from disk.
561 .It Ic r Ar file name
562 Replace the text in the range by the contents of the named external file.
563 .\" Set dot.
565 .It Ic w Ns Oo Cm \&! Oc Op Ar file name
566 Write the range
568 default
569 .Ic 0,$
571 to the named external file.
573 .It Ic wq Ns Oo Cm \&! Oc Op Ar file name
574 Same as
575 .Ic w ,
576 but close file afterwards.
579 If the file name argument is absent from any of these, the current file name is
580 used.
582 .Ic e
583 always sets the file name,
584 .Ic w
585 will do so if the file has no name.
586 Forcing the
587 .Ic e
588 command with
589 .Cm \&!
590 will discard any unsaved changes.
591 Forcing
592 .Ic w
593 will overwrite the file on disk even if it has been externally modified
594 since loading it.
595 Write commands with a non-default addresses and no file name are destructive
596 and need always to be forced.
597 .Bl -tag -width indent
599 .It Ic < Ar shell command
600 Replace the range by the standard output of the shell command.
602 .It Ic > Ar shell command
603 Sends the range to the standard input of the shell command.
605 .It Ic \&| Ar shell command
606 Send the range to the standard input, and replace it by the standard output, of
607 the shell command.
609 .It Ic \&! Ar shell command
610 Run interactive shell command, redirect keyboard input to it.
612 .It Ic cd Ar directory
613 Change working directory.
614 If no directory is specified,
615 .Ev "$HOME"
616 is used.
619 In any of
620 .Ic < ,
621 .Ic > ,
622 .Ic \&| ,
624 .Ic \&! ,
625 if the shell command is omitted, the last shell command
626 .Pq of any type
627 is substituted.
628 Unless the file being edited is unnamed, all these external commands
629 can refer to its absolute path and file name through the
630 .Ev vis_filepath
632 .Ev vis_filename
633 environment variables.
635 .Ss Loops and conditionals
637 .Bl -tag -width indent
638 .It Ic x/ Ns Ar regexp Ns Ic / Op Ar command
639 For each match of the regular expression in the range, run the command with
640 range set to the match.
641 If the regular expression and its slashes are omitted,
642 .Ar "/.*\[rs]n/"
643 is assumed.
644 Null string matches potentially occur before every character of the range and
645 at the end of the range.
648 .Ic \(dq1 Ns \(en Ns Ic \(dq9
650 .Ic \(dq&
651 registers are updated with the (sub) expression matches of the pattern.
653 .It Ic y/ Ns Ar regexp Ns Ic / Op Ar command
654 Like
655 .Ic x ,
656 but run the command for each substring that lies before, between, or after the
657 matches that would be generated by
658 .Ic x .
659 There is no default behavior.
660 Null substrings potentially occur before every character in the range.
662 .It Ic X/ Ns Ar regexp Ns Ic "/" Ar command
663 For each file whose file name matches the regular expression, make that the
664 current file and run the command.
665 If the expression is omitted, the command is run in every file.
667 .It Ic Y/ Ns Ar regexp Ns Ic / Ar command
668 Same as
669 .Ic X ,
670 but for files that do not match the regular expression, and the expression is
671 required.
672 .\" TODO improve markup, use Op macro, make it actually understandable :/
673 .It Ic g Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
674 .It Ic v Ns [ Ar count ] Ns [ Ar /regexp/ ] Ar command
675 If the
676 .Ar count
677 range contains
679 .Ic g
681 or does not contain
683 .Ic v
685 a match for the expression, run command on the range.
688 .Ar count
689 specifier has the following format, where
690 .Ar n
692 .Ar m
693 are integers denoting the ranges.
694 .Bl -tag -width indent
695 .It Ar n Ns Ic \&, Ns Ar m
696 The closed interval from
697 .Ar n
699 .Ar m .
701 .Ar n
702 is missing,
703 .Ic 1
704 is substituted.
706 .Ar m
707 is missing,
708 .Ic ∞
709 is substituted.
710 Negative values are interpreted relative to the last range.
711 .It Ic % Ns Ar n
712 Matches every
713 .Ar n Ns -th
714 range.
719 These may be nested arbitrarily deeply.
720 An empty command in an
721 .Ic x
723 .Ic y
724 defaults to
725 .Ic p .
726 .Ic X ,
727 .Ic Y ,
728 .Ic g
730 .Ic v
731 do not have defaults.
733 .Ss Grouping and multiple changes
735 Commands may be grouped by enclosing them in curly braces.
736 Semantically, the opening brace is like a command: it takes an
737 .Pq optional
738 address and runs each sub-command on the range.
739 Commands within the braces are executed sequentially, but changes
740 made by one command are not visible to other commands.
742 When a command makes a number of changes to a file, as in
743 .Ic x/ Ns Ar re Ns Ic / Ic c/ Ns Ar text Ns Ic / ,
744 the addresses of all changes are computed based on the initial state.
745 If the changes are non-overlapping, they are applied in the specified
746 order.
747 Conflicting changes are rejected.
749 Braces may be nested arbitrarily.
751 .Sh VI(M) KEY BINDINGS
753 In the following sections angle brackets are used to denote special keys.
754 The prefixes
755 .Ic C- ,
756 .Ic S- ,
758 .Ic M-
759 are used to refer to the
760 .Aq Ctrl ,
761 .Aq Shift
763 .Aq Alt
764 modifiers, respectively.
766 All active key bindings can be listed at runtime using the
767 .Ic :help
768 command.
770 .Ss Operators
772 Operators perform a certain operation on a text range indicated by either a
773 motion, a text object or an existing selection.
775 When used in normal mode, the following operators wait for a motion, putting
776 vis into operator pending mode.
777 .Bl -tag -width XXXXXXXXXX -compact
778 .It Ic c
779 change, delete range and enter insert mode
781 .It Ic d
782 delete, cut range to register
784 .It Ic <
785 shift-left, decrease indent
787 .It Ic >
788 shift-right, increase indent
790 .It Ic y
791 yank, copy range to register
794 When used in normal mode, the following actions take effect immediately.
795 .Bl -tag -width XXXXXXXXXX -compact
796 .It Ic =
797 format, filter range through
798 .Xr fmt 1
800 .It Ic gu
801 make lowercase
803 .It Ic gU
804 make uppercase
806 .It Ic g~
807 swap case
809 .It Ic J
810 join lines, insert spaces in between
812 .It Ic gJ
813 join lines remove any delimiting white spaces
815 .It Ic p
816 put register content after cursor
818 .It Ic P
819 put register content before cursor
823 .Ss Motions
825 .\" TODO? more formal definition: pos -> [min(pos, f(pos)), max(pos, f(pos))]
826 Motions take an initial file position and transform it to a destination file
827 position,
828 thereby defining a range.
829 .\" TODO define word/WORD
831 .Bl -tag -width XXXXXXXXXX -compact
832 .It Ic 0
833 start of line
835 .It Ic b
836 previous start of a word
838 .It Ic B
839 previous start of a WORD
841 .It Ic $
842 end of line
844 .It Ic e
845 next end of a word
847 .It Ic E
848 next end of a WORD
850 .It Ic F Ns Aq Ar char
851 to next occurrence of
852 .Aq Ar char
853 to the left
855 .It Ic f Ns Aq Ar char
856 to next occurrence of
857 .Aq Ar char
858 to the right
860 .It Ic ^
861 first non-blank of line
863 .It Ic g0
864 begin of display line
866 .It Ic g$
867 end of display line
869 .It Ic ge
870 previous end of a word
872 .It Ic gE
873 previous end of a WORD
875 .It Ic gg
876 begin of file
878 .It Ic G
879 goto line or end of file
881 .It Ic gj
882 display line down
884 .It Ic gk
885 display line up
887 .It Ic gh
888 codepoint left
890 .It Ic gl
891 codepoint right
893 .It Ic gH
894 byte left
896 .It Ic gL
897 byte right
898 .It Ic g_
899 last non-blank of line
901 .It Ic gm
902 middle of display line
904 .It Ic g\&|
905 goto column
907 .It Ic h
908 char left
910 .It Ic H
911 goto top/home line of window
913 .It Ic j
914 line down
916 .It Ic k
917 line up
919 .It Ic l
920 char right
922 .It Ic L
923 goto bottom/last line of window
925 .It Ic %
926 match bracket, quote or backtick
928 .It Ic }
929 next paragraph
931 .It Ic \&)
932 next sentence
934 .It Ic N
935 repeat last search backwards
937 .It Ic n
938 repeat last search forward
940 .It Ic [{
941 previous start of block
943 .It Ic ]}
944 next start of block
946 .It Ic [(
947 previous start of parentheses pair
949 .It Ic ])
950 next start of parentheses pair
952 .It Ic {
953 previous paragraph
955 .It Ic \&(
956 previous sentence
958 .It Ic \&;
959 repeat last to/till movement
961 .It Ic \&,
962 repeat last to/till movement but in opposite direction
964 .It Ic #
965 search word under selection backwards
967 .It Ic *
968 search word under selection forwards
970 .It Ic T Ns Aq Ar char
971 till before next occurrence of
972 .Aq Ar char
973 to the left
975 .It Ic t Ns Aq Ar char
976 till before next occurrence of
977 .Aq Ar char
978 to the right
980 .It Ic \&? Ns Ar pattern
981 to next match of
982 .Ar pattern
983 in backward direction
985 .It Ic / Ns Ar pattern
986 to next match of
987 .Ar pattern
988 in forward direction
990 .It Ic w
991 next start of a word
993 .It Ic W
994 next start of a WORD
997 .Ss Text objects
999 .\" TODO? more formal definition: text-object: pos -> [a, b]
1000 Text objects take an initial file position and transform it to a range
1001 where the former does not necessarily have to be contained in the latter.
1003 All of the following text objects are implemented in an inner variant
1004 (prefixed with
1005 .Ic i )
1006 where the surrounding white space or delimiting characters are not part
1007 of the resulting range and a normal variant (prefixed with
1008 .Ic a )
1009 where they are.
1011 .Bl -tag -width XXXXXXXXXX -compact
1013 .It Ic w
1014 word
1016 .It Ic W
1017 WORD
1019 .It Ic s
1020 sentence
1022 .It Ic p
1023 paragraph
1025 .It Ic [, ], (, ), {, }, <, >, \(dq, ', `
1026 block enclosed by these symbols
1029 Further available text objects include:
1030 .Bl -tag -width XXXXXXXXXX -compact
1032 .It Ic gn
1033 matches the last used search term in forward direction
1035 .It Ic gN
1036 matches the last used search term in backward direction
1038 .It Ic al
1039 current line
1041 .It Ic il
1042 current line without leading and trailing white spaces
1045 .Ss Multiple Selections
1048 supports multiple selections with immediate visual feedback.
1049 There always exists one primary selection located within the current
1050 view port.
1051 Additional selections can be created as needed.
1052 If more than one selection exists, the primary one is styled differently.
1054 To manipulate selections use in normal mode:
1056 .Bl -tag -width XXXXXXXXXX -compact
1057 .It Aq Ic C-k
1058 create count new selections on the lines above
1060 .It Aq Ic C-M-k
1061 create count new selections on the lines above the first selection
1063 .It Aq Ic C-j
1064 create count new selections on the lines below
1066 .It Aq Ic C-M-j
1067 create count new selections on the lines below the last selection
1069 .It Aq Ic C-p
1070 remove primary selection
1072 .It Aq Ic C-n
1073 select word the selection is currently over, switch to visual mode
1075 .It Aq Ic C-u
1076 make the count previous selection primary
1078 .It Aq Ic C-d
1079 make the count next selection primary
1081 .It Aq Ic C-c
1082 remove the count selection column
1084 .It Aq Ic C-l
1085 remove all but the count selection column
1087 .It Aq Ic Tab
1088 try to align all selections on the same column
1090 .It Aq Ic Escape
1091 dispose all but the primary selection
1094 The visual modes were enhanced to recognize:
1096 .Bl -tag -width XXXXXXXXXX -compact
1097 .It Ic I
1098 create a selection at the start of every selected line
1100 .It Ic A
1101 create a selection at the end of every selected line
1103 .It Aq Ic Tab
1104 left align selections by inserting spaces
1106 .It Aq Ic S-Tab
1107 right align selections by inserting spaces
1109 .It Aq Ic C-a
1110 create new selections everywhere matching current word or selection
1112 .It Aq Ic C-n
1113 create new selection and select next word matching current selection
1115 .It Aq Ic C-x
1116 clear (skip) current selection, but select next matching word
1118 .It Aq Ic C-p
1119 remove primary selection
1121 .It Aq Ic C-u
1122 .It Aq Ic C-k
1123 make the count previous selection primary
1125 .It Aq Ic C-d
1126 .It Aq Ic C-j
1127 make the count next selection primary
1129 .It Aq Ic C-c
1130 remove the count selection column
1132 .It Aq Ic C-l
1133 remove all but the count selection column
1135 .It Ic +
1136 rotate selections rightwards count times
1138 .It Ic -
1139 rotate selections leftwards count times
1141 .It Ic _
1142 trim selections, remove leading and trailing white space
1144 .It Ic o
1145 flip selection direction, swap cursor and anchor
1147 .It Aq Ic Escape
1148 clear all selections, switch to normal mode
1151 In insert and replace mode:
1153 .Bl -tag -width XXXXXXXXXX -compact
1154 .It Aq Ic S-Tab
1155 align all selections by inserting spaces
1158 Selections can be manipulated using set operations.
1159 The first operand is the currently active selections while the second
1160 can be specified as a mark.
1162 .Bl -tag -width XXXXXXXXXX -compact
1163 .It Ic \&|
1164 set union
1165 .It Ic &
1166 set intersection
1167 .It Ic \e
1168 set minus
1169 .It Ic ~
1170 set complement
1173 .Sh VI(M) COMMANDS
1175 Any unique prefix can be used to abbreviate a command.
1177 .Ss File and Window management
1179 A file must be opened in at least one window.
1180 If the last window displaying a certain file is closed all unsaved changes are
1181 discarded.
1182 Windows are equally sized and can be displayed in either horizontal or vertical
1183 fashion.
1185 .Aq Ic C-w
1186 .Ic h ,
1187 .Aq Ic C-w
1188 .Ic j ,
1189 .Aq Ic C-w
1190 .Ic k
1192 .Aq Ic C-w
1193 .Ic l
1194 key mappings can be used to switch between windows.
1195 .Bl -tag -width indent
1196 .It Ic :new
1197 open an empty window, arrange horizontally
1199 .It Ic :vnew
1200 open an empty window, arrange vertically
1202 .It Ic :open Ns Oo Cm \&! Oc Op Ar file name
1203 open a new window, displaying file name if given
1205 .It Ic :split Op Ar file name
1206 split window horizontally
1208 .It Ic :vsplit Op Ar file name
1209 split window vertically
1211 .It Ic :q Ns Oo Cm \&! Oc Op Ar exit code
1212 close currently focused window
1214 .It Ic :qall Ns Oo Cm \&! Oc Op Ar exit code
1215 close all windows, terminate editor with exit code (defaults to 0)
1218 Commands taking a file name will invoke the
1219 .Xr vis-open 1
1220 utility, if given a file pattern or directory.
1222 .Ss Runtime key mappings
1225 supports global as well as window local run time key mappings which are
1226 always evaluated recursively.
1228 .Bl -tag -width indent
1229 .It Ic :map Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
1230 add a global key mapping
1232 .It Ic :map-window Ns Oo Cm \&! Oc Ar mode Ar lhs Ar rhs
1233 add a window local key mapping
1235 .It Ic :unmap Ar mode Ar lhs
1236 remove a global key mapping
1238 .It Ic :unmap-window Ar mode Ar lhs
1239 remove a window local key mapping
1242 In the above
1243 .Ar mode
1244 refers to one of
1245 .Ql normal ,
1246 .Ql insert ,
1247 .Ql replace ,
1248 .Ql visual ,
1249 .Ql visual-line
1251 .Ql operator-pending ;
1252 .Ar lhs
1253 refers to the key to map and
1254 .Ar rhs
1255 is a key action or alias.
1256 An existing mapping may be overridden by forcing the map command by specifying
1257 .Cm \&! .
1259 Because key mappings are always recursive, doing something like:
1261 .Dl :map! normal j 2j
1263 will not work because it would enter an endless loop.
1264 Instead,
1266 uses pseudo keys referred to as key actions which can be used to invoke
1267 a set of available editor functions.
1268 .Ic :help
1269 lists all currently active key bindings as well as all available symbolic
1270 keys.
1272 .Ss Keyboard Layout Specific Mappings
1274 In order to facilitate usage of non-latin keyboard layouts,
1276 allows one to map locale specific keys to their latin equivalents by means of the
1278 .D1 Ic :langmap Ar locale-keys Ar latin-keys
1280 command.
1281 As an example, the following maps the movement keys in Russian layout:
1283 .Dl :langmap ролд hjkl
1285 If the key sequences have not the same length, the remainder of the longer
1286 sequence will be discarded.
1288 The defined mappings take effect
1289 in all non-input modes, i.e. everywhere except in insert and replace mode.
1291 .Ss Undo/Redo
1293 .Bl -tag -width indent
1294 .It Ic :earlier Op Ar count
1295 revert to older text state
1296 .It Ic :later Op Ar count
1297 revert to newer text state
1300 If count is suffixed by either of
1301 .Sy d
1302 .Pq days ,
1303 .Sy h
1304 .Pq hours ,
1305 .Sy m
1306 .Pq minutes
1308 .Sy s
1309 .Pq seconds
1310 it is interpreted as an offset from the current system time and the closest
1311 available text state is restored.
1313 .Sh SET OPTIONS
1315 There are a small number of options that may be set
1316 .Pq or unset
1317 to change the editor's behavior using the
1318 .Ic :set
1319 command.
1320 This section describes the options, their abbreviations and their
1321 default values.
1322 Boolean options can be toggled by appending
1323 .Sy \&!
1324 to the option name.
1326 In each entry below, the first part of the tag line is the full name
1327 of the option, followed by any equivalent abbreviations.
1328 The part in square brackets is the default value of the option.
1329 .Bl -tag -width indent
1330 .It Ic shell Op Dq Pa /bin/sh
1331 User shell to use for external commands, overrides
1332 .Ev SHELL
1333 and shell field of password database
1334 .Pa /etc/passwd
1336 .It Ic escdelay Op Ar 50
1337 Milliseconds to wait before deciding whether an escape sequence should
1338 be treated as an
1339 .Aq Cm Escape
1340 key.
1342 .It Ic tabwidth , Ic tw Op Ar 8
1343 Display width of a tab and number of spaces to use if
1344 .Ic expandtab
1345 is enabled.
1347 .It Ic autoindent , Cm ai Op Cm off
1348 Automatically indent new lines by copying white space from previous line.
1350 .It Ic expandtab , Ic et Op Cm off
1351 Whether
1352 .Aq Ic Tab
1353 should be expanded to
1354 .Ic tabwidth
1355 spaces.
1357 .It Ic number , Ic nu Op Cm off
1358 Display absolute line numbers.
1360 .It Ic relativenumbers , Ic rnu Op Cm off
1361 Display relative line numbers.
1363 .It Ic cursorline , Ic cul Op Cm off
1364 Highlight line primary cursor resides on.
1366 .It Ic colorcolumn , Ic cc Op Ar 0
1367 Highlight a fixed column.
1369 .It Ic horizon Op Ar 32768
1370 How many bytes back the lexer will look to synchronize parsing.
1372 .It Ic redrawtime Op Ar 1.0
1373 Maximum time (in seconds) to wait for syntax highlighting before aborting it.
1375 .It Ic theme Op Do default-16 Dc or Do default-256 Dc
1376 Color theme to use, name without file extension.
1377 Loaded from a
1378 .Pa themes/
1379 sub directory of the paths listed in the
1380 .Sx FILES
1381 section.
1383 .It Cm syntax Op Cm off
1384 Syntax highlighting lexer to use, name without file extension.
1386 .It Cm show-tabs Op Cm off
1387 Whether to display replacement symbol instead of tabs.
1389 .It Cm show-newlines Op Cm off
1390 Whether to display replacement symbol instead of newlines.
1392 .It Cm show-spaces Op Cm off
1393 Whether to display replacement symbol instead of blank cells.
1395 .It Cm show-eof Op Cm on
1396 Whether to display replacement symbol for lines after the end of the file.
1398 .It Cm savemethod Op Ar auto
1399 How the current file should be saved,
1400 .Ar atomic
1401 which uses
1402 .Xr rename 2
1403 to atomically replace the file,
1404 .Ar inplace
1405 which truncates the file and then rewrites it or
1406 .Ar auto
1407 which tries the former before falling back to the latter.
1408 The rename method fails for symlinks, hardlinks, in case of insufficient
1409 directory permissions or when either the file owner, group, POSIX ACL or
1410 SELinux labels can not be restored.
1411 .It Cm loadmethod Op Ar auto
1412 How existing files should be loaded,
1413 .Ar read
1414 which copies the file content to an independent in-memory buffer,
1415 .Ar mmap
1416 which memory maps the file from disk and uses OS capabilities as
1417 caching layer or
1418 .Ar auto
1419 which tries the former for files smaller than 8Mb and the latter for
1420 lager ones.
1421 WARNING: modifying a memory mapped file in-place will cause data loss.
1422 .It Ic layout Op Do v Dc or Do h Dc
1423 Whether to use vertical or horizontal layout.
1424 .It Cm ignorecase , Cm ic Op Cm off
1425 Whether to ignore case when searching.
1428 .Sh COMMAND and SEARCH PROMPT
1430 The command and search prompt as opened by
1431 .Ic \&: ,
1432 .Ic / ,
1434 .Ic \&?
1435 is implemented as a single line height window, displaying a regular file
1436 whose editing starts in insert mode.
1437 .Aq Ic Escape
1438 switches to normal mode, a second
1439 .Aq Ic Escape
1440 cancels the prompt.
1441 .Aq Ic Up
1442 enlarges the window, giving access to the command history.
1443 .Aq Ic C-v
1444 .Aq Ic Enter
1445 inserts a literal new line thus enabling multiline commands.
1446 .Aq Ic Enter
1447 executes the visual selection if present, or else everything in the
1448 region spawned by the selection position and the delimiting prompt symbols
1449 at the start of adjacent lines.
1451 .Sh CONFIGURATION
1454 uses Lua for configuration and scripting purposes.
1455 During startup
1456 .Pa visrc.lua
1457 (see the
1458 .Sx FILES
1459 section) is sourced which can be used to set personal configuration options.
1460 As an example the following will enable the display of line numbers:
1462 .Dl vis:command('set number')
1464 .Sh ENVIRONMENT
1466 .Bl -tag -width indent
1467 .It Ev VIS_PATH
1468 The default path to use to load Lua support files.
1469 .It Ev HOME
1470 The home directory used for the
1471 .Ic cd
1472 command if no argument is given.
1473 .It Ev TERM
1474 The terminal type to use to initialize the curses interface, defaults to
1475 .Sy xterm
1476 if unset.
1477 .It Ev SHELL
1478 The command shell to use for I/O related commands like
1479 .Ic \&! ,
1480 .Ic > ,
1481 .Ic <
1483 .Ic \&| .
1484 .It Ev XDG_CONFIG_HOME
1485 The configuration directory to use, defaults to
1486 .Pa $HOME/.config
1487 if unset.
1490 .Sh ASYNCHRONOUS EVENTS
1492 .Bl -tag -width indent
1493 .It Dv SIGSTOP
1494 Suspend editor.
1495 .It Dv SIGCONT
1496 Resume editor.
1497 .It Dv SIGBUS
1499 .Xr mmap 2
1500 ed file got truncated, unsaved file contents will be lost.
1501 .It Dv SIGHUP
1502 .It Dv SIGTERM
1503 Restore initial terminal state.
1504 Unsaved file contents will be lost.
1505 .It Dv SIGINT
1506 When an interrupt occurs while an external command is being run it is terminated.
1507 .It Dv SIGWINCH
1508 The screen is resized.
1511 .Sh FILES
1513 Upon startup
1515 will source the first
1516 .Pa visrc.lua
1517 configuration file found from these locations.
1518 All actively used paths can be listed at runtime using the
1519 .Cm :help
1520 command.
1521 .Bl -bullet
1523 .Pa $VIS_PATH
1525 The location of the
1527 binary (on systems where
1528 .Pa /proc/self/exe
1529 is available).
1531 .Pa $XDG_CONFIG_HOME/vis
1532 where
1533 .Ev XDG_CONFIG_HOME
1534 refers to
1535 .Pa $HOME/.config
1536 if unset.
1539 .Pa /etc/vis
1540 for a system-wide configuration provided by administrator.
1542 .Pa /usr/local/share/vis
1544 .Pa /usr/share/vis
1545 depending on the build configuration.
1548 When creating a new
1549 .Pa visrc.lua
1550 be sure to copy the structure from here.
1553 .Sh EXIT STATUS
1555 .Ex -std
1557 .Sh EXAMPLES
1561 as an interactive filter.
1563 .Dl $ { echo Pick your number; seq 1 10; } | vis - > choice
1565 Use the
1566 .Xr vis-open 1
1567 based file browser to list all C language source files:
1569 .Dl :e *.c
1571 Spawn background process and pipe range to its standard input:
1573 .Dl :> { plumber <&3 3<&- & } 3<&0 1>&- 2>&-
1575 .Sh SEE ALSO
1577 .Xr sam 1 ,
1578 .Xr vi 1 ,
1579 .Xr vis-clipboard 1 ,
1580 .Xr vis-complete 1 ,
1581 .Xr vis-digraph 1 ,
1582 .Xr vis-menu 1 ,
1583 .Xr vis-open 1
1585 .Lk http://doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pdf "A Tutorial for the Sam Command Language"
1587 .An Rob Pike
1589 .Lk http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ "The Text Editor sam"
1591 .An Rob Pike
1593 .Lk http://man.cat-v.org/plan_9/1/sam "Plan 9 manual page for sam(1)"
1595 .Lk http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf "Structural Regular Expressions"
1597 .An Rob Pike
1599 .Lk http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html "vi - screen-oriented (visual) display editor"
1600 .St -p1003.1
1602 .Sh STANDARDS
1605 does not strive to be
1606 .St -p1003.1
1607 compatible, but shares obvious similarities with the
1608 .Nm vi
1609 utility.
1611 .\" .Sh HISTORY
1612 .\" TODO something about vi(m) and sam history
1614 .Sh AUTHORS
1617 is written by
1618 .An Marc André Tanner Aq mat at brain-dump.org
1620 .Sh BUGS
1622 On some systems there already exists a
1624 binary, thus causing a name conflict.