Scroll to navigation

VIS(1) General Commands Manual VIS(1)

NAME

visa highly efficient text editor

SYNOPSIS

vis [-v] [+command] [--] [files ...]

DESCRIPTION

vis is a highly efficient screen-oriented text editor combining the strengths of both vi(m) and sam. This manual page is intended for users already familiar with vi/sam. Anyone else should almost certainly read a good tutorial on either editor before this manual page. The following options are available:

Print version information and exit.
command
Execute command after loading file.
--
Denotes the end of the options. Arguments after this will be handled as a file name.

The special file - instructs vis to read from standard input in which case :wq will write to standard output, thereby enabling usage as an interactive filter.

If standard input is redirected and all input is consumed, vis will open /dev/tty to gather further commands. Failure to do so results in program termination.

Selections

vis uses selections as core editing primitives. A selection is a non-empty, directed range with two endpoints called and . A selection can be anchored in which case the anchor remains fixed while only the position of the cursor is adjusted. For non-anchored selections both endpoints are updated. A singleton selection covers one character on which both cursor and anchor reside. There always exists a primary selection which remains visible (i.e. changes to its position will adjust the viewport).

Modes

vis employs the same editing approach as vi. It supports a ‘normal’, ‘operator pending’, ‘insert’, ‘replace’ and ‘visual’ (in both line and character wise variants) mode. The visual block and ex modes are deliberately not implemented, instead vis has built in support for multiple selections and an interactive variant of the structural regular expression based command language of sam.

In normal mode all selections are non-anchored and reduced to a single character.

Undo/Redo

vis uses an undo tree to keep track of text revisions. The u (undo) and ⟨C-r⟩ (redo) commands can be used to traverse the tree along the main branch. g+ and g- traverse the history in chronological order. The :earlier and :later commands provide means to restore the text to an arbitrary state.

Marks

A mark associates a symbolic name to a set of selections. A stored selection becomes invalid when its delimiting boundaries change in the underlying buffer. If said changes are later undone the mark becomes valid again. m sets a mark, M restores it. For example, 'am sets the mark a while 'aM restores it. Use of m or M without specifying a mark uses the default mark.

Available marks are:

default mark
active selections when leaving visual mode
'z
general purpose marks

No marks across files are supported. Marks are not preserved over editing sessions.

Jump list

A per window, fixed sized file local jump list exists which stores marks (i.e. set of selections).

jump backward
jump forward
save currently active selections

Registers

Registers are named lists of text. Uninitialized register slots default to the empty string. Available registers are:

""
default register
"a"z
general purpose registers
"A"Z
append to corresponding general purpose register
"*, "+
system clipboard integration via shell script vis-clipboard(1)
"0
yank register, most recently yanked range
"1"9
 
"&
sub expression matches of most recent x or y command
"/
search register, most recently used search pattern
":
command register, most recently executed command
"_
black hole (/dev/null) register, ignore content is always empty
"#
selection number (readonly)

If no explicit register is specified the default register is used.

Macros

The general purpose registers "a"z can be used to record macros. Use one of "A"Z to append to an existing macro. q starts a recording, @ plays it back. @@ refers to the most recently recorded macro. @: repeats the last :-command. @/ is equivalent to n in normal mode. These operations always use the first register slot.

Encoding, Tab and Newline handling

vis always assumes the input file to be UTF-8 encoded with \n line endings. If you wish to edit files with legacy encodings or non-Unix line endings, use iconv(1) and dos2unix(1) to convert them as needed. ⟨Tab⟩ can optionally be expanded to a configurable number of spaces (see SET OPTIONS).

Mouse support

The mouse is currently not used at all.

SAM COMMANDS

vis supports an interactive variant of the structural regular expression based command language introduced by sam(1).

Regular expressions

vis currently defers regular expression matching to the underlying C library. It uses what POSIX refers to as “Extended Regular Expressions” as described in regex(7). The anchors ^ and $ match the beginning / end of the range they are applied to. Additionally \n and \t may be used to refer to newlines and tabs, respectively. The . atom matches any character except newline. The empty regular expression stands for the last complete expression encountered.

Addresses

An address identifies a substring (or range) in a file. In the following “character n” means the null string after the n-th character in the file, with 1 the first character in the file. “Line n” means the n-th match, starting at the beginning of the file, of the regular expression “.*\n?”.

All windows always have at least one current substring which is the default address. In sam this is referred to as . In vis multiple “dots” (or selections) can exist at the same time.

