DOKK / manpages / debian 12 / nvi / nex.1.en
VI(1) General Commands Manual VI(1)

ex, vi, view - text editors

ex [-eRrSsv] [-c cmd] [-t tag] [-w size] [file ...]
vi [-elRrSv] [-c cmd] [-t tag] [-w size] [file ...]
view [-eRrSv] [-c cmd] [-t tag] [-w size] [file ...]

The vi program is freely redistributable. You are welcome to copy, modify and share it with others under the conditions listed in the LICENSE file. If any company (not individual!) finds vi sufficiently useful that you would have purchased it, or if any company wishes to redistribute it, contributions to the authors would be appreciated.

Vi is a screen oriented text editor. Ex is a line‐oriented text editor. Ex and vi are different interfaces to the same program, and it is possible to switch back and forth during an edit session. View is the equivalent of using the -R (read‐only) option of vi.

This manual page is the one provided with the nex/nvi versions of the ex/vi text editors. Nex/nvi are intended as bug‐for‐bug compatible replacements for the original Fourth Berkeley Software Distribution (4BSD) ex and vi programs. For the rest of this manual page, nex/nvi is used only when it's necessary to distinguish it from the historic implementations of ex/vi.

This manual page is intended for users already familiar with ex/vi. Anyone else should almost certainly read a good tutorial on the editor before this manual page. If you're in an unfamiliar environment, and you absolutely have to get work done immediately, read the section after the options description, entitled “Fast Startup”. It's probably enough to get you going.

The following options are available:

Execute cmd immediately after starting the edit session. Particularly 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. Nex/nvi supports both the old and new syntax.
Start editing in ex mode, as if the command name were ex.
Start editing with the lisp and showmatch options set.
Start editing in read‐only mode, as if the command name was view, or the readonly option was set.
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.
Run with the secure edit option set, disallowing all access to external programs.
Enter batch mode; applicable only to ex edit sessions. Batch mode is useful when running ex scripts. Prompts, informative messages and other user oriented message are turned off, and no startup files or environmental variables are read. This is the POSIX 1003.2 interface for the historic “-” argument. Nex/nvi supports both the old and new syntax.
Start editing at the specified tag. (See ctags(1)).
Set the initial window size to the specified number of lines.
Start editing in vi mode, as if the command name was vi or view.

Note that the -F option (which prevented ex/vi from making a full backup of the target file) has been removed and is no longer available.

Command input for ex/vi is read from the standard input. In the vi interface, it is an error if standard input is not a terminal. In the ex interface, if standard input is not a terminal, ex will read commands from it regardless, however, the session will be a batch mode session, exactly as if the -s option had been specified.

Ex/vi exits 0 on success, and greater than 0 if an error occurs.

This section will tell you the minimum amount that you need to do simple editing tasks using vi. If you've never used any screen editor before, you're likely to have problems even with this simple introduction. In that case you should find someone that already knows vi and have them walk you through this section.

Vi is a screen editor. This means that it takes up almost the entire screen, displaying part of the file on each screen line, except for the last line of the screen. The last line of the screen is used for you to give commands to vi, and for vi to give information to you.

The other fact that you need to understand is that vi is a modeful editor, i.e. you are either entering text or you are executing commands, and you have to 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 <escape> key. (Key names are written using less‐than and greater‐than signs, e.g. <escape> means the “escape” key, usually labeled “esc” on your terminal's keyboard.) If you're ever confused as to which mode you're in, keep entering the <escape> key until vi beeps at you. (Generally, vi will beep at you if you try and do something that's not allowed. It will also display error messages.)

To start editing a file, enter the command “vi file_name<carriage‐return>”. The command you should enter as soon as you start editing is “:set verbose showmode<carriage‐return>”. This will make the editor give you verbose error messages and display the current mode at the bottom of the screen.

The commands to move around the file are:

Move the cursor left one character.
Move the cursor down one line.
Move the cursor up one line.
Move the cursor right one character.
<cursor‐arrows>
The cursor arrow keys should work, too.
/text<carriage‐return>
Search for the string “text” in the file, and move the cursor to its first character.

The commands to enter new text are:

Append new text, after the cursor.
Insert new text, before the cursor.
Open a new line below the line the cursor is on, and start entering text.
Open a new line above the line the cursor is on, and start entering text.
<escape>
Once you've entered input mode using the one of the a, i, O or o commands, use <escape> to quit entering text and return to command mode.

The commands to copy text are:

Copy the line the cursor is on.
Append the copied line after the line the cursor is on.

