Index of Section 1 Manual Pages
| Interix / SUA | vi.1 | Interix / SUA |
vi(1) vi(1)
nvi
NAME
ex, vi, view - text editors
SYNOPSIS
ex [-eFRrsv] [-c cmd] [-t tag] [-w size] [file ...]
vi [-eFlRrvW] [-c cmd] [-t tag] [-w size] [file ...]
view [-eFRrvW] [-c cmd] [-t tag] [-w size] [file ...]
DESCRIPTION
The vi(1) utility is a screen-oriented text editor; ex(1) is a line-
oriented text editor. The ex(1) and vi(1) utilities are different
interfaces to the same program; it is possible to switch back and forth
between them during an editing session. The view utility is the equivalent
of using the -R (read-only) option of vi.
The information in this topic is also provided in the manual page that
accompanies the nvi version of the ex and vi text editors. The nvi utility
is intended as a bug-for-bug compatible replacement for the original
Fourth Berkeley Software Distribution (4BSD) ex(1) and vi(1) programs. For
the rest of this topic, nvi is used only when it is necessary to
distinguish them from the historic implementations of ex and vi.
The information in this topic is most suitable for users already familiar
with ex/vi. If you are unfamiliar with ex/vi, it is recommended that you
read a good tutorial on these editors to get some background information
about them before reading this topic. If you are in an unfamiliar
environment, however, and you must get work done immediately, read the
section after Options, entitled Fast Startup.
OPTIONS
+cmd
-c cmd
Execute cmd immediately after starting the edit session. This can be
useful for initial positioning in the file; however, cmd is not
limited to positioning commands. This is the POSIX 1003.2 interface
for the historic +cmd syntax. The nvi utility supports both the old
and new syntax.
-e
Start editing in ex mode, as if the command name were ex.
-F
Do not copy the entire file when first starting to edit. (The default
is to copy the file in case someone else modifies the file during your
edit session.)
-l
Start editing with the lisp and showmatch options set.
-R
Start editing in read-only mode, as if the command name were view, or
the readonly option were set.
-r
Recover the specified files, or, if no files are specified, list the
files that could be recovered. If no recoverable files by the
specified name exist, the file is edited as if the -r option had not
been specified.
-s
Enter batch mode; applicable only to ex(1) edit sessions. Batch mode
is useful when running ex(1) scripts. Prompts, informative messages
and other user-oriented messages are turned off, and no startup files
or environment variables are read. This is the POSIX 1003.2 interface
for the historic - argument. The nvi utility supports both the old and
new syntax.
-t
Start editing at the specified tag. (See ctags(1)).
-w
Set the initial window size to the specified number of lines.
-v
Start editing in vi mode, as if the command name were vi(1) or
view(1).
-W
Start editing with the windowstext option set.
Command input for ex/vi is read from the standard input. In the vi(1)
interface, it is an error if standard input is not a terminal. In the
ex(1) interface, if standard input is not a terminal, ex(1) will read
commands from it regardless. The session will be a batch-mode session,
however, exactly as though the -s option had been specified.
FAST STARTUP
This section provides the minimum amount of information that you need in
order to do simple editing tasks using vi. If you have not used any screen
editor before, you are likely to have problems even with this simple
introduction, however. It is therefore recommended that you find someone
who already knows vi(1) for assistance with this section.
The vi(1) utility is a screen editor. This means that it occupies almost
the entire screen, displaying part of the file on each screen line, except
the last line of the screen, which provides space for you to give commands
to vi(1), and for vi(1) to give information to you.
It is important to note that vi(1)is a modeful editor; that is, when using
vi(1), you are either entering text or executing commands, and you must be
in the right mode to do one or the other. You will be in command mode when
you first start editing a file. There are commands that switch you into
input mode. There is only one key that takes you out of input mode, and
that is the key. (Key names are written using less-than and
greater-than signs; for example, means the escape key, usually
labeled Esc on your keyboard.) If you are ever confused as to which mode
you are in, press the key repeatedly until vi(1) beeps.
(Generally, vi(1)beeps if you try and do something that is not allowed. It
will also display error messages.)
To start editing a file, enter the command:
vi file_name
As soon as you start editing, enter the command:
set verbose showmode
This will cause the editor to give you verbose error messages and display
the current mode at the bottom of the screen.
Use the following commands to move the cursor from one place to another in
the file:
h
Move the cursor left one character.
j
Move the cursor down one line.
k
Move the cursor up one line.
l
Move the cursor right one character.
The cursor arrow keys should work, too.
/text
Search for the string text in the file and move the cursor to its
first character.
Use the following commands to enter new text:
a
Append new text after the cursor.
i
Insert new text before the cursor.
o
Open a new line below the line the cursor is on, and start entering
text.
O
Open a new line above the line the cursor is on, and start entering
text.
Once you have entered input mode using one of the commands a, i, O or
o, use to quit entering text and return to command mode.
Use the following commands to copy text:
yy
Copy the line the cursor is on.
p
Append the copied line after the line the cursor is on.
Use the following commands to delete text:
dd
Delete the line the cursor is on.
x
Delete the character the cursor is on.
Use the following commands to write the file:
:w
Write the file back to the file with the name that you originally used
as an argument on the vi(1) command line.
:w file_name
Write the file back to the file with the name file_name.
Use the following commands to to quit editing and exit the editor:
:q
Quit editing and leave vi(1). If you have modified the file but not
saved your changes, vi(1) will refuse to quit.
:q!
Quit, discarding any modifications that you may have made.
One final caution: unusual characters can take up more than one column on
the screen, and long lines can take up more than a single screen line. The
above commands work on physical characters and lines; that is, they affect
the entire line no matter how many screen lines it takes up and the entire
character no matter how many screen columns it takes up.
VI COMMANDS
The following section describes the commands available in the command mode
of the vi(1) editor. In each entry below, the tag line is a usage synopsis
for the command character.
[count]
Search forward count times for the current word.
[count]
Page backwards count screens.
[count]
Scroll forward count lines.
[count]
Scroll forward count lines, leaving the current line and column as is,
if possible.
[count]
Page forward count screens.
Display the file information.
[count] h
Move the cursor back count characters in the current line.
[count]
[count]
[count] j
Move the cursor down count lines without changing the current column.
Repaint the screen.
[count]
[count] +
Move the cursor down count lines to the first nonblank character of
that line.
[count]
[count] k
Move the cursor up count lines, without changing the current column.
Return to the most recent tag context.
Scroll backwards count lines.
Switch to the next lower screen in the window, or to the first screen
if there are no lower screens in the window.
Scroll backwards count lines, leaving the current line and column as
is, if possible.
Suspend the current editor session.
Execute ex(1) commands or cancel partial commands.
Push a tag reference onto the tag stack.
Switch to the most recently edited file.
[count]
[count] l
Move the cursor forward count characters without changing the current
line.
[count] ! motion shell-argument(s)
Replace text with results from a shell command.
[count] # #|+|-
Increment or decrement the cursor number.
[count] $
Move the cursor to the end of a line.
%
Move to the matching character.
&
Repeat the previous substitution command on the current line.
'
'
Return to a context marked by the character .
[count] (
Back up count sentences.
[count] )
Move forward count sentences.
[count] ,
Reverse find character count times.
[count] -
Move to first nonblank of the previous line, count times.
[count] .
Repeat the last vi(1) command that modified text.
/RE
/RE/[offset]
?RE
?RE?[offset]
N
n
Search forward or backward for a regular expression.
0
Move to the first character in the current line.
:
Execute an ex command.
[count] ;
Repeat the last character find count times.
[count] < motion
[count] > motion
Shift lines left or right.
@ buffer
Execute a named buffer.
[count] A
Enter input mode, appending the text after the end of the line.
[count] B
Move backwards count bigwords.
[buffer] [count] C
Change text from the current position to the end-of-line.
[buffer] D
Delete text from the current position to the end-of-line.
[count] E
Move forward count end-of-bigwords.
[count] F
Search count times backward through the current line for .
[count] G
Move to line count, or the last line of the file if count not
specified.
[count] H
Move to the screen line count - 1 lines below the top of the screen.
[count] I
Enter input mode, inserting the text at the beginning of the line.
[count] J
Join lines.
[count] L
Move to the screen line count - 1 lines above the bottom of the
screen.
M
Move to the screen line in the middle of the screen.
[count] O
Enter input mode, appending text in a new line above the current line.
[buffer] P
Insert text from a buffer.
Q
Exit vi(1) (or visual) mode and switch to ex(1) mode.
[count] R
Enter input mode, replacing the characters in the current line.
[buffer] [count] S
Substitute count lines.
[count] T
Search backwards, count times, through the current line for the
character after the specified .
U
Restore the current line to its state before the cursor last moved to
it.
[count] W
Move forward count big words.
[buffer] [count] X
Delete count characters before the cursor.
[buffer] [count] Y
Copy (or yank) count lines into the specified buffer.
ZZ
Write the file and exit vi.
[count] [[
Back up count section boundaries.
[count] ]]
Move forward count section boundaries.
^
Move to first nonblank character on the current line.
[count] _
Move down count-1 lines, to the first nonblank character.
[count] a
Enter input mode, appending the text after the cursor.
[count] b
Move backwards count words.
[buffer][count]cmotion
Change a region of text.
[buffer][count]dmotion
Delete a region of text.
[count] e
Move forward count end-of-words.
[count] f
Search forward, count times, through the rest of the current line for
.
[count] i
Enter input mode, inserting the text before the cursor.
m
Save the current context (line and column) as .
[count] o
Enter input mode, appending text in a new line under the current line.
[buffer] p
Append text from a buffer.
[count] r
Replace count characters.
[buffer] [count] s
Substitute count characters in the current line starting with the
current character.
[count] t
Search forward, count times, through the current line for the
character immediately before .
u
Undo the last change made to the file.
[count] w
Move forward count words.
[buffer] [count] x
Delete count characters.
[buffer][count]ymotion
Copy (or yank) a text region specified by the count and motion into a
buffer.
[count1] z [count2] -|.|+|^|
Redraw, optionally repositioning and resizing the screen.
[count] {
Move backward count paragraphs.
[count] |
Move to a specific column position on the current line.
[count] }
Move forward count paragraphs.
[count] ~
Reverse the case of the next count character(s).
[count] ~ motion
Reverse the case of the characters in a text region specified by the
count and motion.
Interrupt the current operation.
VI TEXT INPUT COMMANDS
The following section describes the commands available in the text input
mode of the vi(1) editor.
Replay the previous input.
Erase to the previous shiftwidth column boundary.
^
Erase all of the autoindent characters and reset the autoindent level.
0
Erase all of the autoindent characters.
Insert sufficient and characters to move forward to the
next shiftwidth column boundary.
Erase the last character.
Quote the next character.
Resolve all text input into the file and return to command mode.
Erase the current line.
Erase the last word. The definition of word is dependent on the
altwerase and ttywerase options.
[0-9A-Fa-f]+
Insert a character with the specified hexadecimal value into the text.
Interrupt text input mode, returning to command mode.
EX COMMANDS
The following section describes the commands available in the ex(1)
editor. In each entry below, the tag line is a usage synopsis for the
command.
The flags argument listed for many commands is any combination of the
characters.
p
Print the affected line(s) to the screen, as if it had been selected
by the print command.
l (the lowercase letter el)
List the affected line(s) to the screen, as if it had been selected by
the list command, displaying nonprintable characters and marking the
ends of the lines with $.
#
Print the affected line(s) to the screen as if it had been selected by
the number command, displaying line numbers.
These flags can be further modified by adding a number of + or -
characters after the command but before the flags. These determine which
line is displayed or which line is the current line after the command.
As an extension to historical vi(1) implementations, if the commands ex,
edit, next, previous, tag, and visual are typed with an uppercase letter
(such as Ex or Previous), the command happens in a new screen. In
historical vi(1), an uppercase P command had no special meaning.
Scroll the screen.
! argument(s)
[range]! argument(s)
Execute a shell command, or filter lines through a shell command.
A comment.
[range]nu[mber][count] [flags]
[range]#[count][flags]
Display the selected lines, each preceded with its line number.
@ buffer
* buffer
Execute a buffer.
[line]a[ppend][!]
The input text is appended after the specified line.
[range]c[hange][!] [count]
The input text replaces the specified range.
cs[cope] add |find | help | kill |reset
Execute a Cscope command.
[range] d[elete][buffer] [count] [flags]
Delete the lines from the file.
di[splay]b[uffers]|c[onnections]|s[creens] | t[ags]
Display buffers, Cscope connections, screens or tags.
[Ee][dit][!] [+cmd] [file]
[Ee]x[!][+cmd] [file]
Edit a different file.
exu[sage] [command]
Display usage for an ex(1) command.
f[ile] [file]
Display and optionally change the file name.
[Ff]g [name]
Used in vi(1) mode only. Foreground the specified screen.
[range]g[lobal]/pattern/ [commands]
[range]v/pattern/[commands]
Apply commands to lines matching (or not matching) a pattern.
he[lp]
Display a help message.
[line]i[nsert][!]
The input text is inserted before the specified line.
[range]j[oin][!] [count] [flags]
Join lines of text together.
[range] l[ist] [count] [flags]
Display the lines unambiguously, displaying nonprintable characters
and marking the ends of the lines with $.
map[!] [lhs rhs]
Define or display maps (for vi(1) only).
[line] ma[rk]
[line] k
Mark the line with the mark .
[range] m[ove] line
Move the specified lines after the target line.
mk[exrc][!] file
Write the abbreviations, editor options, and maps to the specified
file.
[Nn][ext][!] [file ...]
Edit the next file from the argument list.
[line] o[pen] /pattern/ [flags]
Enter open mode.
pre[serve]
Save the file in a form that can later be recovered using the ex(1) -
r option.
[Pp]rev[ious][!]
Edit the previous file from the argument list.
[range] p[rint] [count] [flags]
Display the specified lines.
[line] pu[t] [buffer]
Append buffer contents to the current line.
q[uit][!]
End the editing session.
[line] r[ead][!] [file]
Read a file.
rec[over] file
Recover file if it was previously saved.
res[ize] [+|-]size
For vi(1) mode only. Expand or shrink the current screen.
rew[ind][!]
Rewind the argument list.
se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]
Display or set editor options.
sh[ell]
Run a shell program.
so[urce] file
Read and execute ex(1) commands from a file.
[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]
[range] & [options] [count] [flags]
[range] ~ [options] [count] [flags]
Make substitutions. In the substitution string, the characters ~ and %
may have special meanings. If the entire replace pattern is a percent
sign (%), the previous replacement pattern is used. (This can be
useful for repeating substitutions that contain back references.) The
special character ~ inserts the previous replacement string into this
replacement string.
The options can be any of the following:
c
Ask for confirmation before replacing the text.
g
Perform the replacement on all occurrences of the regular
expression on the line.
r
If no regular expression was specified, use the most recent
regular expression (used for a search) rather than the same
regular expression as used for the last substitute command.
su[spend][!]
st[op][!]
Suspend the edit session.
[Tt]a[g][!] tagstring
Edit the file containing the specified tag.
tagn[ext][!]
Edit the file containing the next context for the current tag.
tagp[op][!] [file | number]
Pop to the specified tag in the tags stack.
tagp[rev][!]
Edit the file containing the previous context for the current tag.
unm[ap][!] lhs
Unmap a mapped string.
ve[rsion]
Display the version of the ex/vi editor.
[line] vi[sual] [type] [count] [flags]
For ex(1) mode only. Enter vi.
Vi[sual][!] [+cmd] [file]
For vi(1) mode only. Edit a new file; vi(1) opens a new edit session
in half of the screen window (the half without the cursor). Executing
the Vi command again subdivides this smaller window. To return to the
parent window/file, quit the vi(1) session (with q or Q or ZZ). This
is an extension to traditional vi(1).
viu[sage] [command]
Display usage for a vi(1) command.
[range] w[rite][!] [>>] [file]
[range] w[rite] [!] [file]
[range] wn[!] [>>] [file]
[range] wq[!] [>>] [file]
Write the file. The modifier ! forces the write operation even if the
file is newer than the buffer. The modifier >> appends the buffer to
the named file. The wn command writes and then moves to the next file
in the list. The wq command writes and then quits.
[range] x[it][!] [file]
Write the file if it has been modified.
[range] ya[nk] [buffer] [count]
Copy the specified lines to a buffer.
[line] z [type] [count] [flags]
Adjust the window.
SET OPTIONS
There many options available that you can set (or unset) to change the
behavior of the editor. This section describes the options, their
abbreviations and their default values.
In each entry below, the first part of the tag line is the full name of
the option, followed by any equivalent abbreviations. The information in
square brackets is the default value of the option. Most of the options
are boolean: they are either on or off, and do not have an associated
value.
Options apply to both ex(1) and vi(1) modes, unless otherwise specified.
showmatch, sm [off]
For vi(1) only. Note matching { and ( for } and ) characters.
showmode, smd [off]
For vi(1) only. Display the current editor mode and a modified flag.
sidescroll [16]
For vi(1) only. Set the amount a left-right scroll will shift.
slowopen, slow [off]
Delay display updating during text input. This option is not yet
implemented
sourceany [off]
Read startup files not owned by the current user. This option will
never be implemented.
tabstop, ts [8]
This option sets tab widths for the editor display.
taglength, tl [0]
Set the number of significant characters in tag names.
tags, tag [tags]
Set the list of tags files.
term, ttytype, tty [environment variable TERM]
Set the terminal type.
terse [off]
This option has historically made editor messages less verbose. It has
no effect in this implementation.
tildeop [off]
Modify the ~ command to take an associated motion.
timeout, to [on]
Time out on keys which may be mapped.
ttywerase [off]
For vi(1) only. Select an alternate erase algorithm.
verbose [off]
For vi(1) only. Display an error message for every error.
w300 [no default]
For vi(1) only. Set the window size if the baud rate is less than 1200
baud.
w1200 [no default]
For vi(1) only. Set the window size if the baud rate is equal to 1200
baud.
w9600 [no default]
For vi(1) only. Set the window size if the baud rate is greater than
1200 baud.
warn [on]
For ex(1) only. This option causes a warning message to the terminal
if the file has been modified since it was last written, before a !
command.
window, w, wi [environment variable LINES]
Set the window size for the screen.
windowname [off]
Change the icon/window name to the current file name even if it cannot
be restored on editor exit.
windowstext
On input, replaces all carriage-return/linefeed character pairs (\r\n)
to a single linefeed character (\n); on ouptut, converts each linefeed
character to a carriage-return/linefeed character pair.
wraplen, wl [0]
For vi(1) only. Break lines automatically, the specified number of
columns from the left-hand margin. If both the wraplen and wrapmargin
edit options are set, the wrapmargin value is used.
wrapmargin, wm [0]
For vi(1) only. Break lines automatically the specified number of
columns from the right-hand margin. If both the wraplen and wrapmargin
edit options are set, the wrapmargin value is used.
wrapscan, ws [on]
Set searches to wrap around the end or beginning of the file.
writeany, wa [off]
Turn off file-overwriting checks.
DIAGNOSTICS
The ex/vi utility exits 0 on success and greater than 0 if an error
occurs.
ENVIRONMENT VARIABLES
COLUMNS
The number of columns on the screen. This value overrides any system
or terminal specific values. If the COLUMNS environment variable is
not set when ex/vi runs, or the columns option is explicitly reset by
the user, ex enters the value into the environment.
EXINIT
A list of ex(1) startup commands, read if the variable NEXINIT is not
set.
HOME
The user's home directory, used as the initial directory path for the
startup $HOME/.nexrc and $HOME/.exrc files. This value is also used as
the default directory for the vi(1) cd command.
LINES
The number of rows on the screen. This value overrides any system or
terminal-specific values. If the LINES environment variable is not set
when ex/vi runs, or the lines option is explicitly reset by the user,
ex/vi enters the value into the environment.
NEXINIT
A list of ex(1) startup commands.
SHELL
The user's shell of choice (see also the shell option).
TERM
The user's terminal type. The default is the type unknown. If the TERM
environment variable is not set when ex/vi runs, or the term option is
explicitly reset by the user, ex/vi enters the value into the
environment.
TMPDIR
The location used to stored temporary files (see also the directory
edit option).
ASYNCHRONOUS EVENTS
SIGALRM
The ex/viutility uses this signal for periodic backups of file
modifications and to display busy messages when operations are likely
to take a long time.
SIGHUP
SIGTERM
If the current buffer has changed since it was last written in its
entirety, the editor attempts to save the modified file so it can be
later recovered. See the ex/vi rreferenreferencesection entitled
"Recovery" for more information.
SIGINT
When an interrupt occurs, the current operation is halted, and the
editor returns to the command level. If interrupted during text input,
the text already input is resolved into the file as if the text input
had been normally terminated.
SIGWINCH
The screen is resized. See the ex/vi reference manual section entitled
"Sizing the Screen" for more information.
SIGCONT
SIGQUIT
SIGTSTP
The ex/vi utility ignores these signals.
FILES
The vi(1) utility uses the following files:
/bin/sh
The default user shell.
/etc/vi.exrc
System-wide vi(1) startup file.
/tmp
Temporary file directory, used if TMPDIR is not defined.
/tmp/vi.recover
The default recovery file directory.
$HOME/.nexrc
The first choice for user's home directory startup file.
$HOME/.exrc
The second choice for user's home directory startup file.
.nexrc
The first choice for local directory startup file.
.exrc
The second choice for local directory startup file.
SEE ALSO
ctags(1)
more(1)
curses(3)
The Vi Quick Reference card
An Introduction to Display Editing with Vi, found in the user manual of
both the 4.3BSD and 4.4BSD manual sets. This document is the closest thing
available to an introduction to the vi(1) screen editor.
Ex Reference Manual (Version 3.7), found in the user manual of both the
4.3BSD and 4.4BSD manual sets. This document is the final reference for
the ex(1) editor, as distributed in most historic 4BSD and System V
systems.
Edit: A tutorial, found in the user manual of the 4.3BSD manual set. This
document is an introduction to a simple version of the ex(1) screen
editor.
Ex/Vi Reference Manual, found in the user manual of the 4.4BSD manual set.
This document is the final reference for the nvi text editor, as
distributed in 4.4BSD and 4.4BSD-Lite.
Roff source for all of these documents is distributed with nvi in the nvi/
USD.doc directory of the nvi(1) source code.
The files autowrite, input, quoting, and structures are found in the nvi/
docs/internals directory of the nvi(1) source code.