Simple addresses

n
The empty string after character n; #0 is the beginning of the file.
n
Line n.
regexp/
 
regexp?
The substring that matches the regular expression, found by looking towards the end (/) or beginning (?) of the file. The search does not wrap around when hitting the end (start) of the file.
The string before the first full line. This is not necessarily the null string; see + and - below.
The null string at the end of the file.
Dot, the current range.
m
The mark m in the file.

Compound addresses

In the following, a1 and a2 are addresses.

a1+a2
The address a2 evaluated starting at the end of a1.
a1-a2
The address a2 evaluated looking the reverse direction starting at the beginning of a1.
a1,a2
The substring from the beginning of a1 to the end of a2. If a1 is missing, 0 is substituted. If a2 is missing, $ is substituted.
a1;a2
Like a1,a2 but with a2 evaluated at the end of, and range set to, a1.

The operators + and - are high precedence, while , and ; are low precedence.

In both + and - forms, if a2 is a line or character address with a missing number, the number defaults to 1. If a1 is missing, . is substituted. If both a1 and a2 are present and distinguishable, + may be elided. a2 may be a regular expression; if it is delimited by ? characters, the effect of the + or - is reversed. The % sign is an alias for , and hence 0,$. It is an error for a compound address to represent a malformed substring.

Commands

In the following, text demarcated by slashes represents text delimited by any printable ASCII character except alphanumerics. Any number of trailing delimiters may be elided, with multiple elisions then representing null strings, but the first delimiter must always be present. In any delimited text, newline may not appear literally; \n and \t may be typed for newline and tab; \/ quotes the delimiter, here /. An ampersand & and \n, where n is a digit (1–9) are replaced by the corresponding register. Backslash is otherwise interpreted literally.

Most commands may be prefixed with an address to indicate their range of operation. If a command takes an address and none is supplied, a default address is used. In normal mode this equates to the character the selection is currently over. If only one selection exists x and y default to the whole file 0,$. In normal mode the write commands w and wq always apply to the whole file. Commands are executed once for every selection. In visual mode the commands are applied to every selection as if an implicit x command, matching the existing selections, was present.

In the description, “range” is used to represent whatever address is supplied.

Many commands create new selections as a side effect when issued from a visual mode. If so, it is always to the “result” of the change: the new text for an insertion, the empty string for a deletion, the command output of a filter etc. If after a successful command execution no selections remain, the editor will switch to normal mode, otherwise it remains in visual mode. This allows interactive refinements of ranges.

Text commands

[count]/text/
Insert the text count times into the file after the range.

May also be written as

 a
 lines
 of
 text
 .
or i
Same as a, but c replaces the text, while i inserts the range.
Delete the text in range.

Display commands

Create a new selection for the range.

I/O commands

[!] [file name]
Replace the file by the contents of the named external file. If no file name is given, reload file from disk.
file name
Replace the text in the range by the contents of the named external file.
[!] [file name]
Write the range (default 0,$) to the named external file.
[!] [file name]
Same as w, but close file afterwards.

If the file name argument is absent from any of these, the current file name is used. e always sets the file name, w will do so if the file has no name. Forcing the e command with ! will discard any unsaved changes. Forcing w will overwrite the file on disk even if it has been externally modified since loading it. Write commands with a non-default addresses and no file name are destructive and need always to be forced.

shell command
Replace the range by the standard output of the shell command.
shell command
Sends the range to the standard input of the shell command.
shell command
Send the range to the standard input, and replace it by the standard output, of the shell command.
shell command
Run interactive shell command, redirect keyboard input to it.
directory
Change working directory. If no directory is specified, $HOME is used.

In any of <, >, |, or !, if the shell command is omitted, the last shell command (of any type) is substituted. Unless the file being edited is unnamed, all these external commands can refer to its absolute path and file name through the vis_filepath and vis_filename environment variables.

Loops and conditionals

regexp/ [command]
For each match of the regular expression in the range, run the command with range set to the match. If the regular expression and its slashes are omitted, /.*\n/ is assumed. Null string matches potentially occur before every character of the range and at the end of the range.

The "1"9 and "& registers are updated with the (sub) expression matches of the pattern.

regexp/ [command]
Like x, but run the command for each substring that lies before, between, or after the matches that would be generated by x. There is no default behavior. Null substrings potentially occur before every character in the range.
regexp/ command
For each file whose file name matches the regular expression, make that the current file and run the command. If the expression is omitted, the command is run in every file.
regexp/ command
Same as X, but for files that do not match the regular expression, and the expression is required.
[count][/regexp/] command
 
