8 .Nd a highly efficient text editor
14 .Op Cm + Ns Ar command
21 is a highly efficient screen-oriented text editor combining the strengths of
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
34 Print version information and exit.
35 .It Cm + Ns Ar command
41 Denotes the end of the options.
42 Arguments after this will be handled as a
50 to read from standard input in which case
52 will write to standard output, thereby enabling usage as an interactive filter.
54 If standard input is redirected and all input is consumed,
58 to gather further commands.
59 Failure to do so results in program termination.
64 uses selections as core editing primitives.
65 A selection is a non-empty, directed range with two endpoints called
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
74 There always exists a primary selection which remains visible
75 (i.e. changes to its position will adjust the viewport).
86 .Sq operator pending ,
91 (in both line and character wise variants) mode.
92 The visual block and ex modes are deliberately not implemented,
95 has built in support for multiple selections and an
97 variant of the structural regular expression based command language of
100 In normal mode all selections are non-anchored and reduced to a single character.
105 uses an undo tree to keep track of text revisions.
112 commands can be used to traverse the tree along the main branch.
116 traverse the history in chronological order.
121 commands provide means to restore the text to an arbitrary state.
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.
134 .Ic ' Ns Ar a Ns Ic m
138 .Ic ' Ns Ar a Ns Ic M
142 .Bl -tag -width indent
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.
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
164 save currently active selections
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
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
183 yank register, most recently yanked range
184 .It Ic \(dq1 Ns \(en Ns Ic \(dq9
186 sub expression matches of most recent
192 search register, most recently used search pattern
194 command register, most recently executed command
198 register, ignore content is always empty
200 selection number (readonly)
203 If no explicit register is specified the default register is used.
207 The general purpose registers
208 .Ic \(dqa Ns \(en Ns Ic \(dqz
209 can be used to record macros.
211 .Ic \(dqA Ns \(en Ns Ic \(dqZ
212 to append to an existing macro.
218 refers to the most recently recorded macro.
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
235 If you wish to edit files with legacy encodings or non-Unix line endings,
240 to convert them as needed.
242 can optionally be expanded to a configurable number of spaces (see
243 .Sx "SET OPTIONS" ) .
247 The mouse is currently not used at all.
252 supports an interactive variant of the structural regular expression based
253 command language introduced by
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
268 match the beginning / end of the range they are applied to.
273 may be used to refer to newlines and tabs,
277 atom matches any character except newline.
278 The empty regular expression stands for the last complete expression
283 An address identifies a substring (or range) in a file.
289 means the null string after the
291 character in the file, with 1 the first character in the file.
298 match, starting at the beginning of the file, of the regular expression
301 All windows always have at least one current substring which is the default
303 In sam this is referred to as
309 (or selections) can exist at the same time.
313 .Bl -tag -width indent
315 The empty string after character
318 is the beginning of the file.
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
330 The search does not wrap around when hitting the end
334 The string before the first full line.
335 This is not necessarily the null string; see
341 The null string at the end of the file.
343 Dot, the current range.
350 .Ss Compound addresses
357 .Bl -tag -width indent
358 .It Ar a1 Ns Ic + Ns Ar a2
361 evaluated starting at the end of
363 .It Ar a1 Ns Ic - Ns Ar a2
366 evaluated looking the reverse direction starting at the beginning of
368 .It Ar a1 Ns Ic \&, Ns Ar a2
369 The substring from the beginning of
383 .It Ar a1 Ns Ic \&; Ns Ar a2
385 .Ar a1 Ns Ic \&, Ns Ar a2
388 evaluated at the end of, and range set to,
396 are high precedence, while
408 is a line or character address with a missing number, the number defaults to 1.
418 are present and distinguishable,
422 may be a regular expression; if it is delimited by
424 characters, the effect of the
437 It is an error for a compound address to represent a malformed substring.
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;
449 may be typed for newline and tab;
451 quotes the delimiter, here
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
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
470 default to the whole file
472 In normal mode the write commands
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
481 command, matching the existing selections, was present.
486 is used to represent whatever address is supplied.
488 Many commands create new selections as a side effect when issued from a visual
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
497 refinements of ranges.
499 .\" Many commands set the value of dot as a side effect.
500 .\" If so, it is always to the
502 .\" of the change: the empty string for a deletion, the new text for an
514 .Bl -tag -width indent
515 .It Ic a Ns [ Ar count ] Ns / Ns Ar text Ns Ic /
519 times into the file after the range.
522 May also be written as
523 .Bd -literal -offset indent
536 replaces the text, while
543 Delete the text in range.
551 Create a new selection for the range.
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.
565 .It Ic w Ns Oo Cm \&! Oc Op Ar file name
571 to the named external file.
573 .It Ic wq Ns Oo Cm \&! Oc Op Ar file name
576 but close file afterwards.
579 If the file name argument is absent from any of these, the current file name is
583 always sets the file name,
585 will do so if the file has no name.
590 will discard any unsaved changes.
593 will overwrite the file on disk even if it has been externally modified
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
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,
625 if the shell command is omitted, the last shell command
628 Unless the file being edited is unnamed, all these external commands
629 can refer to its absolute path and file name through the
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,
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
651 registers are updated with the (sub) expression matches of the pattern.
653 .It Ic y/ Ns Ar regexp Ns Ic / Op Ar command
656 but run the command for each substring that lies before, between, or after the
657 matches that would be generated by
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
670 but for files that do not match the regular expression, and the expression is
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
685 a match for the expression, run command on the range.
689 specifier has the following format, where
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
710 Negative values are interpreted relative to the last range.
719 These may be nested arbitrarily deeply.
720 An empty command in an
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
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
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.
759 are used to refer to the
764 modifiers, respectively.
766 All active key bindings can be listed at runtime using the
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
779 change, delete range and enter insert mode
782 delete, cut range to register
785 shift-left, decrease indent
788 shift-right, increase indent
791 yank, copy range to register
794 When used in normal mode, the following actions take effect immediately.
795 .Bl -tag -width XXXXXXXXXX -compact
797 format, filter range through
810 join lines, insert spaces in between
813 join lines remove any delimiting white spaces
816 put register content after cursor
819 put register content before cursor
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
828 thereby defining a range.
829 .\" TODO define word/WORD
831 .Bl -tag -width XXXXXXXXXX -compact
836 previous start of a word
839 previous start of a WORD
850 .It Ic F Ns Aq Ar char
851 to next occurrence of
855 .It Ic f Ns Aq Ar char
856 to next occurrence of
861 first non-blank of line
864 begin of display line
870 previous end of a word
873 previous end of a WORD
879 goto line or end of file
899 last non-blank of line
902 middle of display line
911 goto top/home line of window
923 goto bottom/last line of window
926 match bracket, quote or backtick
935 repeat last search backwards
938 repeat last search forward
941 previous start of block
947 previous start of parentheses pair
950 next start of parentheses pair
959 repeat last to/till movement
962 repeat last to/till movement but in opposite direction
965 search word under selection backwards
968 search word under selection forwards
970 .It Ic T Ns Aq Ar char
971 till before next occurrence of
975 .It Ic t Ns Aq Ar char
976 till before next occurrence of
980 .It Ic \&? Ns Ar pattern
983 in backward direction
985 .It Ic / Ns Ar pattern
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
1006 where the surrounding white space or delimiting characters are not part
1007 of the resulting range and a normal variant (prefixed with
1011 .Bl -tag -width XXXXXXXXXX -compact
1025 .It Ic [, ], (, ), {, }, <, >, \(dq, ', `
1026 block enclosed by these symbols
1029 Further available text objects include:
1030 .Bl -tag -width XXXXXXXXXX -compact
1033 matches the last used search term in forward direction
1036 matches the last used search term in backward direction
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
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
1058 create count new selections on the lines above
1061 create count new selections on the lines above the first selection
1064 create count new selections on the lines below
1067 create count new selections on the lines below the last selection
1070 remove primary selection
1073 select word the selection is currently over, switch to visual mode
1076 make the count previous selection primary
1079 make the count next selection primary
1082 remove the count selection column
1085 remove all but the count selection column
1088 try to align all selections on the same column
1091 dispose all but the primary selection
1094 The visual modes were enhanced to recognize:
1096 .Bl -tag -width XXXXXXXXXX -compact
1098 create a selection at the start of every selected line
1101 create a selection at the end of every selected line
1104 left align selections by inserting spaces
1107 right align selections by inserting spaces
1110 create new selections everywhere matching current word or selection
1113 create new selection and select next word matching current selection
1116 clear (skip) current selection, but select next matching word
1119 remove primary selection
1123 make the count previous selection primary
1127 make the count next selection primary
1130 remove the count selection column
1133 remove all but the count selection column
1136 rotate selections rightwards count times
1139 rotate selections leftwards count times
1142 trim selections, remove leading and trailing white space
1145 flip selection direction, swap cursor and anchor
1148 clear all selections, switch to normal mode
1151 In insert and replace mode:
1153 .Bl -tag -width XXXXXXXXXX -compact
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
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
1182 Windows are equally sized and can be displayed in either horizontal or vertical
1194 key mappings can be used to switch between windows.
1195 .Bl -tag -width indent
1197 open an empty window, arrange horizontally
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
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
1251 .Ql operator-pending ;
1253 refers to the key to map and
1255 is a key action or alias.
1256 An existing mapping may be overridden by forcing the map command by specifying
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.
1266 uses pseudo keys referred to as key actions which can be used to invoke
1267 a set of available editor functions.
1269 lists all currently active key bindings as well as all available symbolic
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
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.
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
1310 it is interpreted as an offset from the current system time and the closest
1311 available text state is restored.
1315 There are a small number of options that may be set
1317 to change the editor's behavior using the
1320 This section describes the options, their abbreviations and their
1322 Boolean options can be toggled by appending
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
1333 and shell field of password database
1336 .It Ic escdelay Op Ar 50
1337 Milliseconds to wait before deciding whether an escape sequence should
1342 .It Ic tabwidth , Ic tw Op Ar 8
1343 Display width of a tab and number of spaces to use if
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
1353 should be expanded to
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.
1379 sub directory of the paths listed in the
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,
1403 to atomically replace the file,
1405 which truncates the file and then rewrites it or
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,
1414 which copies the file content to an independent in-memory buffer,
1416 which memory maps the file from disk and uses OS capabilities as
1419 which tries the former for files smaller than 8Mb and the latter for
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
1435 is implemented as a single line height window, displaying a regular file
1436 whose editing starts in insert mode.
1438 switches to normal mode, a second
1442 enlarges the window, giving access to the command history.
1445 inserts a literal new line thus enabling multiline commands.
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.
1454 uses Lua for configuration and scripting purposes.
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')
1466 .Bl -tag -width indent
1468 The default path to use to load Lua support files.
1470 The home directory used for the
1472 command if no argument is given.
1474 The terminal type to use to initialize the curses interface, defaults to
1478 The command shell to use for I/O related commands like
1484 .It Ev XDG_CONFIG_HOME
1485 The configuration directory to use, defaults to
1490 .Sh ASYNCHRONOUS EVENTS
1492 .Bl -tag -width indent
1500 ed file got truncated, unsaved file contents will be lost.
1503 Restore initial terminal state.
1504 Unsaved file contents will be lost.
1506 When an interrupt occurs while an external command is being run it is terminated.
1508 The screen is resized.
1515 will source the first
1517 configuration file found from these locations.
1518 All actively used paths can be listed at runtime using the
1527 binary (on systems where
1531 .Pa $XDG_CONFIG_HOME/vis
1540 for a system-wide configuration provided by administrator.
1542 .Pa /usr/local/share/vis
1545 depending on the build configuration.
1550 be sure to copy the structure from here.
1561 as an interactive filter.
1563 .Dl $ { echo Pick your number; seq 1 10; } | vis - > choice
1567 based file browser to list all C language source files:
1571 Spawn background process and pipe range to its standard input:
1573 .Dl :> { plumber <&3 3<&- & } 3<&0 1>&- 2>&-
1579 .Xr vis-clipboard 1 ,
1580 .Xr vis-complete 1 ,
1585 .Lk http://doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pdf "A Tutorial for the Sam Command Language"
1589 .Lk http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ "The Text Editor sam"
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"
1599 .Lk http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html "vi - screen-oriented (visual) display editor"
1605 does not strive to be
1607 compatible, but shares obvious similarities with the
1612 .\" TODO something about vi(m) and sam history
1618 .An Marc André Tanner Aq mat at brain-dump.org
1622 On some systems there already exists a
1624 binary, thus causing a name conflict.