The commands to delete text are:

Delete the line the cursor is on.
Delete the character the cursor is on.

The commands to write the file are:

:w<carriage‐return>
Write the file back to the file with the name that you originally used as an argument on the vi command line.
:w file_name<carriage‐return>
Write the file back to the file with the name “file_name”.

The commands to quit editing and exit the editor are:

:q<carriage‐return>
Quit editing and leave vi (if you've modified the file, but not saved your changes, vi will refuse to quit).
:q!<carriage‐return>
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, i.e. 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.

The following section describes the commands available in the command mode of the vi editor. In each entry below, the tag line is a usage synopsis for the command character.

[count] <control‐A>
Search forward count times for the current word.
[count] <control‐B>
Page backwards count screens.
[count] <control‐D>
Scroll forward count lines.
[count] <control‐E>
Scroll forward count lines, leaving the current line and column as is, if possible.
[count] <control‐F>
Page forward count screens.
<control‐G>
Display the file information.
<control‐H>
[count] h
Move the cursor back count characters in the current line.
[count] <control‐J>
[count] <control‐N>
[count] j
Move the cursor down count lines without changing the current column.
<control‐L>
<control‐R>
Repaint the screen.
[count] <control‐M>
[count] +
Move the cursor down count lines to the first nonblank character of that line.
[count] <control‐P>
[count] k
Move the cursor up count lines, without changing the current column.
<control‐T>
Return to the most recent tag context.
<control‐U>
Scroll backwards count lines.
<control‐W>
Switch to the next lower screen in the window, or, to the first screen if there are no lower screens in the window.
<control‐Y>
Scroll backwards count lines, leaving the current line and column as is, if possible.
<control‐Z>
Suspend the current editor session.
<escape>
Execute ex commands or cancel partial commands.
<control‐]>
Push a tag reference onto the tag stack.
<control‐^>
Switch to the most recently edited file.
[count] <space>
[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.
'<character>
`<character>
Return to a context marked by the character <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 command that modified text.
/RE<carriage‐return>
/RE/ [offset]<carriage‐return>
?RE<carriage‐return>
?RE? [offset]<carriage‐return>
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 <character>
Search count times backward through the current line for <character>.
[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.
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.
Exit vi (or visual) mode and switch to ex mode.
[count] R
Enter input mode, replacing the characters in the current line.
[buffer] [count] S
Substitute count lines.
[count] T <character>
Search backwards, count times, through the current line for the character after the specified <character>.
Restore the current line to its state before the cursor last moved to it.
[count] W
Move forward count bigwords.
[buffer] [count] X
Delete count characters before the cursor.
[buffer] [count] Y
Copy (or “yank”) count lines into the specified buffer.
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] c motion
Change a region of text.
[buffer] [count] d motion
Delete a region of text.
[count] e
Move forward count end‐of‐words.
[count] f<character>
Search forward, count times, through the rest of the current line for <character>.
[count] i
Enter input mode, inserting the text before the cursor.
Save the current context (line and column) as <character>.
[count] o
Enter input mode, appending text in a new line under the current line.
[buffer] p
Append text from a buffer.
[count] r <character>
Replace count characters.
[buffer] [count] s
Substitute count characters in the current line starting with the current character.
[count] t <character>
Search forward, count times, through the current line for the character immediately before <character>.
Undo the last change made to the file.
[count] w
Move forward count words.
[buffer] [count] x
Delete count characters.
[buffer] [count] y motion
Copy (or “yank”) a text region specified by the count and motion into a buffer.
[count1] z [count2] -|.|+|^|<carriage‐return>
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), if the tildeop option is unset.
[count] ~ motion
Reverse the case of the characters in a text region specified by the count and motion, if the tildeop option is set.
<interrupt>
Interrupt the current operation.

The following section describes the commands available in the text input mode of the vi editor.

<nul>
Replay the previous input.
<control‐D>
Erase to the previous shiftwidth column boundary.
^<control‐D>
Erase all of the autoindent characters, and reset the autoindent level.
0<control‐D>
Erase all of the autoindent characters.
<control‐T>
Insert sufficient <tab> and <space> characters to move forward to the next shiftwidth column boundary.
<erase>
<control‐H>
Erase the last character.
<literal next>
Quote the next character.
<escape>
Resolve all text input into the file, and return to command mode.
<line erase>
Erase the current line.
<control‐W>
<word erase>
Erase the last word. The definition of word is dependent on the altwerase and ttywerase options.
<control‐X>[0-9A-Fa-f]+
Insert a character with the specified hexadecimal value into the text.
<interrupt>
Interrupt text input mode, returning to command mode.

The following section describes the commands available in the ex editor. In each entry below, the tag line is a usage synopsis for the command.

<end‐of‐file>
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.
Execute a Cscope command.
[range] d[elete] [buffer] [count] [flags]
Delete the lines from the file.
Display buffers, Cscope connections, screens or tags.
[Ee][dit][!] [+cmd] [file]
[Ee]x[!] [+cmd] [file]
Edit a different file.
Display usage for an ex command.
Display and optionally change the file name.
[Ff]g [name]
Vi 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.
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.
Define or display maps (for vi only).
[line] ma[rk] <character>
[line] k <character>
Mark the line with the mark <character>.
[range] m[ove] line
Move the specified lines after the target line.
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.
Save the file in a form that can later be recovered using the ex -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.
End the editing session.
[line] r[ead][!] [file]
Read a file.
Recover file if it was previously saved.
Vi mode only. Grow or shrink the current screen.
Rewind the argument list.
Display or set editor options.
Run a shell program.
Read and execute ex commands from a file.
[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]
[range] & [options] [count] [flags]
[range] ~ [options] [count] [flags]
Make substitutions.
<suspend>
Suspend the edit session.
[Tt]a[g][!] tagstring
Edit the file containing the specified tag.
Edit the file containing the next context for the current tag.
Pop to the specified tag in the tags stack.
Edit the file containing the previous context for the current tag.
Unmap a mapped string.
Display the version of the ex/vi editor.
[line] vi[sual] [type] [count] [flags]
Ex mode only. Enter vi.
[Vi]i[sual][!] [+cmd] [file]
Vi mode only. Edit a new file.
Display usage for a vi command.
[range] w[rite][!] [>>] [file]
[range] w[rite] [!] [file]
[range] wn[!] [>>] [file]
[range] wq[!] [>>] [file]
Write the file.
[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.

There are a large number of options that may be set (or unset) to change the editor's behavior. 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 part in square brackets is the default value of the option. Most of the options are boolean, i.e. they are either on or off, and do not have an associated value.

Options apply to both ex and vi modes, unless otherwise specified. Multiple options can be given in one set or unset, separated by spaces or tabs. Spaces and tabs can be included in string options (eg. tags or filec) by preceding each with a backslash. There's no way to get backslash itself into an option.

Vi only. Select an alternate word erase algorithm.
Automatically indent new lines.
Ex only. Display the current line automatically.
Write modified files automatically when changing files.
Backup files before they are overwritten.
Discard control characters.
The directory paths used as path prefixes for the cd command.
Set the character to edit the colon command‐line history.
Set the number of columns in the screen.
Vi only. Skip leading comments in shell, C and C++ language files.
The directory where temporary files are created.
Remember the values of the “c” and “g” suffices to the substitute commands, instead of initializing them as unset for each new command.
Ex only. Announce error messages with a bell.
Read the startup files in the local directory.
Regular expressions are extended (i.e. egrep(1)-style) expressions.
Set the character to perform file path completion on the colon command line.
Flash the screen instead of beeping the keyboard on error.
Set the spacing between hardware tab settings.
Makes all Regular Expressions case‐insensitive, as long as an upper‐case letter does not appear in the search string.
Ignore case differences in regular expressions.
The 10th's of a second ex/vi waits for a subsequent key to complete a key mapping.
Vi only. Do left‐right scrolling.
Vi only. Set the number of lines in the screen.
Vi only. Modify various search commands and options to work with Lisp. This option is not yet implemented.
Display lines in an unambiguous fashion.
Attempt to get an exclusive lock on any file being edited, read or written.
Treat certain characters specially in regular expressions.
Vi only. The 10th's of a second ex/vi pauses on the matching character when the showmatch option is set.
Permit messages from other users.
Read the first and last few lines of each file for ex commands. This option will never be implemented.
Characters that are never handled as printable characters.
Precede each line displayed with its current line number.
Display unknown characters as octal numbers, instead of the default hexadecimal.
Ex only. If this option is not set, the open and visual commands are disallowed.
Vi only. Optimize text throughput to dumb terminals. This option is not yet implemented.
Vi only. Define additional paragraph boundaries for the { and } commands.
Define additional directories to search for files being edited.
Characters that are always handled as printable characters.
Ex only. Display a command prompt.
Mark the file and session as read‐only.
The directory where recovery files are stored.
Vi only. Simulate an intelligent terminal on a dumb one. This option is not yet implemented.
Remap keys until resolved.
Set the number of lines about which the editor reports changes or yanks.
Vi only. Display a row/column ruler on the colon command line.
Set the number of lines scrolled.
Makes the / and ? commands incremental.
Vi only. Define additional section boundaries for the [[ and ]] commands.
Turns off all access to external programs.
Select the shell used by the editor.
Set the meta characters checked to determine if file name expansion is necessary.
Set the autoindent and shift command indentation width.
Vi only. Note matching “{” and “(” for “}” and “)” characters.
Vi only. Display the current editor mode and a “modified” flag.
Vi only. Set the amount a left‐right scroll will shift.
Delay display updating during text input. This option is not yet implemented.
Read startup files not owned by the current user. This option will never be implemented.
This option sets tab widths for the editor display.
Set the number of significant characters in tag names.
Set the list of tags files.
Set the terminal type.
This option has historically made editor messages less verbose. It has no effect in this implementation.
Modify the ~ command to take an associated motion.
Time out on keys which may be mapped.
Vi only. Select an alternate erase algorithm.
Vi only. Display an error message for every error.
Vi only. Set the window size if the baud rate is less than 1200 baud.
Vi only. Set the window size if the baud rate is equal to 1200 baud.
Vi only. Set the window size if the baud rate is greater than 1200 baud.
Ex only. This option causes a warning message to the terminal if the file has been modified, since it was last written, before a ! command.
Set the window size for the screen.
Change the icon/window name to the current file name even if it can't be restored on editor exit.
Vi 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.
Vi 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.
Set searches to wrap around the end or beginning of the file.
Turn off file‐overwriting checks.

The number of columns on the screen. This value overrides any system or terminal specific values. If the COLUMNS environmental variable is not set when ex/vi runs, or the columns option is explicitly reset by the user, ex/vi enters the value into the environment.
A list of ex startup commands, read if the variable NEXINIT is not set.
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 cd command.
The number of rows on the screen. This value overrides any system or terminal specific values. If the LINES environmental 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.
A list of ex startup commands.
The user's shell of choice (see also the shell option).
The user's terminal type. The default is the type “unknown”. If the TERM environmental 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.
The location used to stored temporary files (see also the directory edit option).

Vi/ex uses this signal for periodic backups of file modifications and to display “busy” messages when operations are likely to take a long time.
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 vi/ex Reference manual section entitled “Recovery” for more information.
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.
The screen is resized. See the vi/ex Reference manual section entitled “Sizing the Screen” for more information.
Vi/ex ignores these signals.

/bin/sh
The default user shell.
/etc/vi.exrc
System‐wide vi startup file.
/tmp
Temporary file directory.
/var/tmp/vi.recover
The default recovery file directory.
$HOME/.nexrc
1st choice for user's home directory startup file.
$HOME/.exrc
2nd choice for user's home directory startup file.
.nexrc
1st choice for local directory startup file.
.exrc
2nd choice for local directory startup file.

ctags(1), more(1), curses(3), dbopen(3)

The “Vi Quick Reference” card.

“An Introduction to Display Editing with Vi”, found in the “UNIX User's Manual Supplementary Documents” section of both the 4.3BSD and 4.4BSD manual sets. This document is the closest thing available to an introduction to the vi screen editor.

“Ex Reference Manual (Version 3.7)”, found in the “UNIX User's Manual Supplementary Documents” section of both the 4.3BSD and 4.4BSD manual sets. This document is the final reference for the ex editor, as distributed in most historic 4BSD and System V systems.

“Edit: A tutorial”, found in the “UNIX User's Manual Supplementary Documents” section of the 4.3BSD manual set. This document is an introduction to a simple version of the ex screen editor.

“Ex/Vi Reference Manual”, found in the “UNIX User's Manual Supplementary Documents” section of the 4.4BSD manual set. This document is the final reference for the nex/nvi text editors, as distributed in 4.4BSD and 4.4BSD‐Lite.

Roff source for all of these documents is distributed with nex/nvi in the nvi/USD.doc directory of the nex/nvi source code.

The files “autowrite”, “input”, “quoting” and “structures” found in the nvi/docs/internals directory of the nex/nvi source code.

The nex/nvi replacements for the ex/vi editor first appeared in 4.4BSD.

Nex/nvi is close to IEEE Std1003.2 (“POSIX”). That document differs from historical ex/vi practice in several places; there are changes to be made on both sides.

%Q% 3rd Berkeley Distribution