[count][/regexp/] command
If the count range contains (g) or does not contain (v) a match for the expression, run command on the range.

The count specifier has the following format, where n and m are integers denoting the ranges.

n,m
The closed interval from n to m. If n is missing, 1 is substituted. If m is missing, is substituted. Negative values are interpreted relative to the last range.
n
Matches every n-th range.

These may be nested arbitrarily deeply. An empty command in an x or y defaults to p. X, Y, g and v do not have defaults.

Grouping and multiple changes

Commands may be grouped by enclosing them in curly braces. Semantically, the opening brace is like a command: it takes an (optional) address and runs each sub-command on the range. Commands within the braces are executed sequentially, but changes made by one command are not visible to other commands.

When a command makes a number of changes to a file, as in x/re/ c/text/, the addresses of all changes are computed based on the initial state. If the changes are non-overlapping, they are applied in the specified order. Conflicting changes are rejected.

Braces may be nested arbitrarily.

VI(M) KEY BINDINGS

In the following sections angle brackets are used to denote special keys. The prefixes C-, S-, and M- are used to refer to the ⟨Ctrl⟩, ⟨Shift⟩ and ⟨Alt⟩ modifiers, respectively.

All active key bindings can be listed at runtime using the :help command.

Operators

Operators perform a certain operation on a text range indicated by either a motion, a text object or an existing selection.

When used in normal mode, the following operators wait for a motion, putting vis into operator pending mode.

change, delete range and enter insert mode
delete, cut range to register
shift-left, decrease indent
shift-right, increase indent
yank, copy range to register

When used in normal mode, the following actions take effect immediately.

format, filter range through fmt(1)
make lowercase
make uppercase
swap case
join lines, insert spaces in between
join lines remove any delimiting white spaces
put register content after cursor
put register content before cursor

Motions

Motions take an initial file position and transform it to a destination file position, thereby defining a range.

start of line
previous start of a word
previous start of a WORD
end of line
next end of a word
next end of a WORD
char
to next occurrence of ⟨char⟩ to the left
char
to next occurrence of ⟨char⟩ to the right
first non-blank of line
begin of display line
end of display line
previous end of a word
previous end of a WORD
begin of file
goto line or end of file
display line down
display line up
codepoint left
codepoint right
byte left
byte right
last non-blank of line
middle of display line
g|
goto column
char left
goto top/home line of window
line down
line up
char right
goto bottom/last line of window
match bracket, quote or backtick
next paragraph
next sentence
repeat last search backwards
repeat last search forward
previous start of block
next start of block
previous start of parentheses pair
next start of parentheses pair
previous paragraph
previous sentence
repeat last to/till movement
repeat last to/till movement but in opposite direction
search word under selection backwards
search word under selection forwards
char
till before next occurrence of ⟨char⟩ to the left
char
till before next occurrence of ⟨char⟩ to the right
pattern
to next match of pattern in backward direction
pattern
to next match of pattern in forward direction
next start of a word
next start of a WORD

Text objects

Text objects take an initial file position and transform it to a range where the former does not necessarily have to be contained in the latter. All of the following text objects are implemented in an inner variant (prefixed with i) where the surrounding white space or delimiting characters are not part of the resulting range and a normal variant (prefixed with a) where they are.

word
WORD
sentence
paragraph
block enclosed by these symbols

Further available text objects include:

matches the last used search term in forward direction
matches the last used search term in backward direction
current line
current line without leading and trailing white spaces

Multiple Selections

vis supports multiple selections with immediate visual feedback. There always exists one primary selection located within the current view port. Additional selections can be created as needed. If more than one selection exists, the primary one is styled differently.

To manipulate selections use in normal mode:

C-k
create count new selections on the lines above
C-M-k
create count new selections on the lines above the first selection
C-j
create count new selections on the lines below
C-M-j
create count new selections on the lines below the last selection
C-p
remove primary selection
C-n
select word the selection is currently over, switch to visual mode
C-u
make the count previous selection primary
C-d
make the count next selection primary
C-c
remove the count selection column
C-l
remove all but the count selection column
Tab
try to align all selections on the same column
Escape
dispose all but the primary selection

The visual modes were enhanced to recognize:

create a selection at the start of every selected line
create a selection at the end of every selected line
Tab
left align selections by inserting spaces
S-Tab
right align selections by inserting spaces
C-a
create new selections everywhere matching current word or selection
C-n
create new selection and select next word matching current selection
C-x
clear (skip) current selection, but select next matching word
C-p
remove primary selection
C-u⟩ ⟨C-k
make the count previous selection primary
C-d⟩ ⟨C-j
make the count next selection primary
C-c
remove the count selection column
C-l
remove all but the count selection column
rotate selections rightwards count times
-
rotate selections leftwards count times
trim selections, remove leading and trailing white space
flip selection direction, swap cursor and anchor
Escape
clear all selections, switch to normal mode

In insert and replace mode:

S-Tab
align all selections by inserting spaces

Selections can be manipulated using set operations. The first operand is the currently active selections while the second can be specified as a mark. For example, 'a| produces the union of the mark a and the current selection. Use of set operations without specifying a mark use the default mark as the first operand.

set union
set intersection
\
set minus
set complement

VI(M) COMMANDS

Any unique prefix can be used to abbreviate a command.

File and Window management

A file must be opened in at least one window. If the last window displaying a certain file is closed all unsaved changes are discarded. Windows are equally sized and can be displayed in rows (horizontally) or in columns (vertically). The ⟨C-wh, ⟨C-wj, ⟨C-wk and ⟨C-wl key mappings can be used to switch between windows.

open an empty window, arranged as a new row (horizontally)
open an empty window, arranged as a new column (vertically)
[!] [file name]
open a new window, displaying file name if given
[file name]
split window into rows (horizontally)
[file name]
split window into columns (vertically)
[!] [exit code]
close currently focused window
[!] [exit code]
close all windows, terminate editor with exit code (defaults to 0)

Commands taking a file name will invoke the vis-open(1) utility, if given a file pattern or directory.

Runtime key mappings

vis supports global as well as window local run time key mappings which are always evaluated recursively.

[!] mode lhs rhs
add a global key mapping
[!] mode lhs rhs
add a window local key mapping
mode lhs
remove a global key mapping
mode lhs
remove a window local key mapping

In the above mode refers to one of ‘normal’, ‘insert’, ‘replace’, ‘visual’, ‘visual-line’ or ‘operator-pending’; lhs refers to the key to map and rhs is a key action or alias. An existing mapping may be overridden by forcing the map command by specifying !.

Because key mappings are always recursive, doing something like:

:map! normal j 2j

will not work because it would enter an endless loop. Instead, vis uses pseudo keys referred to as key actions which can be used to invoke a set of available editor functions. :help lists all currently active key bindings as well as all available symbolic keys.

Keyboard Layout Specific Mappings

In order to facilitate usage of non-latin keyboard layouts, vis allows one to map locale specific keys to their latin equivalents by means of the

:langmap locale-keys latin-keys

command. As an example, the following maps the movement keys in Russian layout:

:langmap ролд hjkl

If the key sequences have not the same length, the remainder of the longer sequence will be discarded.

The defined mappings take effect in all non-input modes, i.e. everywhere except in insert and replace mode.

Undo/Redo

[count]
revert to older text state
[count]
revert to newer text state

If count is suffixed by either of d (days), h (hours), (minutes) or s (seconds) it is interpreted as an offset from the current system time and the closest available text state is restored.

SET OPTIONS

There are a small number of options that may be set (or unset) to change the editor's behavior using the :set command. This section describes the options, their abbreviations and their default values. Boolean options can be toggled by appending ! to the option name.

In each entry below, the first part of the tag line is the full name of the option, followed by any equivalent abbreviations. The part in square brackets is the default value of the option.

[“/bin/sh”]
User shell to use for external commands, overrides SHELL and shell field of password database /etc/passwd
[50]
Milliseconds to wait before deciding whether an escape sequence should be treated as an ⟨Escape⟩ key.
, tw [8]
Display width of a tab and number of spaces to use if expandtab is enabled.
, ai [off]
Automatically indent new lines by copying white space from previous line.
, et [off]
Whether ⟨Tab⟩ should be expanded to tabwidth spaces.
, nu [off]
Display absolute line numbers.
, rnu [off]
Display relative line numbers.
, cul [off]
Highlight line primary cursor resides on.
, cc [0]
Highlight a fixed column.
[32768]
How many bytes back the lexer will look to synchronize parsing.
[“default-16” or “default-256”]
Color theme to use, name without file extension. Loaded from a themes/ sub directory of the paths listed in the FILES section.
[auto]
Syntax highlighting lexer to use, name without file extension.
[off]
Whether to display replacement symbol instead of tabs.
[off]
Whether to display replacement symbol instead of newlines.
[off]
Whether to display replacement symbol instead of blank cells.
[on]
Whether to display replacement symbol for lines after the end of the file.
[auto]
How the current file should be saved, atomic which uses rename(2) to atomically replace the file, inplace which truncates the file and then rewrites it or auto which tries the former before falling back to the latter. The rename method fails for symlinks, hardlinks, in case of insufficient directory permissions or when either the file owner, group, POSIX ACL or SELinux labels can not be restored.
[auto]
How existing files should be loaded, read which copies the file content to an independent in-memory buffer, mmap which memory maps the file from disk and uses OS capabilities as caching layer or auto which tries the former for files smaller than 8Mb and the latter for lager ones. WARNING: modifying a memory mapped file in-place will cause data loss.
[“v” or “h”]
Whether to use vertical or horizontal layout.
, ic [off]
Whether to ignore case when searching.
, wc [0]
Wrap lines at minimum of window width and wrapcolumn.
, brk [“”]
Characters which might cause a word wrap.

COMMAND and SEARCH PROMPT

The command and search prompt as opened by :, /, or ? is implemented as a single line height window, displaying a regular file whose editing starts in insert mode. ⟨Escape⟩ switches to normal mode, a second ⟨Escape⟩ cancels the prompt. ⟨Up⟩ enlarges the window, giving access to the command history. ⟨C-v⟩ ⟨Enter⟩ inserts a literal new line thus enabling multiline commands. ⟨Enter⟩ executes the visual selection if present, or else everything in the region spawned by the selection position and the delimiting prompt symbols at the start of adjacent lines.

CONFIGURATION

vis uses Lua for configuration and scripting purposes. During startup visrc.lua (see the FILES section) is sourced which can be used to set personal configuration options. As an example the following will enable the display of line numbers:

vis:command('set number')

ENVIRONMENT

The default path to use to load Lua support files.
The home directory used for the cd command if no argument is given.
The terminal type to use to initialize the curses interface, defaults to if unset.
The command shell to use for I/O related commands like !, >, < and |.
The configuration directory to use, defaults to $HOME/.config if unset.

ASYNCHRONOUS EVENTS

Suspend editor.
Resume editor.
An mmap(2) ed file got truncated, unsaved file contents will be lost.
 
Restore initial terminal state. Unsaved file contents will be lost.
When an interrupt occurs while an external command is being run it is terminated.
The screen is resized.

FILES

Upon startup vis will source the first visrc.lua configuration file found from these locations. All actively used paths can be listed at runtime using the :help command.

  • $VIS_PATH
  • The location of the vis binary (on systems where /proc/self/exe is available).
  • $XDG_CONFIG_HOME/vis where XDG_CONFIG_HOME refers to $HOME/.config if unset.
  • /etc/vis for a system-wide configuration provided by administrator.
  • /usr/local/share/vis or /usr/share/vis depending on the build configuration.

    When creating a new visrc.lua be sure to copy the structure from here.

EXIT STATUS

The vis utility exits 0 on success, and >0 if an error occurs.

EXAMPLES

Use vis as an interactive filter.

$ { echo Pick your number; seq 1 10; } | vis - > choice

Use the vis-open(1) based file browser to list all C language source files:

:e *.c

Spawn background process and pipe range to its standard input:

:> { plumber <&3 3<&- & } 3<&0 1>&- 2>&-

SEE ALSO

sam(1), vi(1), vis-clipboard(1), vis-complete(1), vis-digraph(1), vis-menu(1), vis-open(1)

A Tutorial for the Sam Command Language by Rob Pike

The Text Editor sam by Rob Pike

Plan 9 manual page for sam(1)

Structural Regular Expressions by Rob Pike

vi - screen-oriented (visual) display editor IEEE Std 1003.1 (“POSIX.1”)

STANDARDS

vis does not strive to be IEEE Std 1003.1 (“POSIX.1”) compatible, but shares obvious similarities with the vi utility.

AUTHORS

vis is written by Marc André Tanner ⟨mat at brain-dump.org⟩

BUGS

On some systems there already exists a vis binary, thus causing a name conflict.

January 14, 2017 Vis 0.9