Table of Contents

Description

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 reference manual 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/vi programs. This reference manual is accompanied by a traditional-style manual page. That manual page describes the functionality found in ex/vi in far less detail than the description here. In addition, it describes the system interface to ex/vi, e.g. command line options, session recovery, signals, environmental variables, and similar things.

This reference is intended for users already familiar with ex/vi. Anyone else should almost certainly read a good tutorial on the editor first. If you are in an unfamiliar environment, and you absolutely have to get work done immediately, see the section entitled "Fast Startup" in the manual page. It is probably enough to get you started.

There are a few features in nex/nvi that are not found in historic versions of ex/vi. Some of the more interesting of those features are briefly described in the next section, entitled "Additional Features" . For the rest of this document, nex/nvi is used only when it is necessary to distinguish it from the historic implementations of ex/vi.

Future versions of this software will be periodically made available by anonymous ftp, and can be retrieved from ftp.cs.berkeley.edu, in the directory ucb/4bsd.

Additional Features in Nex/Nvi

There are a few features in nex/nvi that are not found in historic versions of ex/vi. Some of the more interesting of these are as follows:

Startup Information

Ex/vi interprets one of two possible environmental variables and reads up to three of five possible files during startup. The variables and files are expected to contain ex commands, not vi commands. In addition, they are interpreted before the file to be edited is read, and therefore many ex commands may not be used. Generally, any command that requires output to the screen or that needs a file upon which to operate, will cause an error if included in a startup file or environmental variable.

Because the ex command set supported by nex/nvi is a superset of the command set supported by historical implementations of ex , nex/nvi can use the startup files created for the historical implementations, but the converse may not be true.

If the -s (the historic - option) is specified, or if standard input is redirected from a file, all environmental variables and startup files are ignored.

Otherwise, startup files and environmental variables are handled in the following order:

  1. The file /etc/vi.exrcis read, as long as it is owned by root or the effective user ID of the user.
  2. The environmental variable NEXINIT(or the variable EXINIT, if NEXINITis not set) is interpreted.
  3. If neither NEXINITor EXINITwas set, and the HOMEenvironmental variable is set, the file $HOME/.nexrc(or the file $HOME/.exrc, if $HOME/.nexrcdoes not exist) is read, as long as the effective user ID of the user is root or is the same as the owner of the file.

    When the $HOME directory is being used for both nex/nvi and an historic implementation of ex/vi, a possible solution is to put nex/nvi specific commands in the .nexrcfile, along with a :source $HOME/.exrc command to read in the commands common to both implementations.

  4. If the exrc option was turned on by one of the previous startup information sources, the file .nexrc(or the file .exrc, if .nexrcdoes not exist) is read, as long as the effective user ID of the user is the same as the owner of the file.

No startup file is read if it is writable by anyone other than its owner.

It is not an error for any of the startup environmental variables or files not to exist.

Once all environmental variables are interpreted, and all startup files are read, the first file to be edited is read in (or a temporary file is created). Then, any commands specified using the -c option are executed, in the context of that file.

Recovery

There is no recovery program for nex/nvi, nor does nex/nvi run setuid. Recovery files are created readable and writable by the owner only. Users may recover any file which they can read, and the superuser may recover any edit session.

Edit sessions are backed by files in the directory named by the recdir option (the directory /var/tmp/vi.recoverby default), and are named "vi.XXXXXX", where "XXXXXX" is a number related to the process ID. When a file is first modified, a second recovery file containing an email message for the user is created, and is named "recover.XXXXXX", where, again, "XXXXXX" is associated with the process ID. Both files are removed at the end of a normal edit session, but will remain if the edit session is abnormally terminated or the user runs the ex preserve command.

The recdir option may be set in either the user's or system's startup information, changing the recovery directory. (Note, however, that if a memory based file system is used as the backup directory, each system reboot will delete all of the recovery files! The same caution applies to directories such as /tmpwhich are cleared of their contents by a system reboot, or /usr/tmpwhich is periodically cleared of old files on many systems.)

The recovery directory should be owned by root, or at least by a pseudo-user. In addition, if directory "sticky-bit" semantics are available, the directory should have the sticky-bit set so that files may only be removed by their owners. The recovery directory must be read, write, and executable by any user, i.e. mode 1777.

If the recovery directory does not exist, ex/vi will attempt to create it. This can result in the recovery directory being owned by a normal user, which means that that user will be able to remove other user's recovery and backup files. This is annoying, but is not a security issue as the user cannot otherwise access or modify the files.

The recovery file has all of the necessary information in it to enable the user to recover the edit session. In addition, it has all of the necessary email headers for sendmail(8). When the system is rebooted, all of the files in /var/tmp/vi.recovernamed "recover.XXXXXX" should be sent to their owners, by email, using the -t option of sendmail (or a similar mechanism in other mailers). If ex/vi receives a hangup (SIGHUP) signal, or the user executes the ex preserve command, ex/vi will automatically email the recovery information to the user.

If your system does not have the sendmail utility (or a mailer program which supports its interface) the source file nvi/common/recover.cwill have to be modified to use your local mail delivery programs. Note, if nex/nvi is changed to use another mailer, it is important to remember that the owner of the file given to the mailer is the nex/nvi user, so nothing in the file should be trusted as it may have been modified in an effort to compromise the system.

Finally, the owner execute bit is set on backup files when they are created, and unset when they are first modified, e.g. backup files that have no associated email recovery file will have this bit set. (There is also a small window where empty files can be created and not yet have this bit set. This is due to the method in which the files are created.) Such files should be deleted when the system reboots.

A simple way to do this cleanup is to run the Bourne shell script recover , from your /etc/rc.local(or other system startup) file. The script should work with the historic Bourne shell, a POSIX 1003.2 shell or the Korn shell. The recover script is installed as part of the nex/nvi installation process.

Consult the manual page for details on recovering preserved or aborted editing sessions.

Sizing the Screen

The size of the screen can be set in a number of ways. Ex/vi takes the following steps until values are obtained for both the number of rows and number of columns in the screen.

  1. If the environmental variable LINESexists, it is used to specify the number of rows in the screen.
  2. If the environmental variable COLUMNSexists, it is used to specify the number of columns in the screen.
  3. The TIOCGWINSZ ioctl(2) is attempted on the standard error file descriptor.
  4. The termcap entry (or terminfo entry on System V machines) is checked for the "li" entry (rows) and the "co" entry (columns).
  5. The number of rows is set to 24, and the number of columns is set to 80.

If a window change size signal (SIGWINCH) is received, the new window size is retrieved using the TIOCGWINSZ ioctl(2) call, and all other information is ignored.

Character Display

In both ex and vi printable characters as defined by isprint(3) are displayed using the local character set.

Non-printable characters, for which iscntrl(3) returns true, and which are less than octal \e040, are displayed as the string "^<character>", where <character>is the character that is the original character's value offset from the "@" character. For example, the octal character \e001 is displayed as "^A". If iscntrl(3) returns true for the octal character \e177, it is displayed as the string "^?". All other characters are displayed as either hexadecimal values, in the form "0x<high-halfbyte> ... 0x<low-halfbyte>", or as octal values, in the form "e<high-one-or-two-bits> ... e<low-three-bits>". The display of unknown characters is based on the value of the octal option.

In vi command mode, the cursor is always positioned on the last column of characters which take up more than one column on the screen. In vi text input mode, the cursor is positioned on the first column of characters which take up more than one column on the screen.

Multiple Screens

Nvi supports multiple screens by dividing the window into regions. It also supports stacks of screens by permitting the user to change the set of screens that are currently displayed.

The Edit , Ex , Fg , Next , Previous , Tag and Visual (in vi mode) commands divide the current screen into two regions of approximately equal size and then perform their usual action in a new screen area. If the cursor is in the lower half of the screen, the screen will split up, i.e. the new screen will be above the old one. If the cursor is in the upper half of the screen, the new screen will be below the old one.

When more than one screen is editing a file, changes in any screen are reflected in all other screens editing the same file. Exiting a screen without saving any changes (or explicitly discarding them) is permitted until the last screen editing the file is exited, at which time the changes must be saved or discarded.

The resize command permits resizing of individual screens. Screens may be grown, shrunk or set to an absolute number of rows.

The ^W command is used to switch between screens. Each ^W moves to the next lower screen in the window, or to the first screen in the window if there are no lower screens.

The bg command "backgrounds" the current screen. The screen disappears from the window, and the rows it occupied are taken over by a neighboring screen. It is an error to attempt to background the only screen in the window.

The display screens command displays the names of the files associated with the current backgrounded screens in the window.

The fg [file] command moves the specified screen from the list of backgrounded screens to the foreground. If no file argument is specified, the first screen on the list is foregrounded. By default, foregrounding consists of backgrounding the current screen, and replacing its space in the window with the foregrounded screen.

Capitalizing the first letter of the command, i.e. Fg , will foreground the backgrounded screen in a new screen instead of swapping it with the current screen.

If the last foregrounded screen in the window is exited, and there are backgrounded screens, the first screen on the list of backgrounded screens takes over the window.

Tags, Tag Stacks, and Cscope

Nvi supports the historic vi tag command <control-]> , and the historic ex tag command tag . These commands change the current file context to a new location, based on information found in the tagsfiles. If you are unfamiliar with these commands, you should review their description in the ex and vi commands section of this manual. For additional information on tags files, see the discussion of the tags edit option and the system ctags(1) manual page.

In addition, nvi supports the notion of "tags stacks", using the <control-T> command. The <control-T> command returns the user to the previous context, i.e., the last place from which a <control-]> or tag command was entered. These three commands provide the basic functionality which allows you to use vi to review source code in a structured manner.

Nvi also provides two other basic ex commands for tag support: tagpop and tagtop . The tagpop command is identical to the <control-T> command, with the additional functionality that you may specify that modifications to the current file are to be discarded. This cannot be done using the <control-T> command. The tagtop command discards all of the contexts that have been pushed onto the tag stack, returning to the context from which the first <control-]> or tag command was entered.

The historic ctags(1) tags file format supports only a single location per tag, normally the function declaration or structure or string definition. More sophisticated source code tools often provide multiple locations per tag, e.g., a list of the places from which a function is called or a string definition is used. An example of this functionality is the System V source code tool, cscope .

Cscope creates a database of information on source code files, and supports a query language for that information as described in the cscope(1) manual page. Nvi contains an interface to the cscope query language which permits you to query cscope and then sequentially step through the locations in the sources files which cscope returns. There are two nvi commands which support this ability to step through multiple locations. They are the ex commands tagnext and tagprev . The tagnext command moves to the next location for the current tag. The tagprev command moves to the previous location for the current tag. (See the tagnext and tagprev command discussion in the ex commands section of this manual for more information.) At any time during this sequential walk, you may use the <control-]> , tag or cscope commands to move to a new tag context, and then use the <control-T> or tagpop commands to return and continue stepping through the locations for this tag. This is similar to the previous model of a simple tag stack, except that each entry in the tag stack may have more than one file context that is of interest.

Although there is no widely distributed version of ctags(1) that creates tags files with multiple locations per tag, nvi has been written to understand the obvious extension to the historic tags file format, i.e., more than a single line in the tags file with the same initial tag name. If you wish to extend your ctags implementation or other tool with which you build tags files, this extension should be simple and will require no changes to nvi .

The nvi and cscope interface is based on the new ex command cscope , which has five subcommands: add , find , help , kill and reset . The subcommand find itself has eight subcommands: c , d , e , f , g , i , s and t .

Cscope is not freely redistributable software, but is fairly inexpensive and easily available. To purchase a copy of cscope , see http://www.att.com/ssg/products/toolchest.html.

Regular Expressions and Replacement Strings

Regular expressions are used in line addresses, as the first part of the ex substitute , global , and v commands, and in search patterns.

The regular expressions supported by ex/vi are, by default, the Basic Regular Expressions (BRE's) described in the IEEE POSIX Standard 1003.2. The extended option causes all regular expressions to be interpreted as the Extended Regular Expressions (ERE's) described by the same standard. (See re_format(7) for more information.) Generally speaking, BRE's are the Regular Expressions found in ed(1) and grep(1), and ERE's are the Regular Expressions found in egrep(1).

The following is not intended to provide a description of Regular Expressions. The information here only describes strings and characters which have special meanings in the ex/vi version of RE's, or options which change the meanings of characters that normally have special meanings in RE's.

  1. An empty RE (e.g. "//" or "??" is equivalent to the last RE used.
  2. The construct "e<" matches the beginning of a word.
  3. The construct "e>" matches the end of a word.
  4. The character "~" matches the replacement part of the last substitute command.

When the magic option is not set, the only characters with special meanings are a "^" character at the beginning of an RE, a "$" character at the end of an RE, and the escaping character "e". The characters ".", "*", "[" and "~" are treated as ordinary characters unless preceded by a "e"; when preceded by a "e" they regain their special meaning.

Replacement strings are the second part of a substitute command.

The character "&" (or "e&" if the magic option is not set) in the replacement string stands for the text matched by the RE that is being replaced. The character "~" (or "e~" if the magic option is not set) stands for the replacement part of the previous substitute command. It is only valid after a substitute command has been performed.

The string "e#", where "#" is an integer value from 1 to 9, stands for the text matched by the portion of the RE enclosed in the "#"'th set of escaped parentheses, e.g. "e(" and "e)". For example, "s/abce(.*e)def/e1/" deletes the strings "abc" and "def" from the matched pattern.

The strings "el", "eu", "eL" and "eU" can be used to modify the case of elements in the replacement string. The string "el" causes the next character to be converted to lowercase; the string "eu" behaves similarly, but converts to uppercase (e.g. s/abc/eU&/replaces the string abcwith ABC). The string "eL" causes characters up to the end of the string or the next occurrence of the strings "ee" or "eE" to be converted to lowercase; the string "eU" behaves similarly, but converts to uppercase.

If the entire replacement pattern is "%", then the last replacement pattern is used again.

In vi , inserting a <control-M>into the replacement string will cause the matched line to be split into two lines at that point. (The <control-M>will be discarded.)

Scripting Languages

The nvi editor currently supports two scripting languages, Tcl/Tk and Perl. (Note that Perl4 isn't sufficient, and that the Perl5 used must be version 5.002 or later. See the "Building Nvi" section for more information.

The scripting language interface is still being worked on, therefore the following information is probably incomplete, probably wrong in cases, and likely to change. See the perl_apiand tcl_apisource directories for more information. As a quick reference, the following function calls are provided for both the Perl and Tcl interfaces. The Perl interface uses a slightly different naming convention, e.g. "viFindScreen" is named "VI::FindScreen".

General Editor Description

When ex or vi are executed, the text of a file is read (or a temporary file is created), and then all editing changes happen within the context of the copy of the file. No changes affect the actual file until the file is written out, either using a write command or another command which is affected by the autowrite option.

All files are locked (using the flock(2) or fcntl(2) interfaces) during the edit session, to avoid inadvertently making modifications to multiple copies of the file. If a lock cannot be obtained for a file because it is locked by another process, the edit session is read-only (as if the readonly option or the -R flag had been specified). If a lock cannot be obtained for other reasons, the edit session will continue, but the file status information (see the <control-G> command) will reflect this fact.

Both ex and vi are modeful editors, i.e. they have two modes, "command" mode and "text input" mode. The former is intended to permit you to enter commands which modifies already existing text. The latter is intended to permit you to enter new text. When ex first starts running, it is in command mode, and usually displays a prompt (see the prompt option for more information). The prompt is a single colon ":" character. There are three commands that switch ex into text input mode: append , change and insert . Once in input mode, entering a line containing only a single period "." ends text input mode and returns to command mode, where the prompt is redisplayed.

When vi first starts running, it is in command mode as well. There are eleven commands that switch vi into text input mode: A , a , C , c , I , i , O , o , R , S and s . Once in input mode, entering an <escape>character ends text input mode and returns to command mode.

Ex/vi present three different interfaces to editing a file. Ex presents a line oriented interface. Vi presents a full screen display oriented interface, also known as "visual mode". In addition, there is a third mode, "open mode", which is line oriented, but supports cursor movement and editing within the displayed line, similarly to visual mode. Open mode is not yet implemented in nvi .

The following words have special meanings in both the ex and vi command descriptions:

Vi Description

Vi takes up the entire screen to display the edited file, except for the bottom line of the screen. The bottom line of the screen is used to enter exp commands, and for vi error and informational messages. If no other information is being displayed, the default display can show the current cursor row and cursor column, an indication of whether the file has been modified, and the current mode of the editor. See the ruler and showmode options for more information.

Empty lines do not have any special representation on the screen, but lines on the screen that would logically come after the end of the file are displayed as a single tilde "~" character. To differentiate between empty lines and lines consisting of only whitespace characters, use the list option. Historically, implementations of vi have also displayed some lines as single asterisk "@" characters. These were lines that were not correctly displayed, i.e. lines on the screen that did not correspond to lines in the file, or lines that did not fit on the current screen. Nvi never displays lines in this fashion.

Vi is a modeful editor, i.e. it has two modes, "command" mode and "text input" mode. When vi first starts, it is in command mode. There are several commands that change vi into text input mode. The <escape>character is used to resolve the text input into the file, and exit back into command mode. In vi command mode, the cursor is always positioned on the last column of characters which take up more than one column on the screen. In vi text insert mode, the cursor is positioned on the first column of characters which take up more than one column on the screen.

When positioning the cursor to a new line and column, the type of movement is defined by the distance to the new cursor position. If the new position is close, the screen is scrolled to the new location. If the new position is far away, the screen is repainted so that the new position is on the screen. If the screen is scrolled, it is moved a minimal amount, and the cursor line will usually appear at the top or bottom of the screen. If the screen is repainted, the cursor line will appear in the center of the screen, unless the cursor is sufficiently close to the beginning or end of the file that this isn't possible. If the leftright option is set, the screen may be scrolled or repainted in a horizontal direction as well as in a vertical one.

A major difference between the historical vi presentation and nvi is in the scrolling and screen oriented position commands, <control-B>, <control-D>, <control-E>, <control-F>, <control-U>, <control-Y>, H, L and M. In historical implementations of vi, these commands acted on physical (as opposed to logical, or screen) lines. For lines that were sufficiently long in relation to the size of the screen, this meant that single line scroll commands might repaint the entire screen, scrolling or screen positioning commands might not change the screen or move the cursor at all, and some lines simply could not be displayed, even though vi would edit the file that contained them. In nvi, these commands act on logical, i.e. screen lines. You are unlikely to notice any difference unless you are editing files with lines significantly longer than a screen width.

Vi keeps track of the currently "most attractive" cursor position. Each command description (for commands that alter the current cursor position), specifies if the cursor is set to a specific location in the line, or if it is moved to the "most attractive cursor position". The latter means that the cursor is moved to the cursor position that is horizontally as close as possible to the current cursor position. If the current line is shorter than the cursor position vi would select, the cursor is positioned on the last character in the line. (If the line is empty, the cursor is positioned on the first column of the line.) If a command moves the cursor to the most attractive position, it does not alter the current cursor position, and a subsequent movement will again attempt to move the cursor to that position. Therefore, although a movement to a line shorter than the currently most attractive position will cause the cursor to move to the end of that line, a subsequent movement to a longer line will cause the cursor to move back to the most attractive position.

In addition, the $ command makes the end of each line the most attractive cursor position rather than a specific column.

Each vi command described below notes where the cursor ends up after it is executed. This position is described in terms of characters on the line, i.e. "the previous character", or, "the last character in the line". This is to avoid needing to continually refer to on what part of the character the cursor rests.

The following words have special meaning for vi commands.

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. In addition, the final line and column the cursor rests upon, and any options which affect the command are noted.

[count] Command

Search forward counttimes for the current word. The current word begins at the first non-whitespace character on or after the current cursor position, and extends up to the next non-word character or the end of the line. The search is literal, i.e. no characters in the word have any special meaning in terms of Regular Expressions. It is an error if no matching pattern is found between the starting position and the end of the file.

The <control-A> command is an absolute movement. The <control-A> command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Set to the line where the word is found.
Column:
Set to the first character of the word.
Options:
Affected by the ignorecase and wrapscan options.

[count] Command

Page backward countscreens. Two lines of overlap are maintained, if possible, by displaying the window starting at line (top_line - count * window_size) + 2, where window_sizeis the value of the window option. (In the case of split screens, this size is corrected to the current screen size.) It is an error if the movement is past the beginning of the file.

Line:
Set to the last line of text displayed on the screen.
Column:
Set to the first nonblank character of the line.
Options:
Affected by the window option.

[count] Command

Scroll forward countlines. If countis not specified, scroll forward the number of lines specified by the last <control-D> or <control-U> command. If this is the first <control-D> or <control-U> command, scroll forward half the number of lines in the screen. (In the case of split screens, the default scrolling distance is corrected to half the current screen size.) It is an error if the movement is past the end of the file.

Line:
Set to the current line plus the number of lines scrolled.
Column:
Set to the first nonblank character of the line.
Options:
None.

[count] Command

Scroll forward countlines, leaving the cursor on the current line and column, if possible. It is an error if the movement is past the end of the file.

Line:
Unchanged unless the current line scrolls off the screen, in which case it is set to the first line on the screen.
Column:
Unchanged unless the current line scrolls off the screen, in which case it is set to the most attractive cursor position.
Options:
None.

[count] Command

Page forward countscreens. Two lines of overlap are maintained, if possible, by displaying the window starting at line top_line + count * window_size - 2, where window_sizeis the value of the window option. (In the case of split screens, this size is corrected to the current screen size.) It is an error if the movement is past the end of the file.

Line:
Set to the first line on the screen.
Column:
Set to the first nonblank character of the current line.
Options:
Affected by the window option.

Command

Display the file information. The information includes the current pathname, the current line, the number of total lines in the file, the current line as a percentage of the total lines in the file, if the file has been modified, was able to be locked, if the file's name has been changed, and if the edit session is read-only.

Line:
Unchanged.
Column:
Unchanged.
Options:
None.

[count] Command
[count] h Command
Move the cursor back countcharacters in the current line. It is an error if the cursor is on the first character in the line.

The <control-H> and h commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the current - countcharacter, or, the first character in the line if countis greater than or equal to the number of characters in the line before the cursor.
Options:
None.

[count] Command
[count] Command
[count] j Command
Move the cursor down countlines without changing the current column. It is an error if the movement is past the end of the file.

The <control-J>, <control-N> and j commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the current line plus count.
Column:
The most attractive cursor position.
Options:
None.

Command
Command
Repaint the screen.
Line:
Unchanged.
Column:
Unchanged.
Options:
None.

[count] Command
[count] + Command
Move the cursor down countlines to the first nonblank character of that line. It is an error if the movement is past the end of the file.

The <control-M> and + commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the current line plus count.
Column:
Set to the first nonblank character in the line.
Options:
None.

[count] Command
[count] k Command
Move the cursor up countlines, without changing the current column. It is an error if the movement is past the beginning of the file.

The <control-P> and k commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the current line minus count.
Column:
The most attractive cursor position.
Options:
None.

Command

Return to the most recent tag context. The <control-T> command is an absolute movement.

Line:
Set to the context of the previous tag command.
Column:
Set to the context of the previous tag command.
Options:
None.

[count] Command

Scroll backward countlines. If countis not specified, scroll backward the number of lines specified by the last <control-D> or <control-U> command. If this is the first <control-D> or <control-U> command, scroll backward half the number of lines in the screen. (In the case of split screens, the default scrolling distance is corrected to half the current screen size.) It is an error if the movement is past the beginning of the file.

Line:
Set to the current line minus the amount scrolled.
Column:
Set to the first nonblank character in the line.
Options:
None.

Command

Switch to the next lower screen in the window, or, to the first screen if there are no lower screens in the window.

Line:
Set to the previous cursor position in the window.
Column:
Set to the previous cursor position in the window.
Options:
None.

[count] Command

Scroll backward countlines, leaving the current line and column as is, if possible. It is an error if the movement is past the beginning of the file.

Line:
Unchanged unless the current line scrolls off the screen, in which case it is set to the last line of text displayed on the screen.
Column:
Unchanged unless the current line scrolls off the screen, in which case it is the most attractive cursor position.
Options:
None.

Command

Suspend the current editor session. If the file has been modified since it was last completely written, and the autowrite option is set, the file is written before the editor session is suspended. If this write fails, the editor session is not suspended.

Line:
Unchanged.
Column:
Unchanged.
Options:
Affected by the autowrite option.

Command

Execute ex commands or cancel partial commands. If an ex command is being entered (e.g. /, ?, : or !), the command is executed. If a partial command has been entered, e.g. "[0-9]*", or "[0-9]*[!<>cdy]", the command is cancelled. Otherwise, it is an error.

Line:
When an ex command is being executed, the current line is set as described for that command. Otherwise, unchanged.
Column:
When an ex command is being executed, the current column is set as described for that command. Otherwise, unchanged.
Options:
None.

Command

Push a tag reference onto the tag stack. The tags files (see the tags option for more information) are searched for a tag matching the current word. The current word begins at the first non-whitespace character on or after the current cursor position, and extends up to the next non-word character or the end of the line. If a matching tag is found, the current file is discarded and the file containing the tag reference is edited.

If the current file has been modified since it was last completely written, the command will fail. The <control-]> command is an absolute movement.

Line:
Set to the line containing the matching tag string.
Column:
Set to the start of the matching tag string.
Options:
Affected by the tags and taglength options.

Command

Switch to the most recently edited file.

If the file has been modified since it was last completely written, and the autowrite option is set, the file is written out. If this write fails, the command will fail. Otherwise, if the current file has been modified since it was last completely written, the command will fail.

Line:
Set to the line the cursor was on when the file was last edited.
Column:
Set to the column the cursor was on when the file was last edited.
Options:
Affected by the autowrite option.

[count] Command
[count] l Command
Move the cursor forward countcharacters without changing the current line. It is an error if the cursor is on the last character in the line.

The <space> and l commands may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented. In addition, these commands may be used as the motion components of other commands when the cursor is on the last character in the line, without error.

Line:
Unchanged.
Column:
Set to the current character plus the next countcharacters, or to the last character on the line if countis greater than the number of characters in the line after the current character.
Options:
None.

[count] ! motion shell-argument(s) Command

Replace text with results from a shell command. Pass the lines specified by the countand motionarguments as standard input to the program named by the shell option, and replace those lines with the output (both standard error and standard output) of that command.

After the motion is entered, vi prompts for arguments to the shell command.

Within those arguments, "%" and "#" characters are expanded to the current and alternate pathnames, respectively. The "!" character is expanded with the command text of the previous ! or :! commands. (Therefore, the command !<motion>! repeats the previous ! command.) The special meanings of "%", "#" and "!" can be overridden by escaping them with a backslash. If no ! or :! command has yet been executed, it is an error to use an unescaped "!" character as a shell argument. The ! command does not do shell expansion on the strings provided as arguments. If any of the above expansions change the arguments the user entered, the command is redisplayed at the bottom of the screen.

Vi then executes the program named by the shell option, with a -c flag followed by the arguments (which are bundled into a single argument).

The ! command is permitted in an empty file.

If the file has been modified since it was last completely written, the ! command will warn you.

Line:
The first line of the replaced text.
Column:
The first column of the replaced text.
Options:
Affected by the shell option.

[count] # #|+|- Command

Increment or decrement the number referenced by the cursor. If the trailing character is a +or #, the number is incremented by count. If the trailing character is a -, the number is decremented by count.

A leading "0X" or "0x" causes the number to be interpreted as a hexadecimal number. Otherwise, a leading "0" causes the number to be interpreted as an octal number, unless a non-octal digit is found as part of the number. Otherwise, the number is interpreted as a decimal number, and may have a leading +or -sign. The current number begins at the first non-blank character at or after the current cursor position, and extends up to the end of the line or the first character that isn't a possible character for the numeric type. The format of the number (e.g. leading 0's, signs) is retained unless the new value cannot be represented in the previous format.

Octal and hexadecimal numbers, and the result of the operation, must fit into an "unsigned long". Similarly, decimal numbers and their result must fit into a "signed long". It is an error to use this command when the cursor is not positioned at a number.

Line:
Unchanged.
Column:
Set to the first character in the cursor number.
Options:
None.

[count] $ Command

Move the cursor to the end of a line. If countis specified, the cursor moves down count - 1lines.

It is not an error to use the $ command when the cursor is on the last character in the line or when the line is empty.

The $ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the cursor is at, or before the first nonblank character in the line, in which case it is line oriented. It is not an error to use the $ command as a motion component when the cursor is on the last character in the line, although it is an error when the line is empty.

Line:
Set to the current line plus countminus 1.
Column:
Set to the last character in the line.
Options:
None.

% Command

Move to the matching character. The cursor moves to the parenthesis or curly brace which matches the parenthesis or curly brace found at the current cursor position or which is the closest one to the right of the cursor on the line. It is an error to execute the % command on a line without a parenthesis or curly brace. Historically, any countspecified to the % command was ignored.

The % command is an absolute movement. The % command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting point of the region is at or before the first nonblank character on its line, and the ending point is at or after the last nonblank character on its line, in which case it is line oriented.

Line:
Set to the line containing the matching character.
Column:
Set to the matching character.
Options:
None.

& Command

Repeat the previous substitution command on the current line.

Historically, any countspecified to the & command was ignored.

Line:
Unchanged.
Column:
Unchanged if the cursor was on the last character in the line, otherwise, set to the first nonblank character in the line.
Options:
Affected by the edcompatible, extended, ignorecase and magic options.

' Command
` Command
Return to a context marked by the character <character>. If <character>is the "'" or "`" character, return to the previous context. If <character>is any other character, return to the context marked by that character (see the m command for more information). If the command is the ' command, only the line value is restored, and the cursor is placed on the first nonblank character of that line. If the command is the ` command, both the line and column values are restored.

It is an error if the context no longer exists because of line deletion. (Contexts follow lines that are moved, or which are deleted and then restored.)

The ' and ` commands are both absolute movements. They may be used as a motion component for other vi commands. For the ' command, any text copied into a buffer is line oriented. For the ` command, any text copied into a buffer is character oriented, unless it both starts and stops at the first character in the line, in which case it is line oriented. In addition, when using the ` command as a motion component, commands which move backward and started at the first character in the line, or move forward and ended at the first character in the line, are corrected to the last character of the line preceding the starting and ending lines, respectively.

Line:
Set to the line from the context.
Column:
Set to the first nonblank character in the line, for the ' command, and set to the context's column for the ` command.
Options:
None.

[count] ( Command

Back up countsentences.

The ( command is an absolute movement. The ( command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting and stopping points of the region are the first character in the line, in which case it is line oriented. If it is line oriented, the starting point of the region is adjusted to be the end of the line immediately before the starting cursor position.

Line:
Set to the line containing the beginning of the sentence.
Column:
Set to the first nonblank character of the sentence.
Options:
Affected by the lisp option.

[count] ) Command

Move forward countsentences.

The ) command is an absolute movement. The ) command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting point of the region is the first character in the line, in which case it is line oriented. In the latter case, if the stopping point of the region is also the first character in the line, it is adjusted to be the end of the line immediately before it.

Line:
Set to the line containing the beginning of the sentence.
Column:
Set to the first nonblank character of the sentence.
Options:
Affected by the lisp option.

[count] , Command

Reverse find character counttimes. Reverse the last F, f, T or t command, searching the other way in the line, counttimes. It is an error if a F, f, T or t command has not been performed yet.

The , command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the searched-for character for the F and f commands, before the character for the t command and after the character for the T command.
Options:
None.

[count] - Command

Move to the first nonblank of the previous line, counttimes.

It is an error if the movement is past the beginning of the file.

The - command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the current line minus count.
Column:
Set to the first nonblank character in the line.
Options:
None.

[count] . Command

Repeat the last vi command that modified text. The repeated command may be a command and motion component combination. If countis specified, it replaces both the count specified for the repeated command, and, if applicable, for the repeated motion component. If countis not specified, the counts originally specified to the command being repeated are used again.

As a special case, if the . command is executed immediately after the u command, the change log is rolled forward or backward, depending on the action of the u command.

Line:
Set as described for the repeated command.
Column:
Set as described for the repeated command.
Options:
None.

/RE Command
/RE/ [ Command
?RE Command
?RE? [ Command
N Command
n Command
Search forward or backward for a regular expression. The commands beginning with a slash "/" character are forward searches, the commands beginning with a question mark "?" are backward searches. Vi prompts with the leading character on the last line of the screen for a string. It then searches forward or backward in the file for the next occurrence of the string, which is interpreted as a Basic Regular Expression.

The / and ? commands are absolute movements. They may be used as the motion components of other vi commands, in which case any text copied into a buffer is character oriented, unless the search started and ended on the first column of a line, in which case it is line oriented. In addition, forward searches ending at the first character of a line, and backward searches beginning at the first character in the line, are corrected to begin or end at the last character of the previous line. (Note, forward and backward searches can occur for both / and ? commands, if the wrapscan option is set.)

If an offset from the matched line is specified (i.e. a trailing "/" or "?" character is followed by a signed offset), the buffer will always be line oriented (e.g. "/string/+0" will always guarantee a line orientation).

The N command repeats the previous search, but in the reverse direction. The n command repeats the previous search. If either the N or n commands are used as motion components for the ! command, you will not be prompted for the text of the bang command, instead the previous bang command will be executed.

Missing RE's (e.g. "//<carriage-return>", "/<carriage-return>", "??<carriage-return>", or "?<carriage-return>" search for the last search RE, in the indicated direction.

Searches may be interrupted using the <interrupt>character.

Multiple search patterns may be grouped together by delimiting them with semicolons and zero or more whitespace characters, e.g. /foo/ ; ?bar?searches forward for fooand then, from that location, backwards for bar. When search patterns are grouped together in this manner, the search patterns are evaluated left to right with the final cursor position determined by the last search pattern.

It is also permissible to append a z command to the search strings, e.g. /foo/ z.searches forward for the next occurrence of foo, and then positions that line in the middle of screen.

Line:
Set to the line in which the match occurred.
Column:
Set to the first character of the matched string.
Options:
Affected by the edcompatible, extended, ignorecase, magic, and wrapscan options.

0 Command

Move to the first character in the current line. It is not an error to use the 0 command when the cursor is on the first character in the line,

The 0 command may be used as the motion component of other vi commands, in which case it is an error if the cursor is on the first character in the line, and any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the first character in the line.
Options:
None.

: Command

Execute an ex command. Vi prompts for an ex command on the last line of the screen, using a colon ":" character. The command is terminated by a <carriage-return>, <newline>or <escape>character; all of these characters may be escaped by using a <literal-next>character. The command is then executed.

If the ex command writes to the screen, vi will prompt the user for a <carriage-return>before continuing when the ex command finishes. Large amounts of output from the ex command will be paged for the user, and the user prompted for a <carriage-return>or <space>key to continue. In some cases, a quit (normally a "q" character) or <interrupt>may be entered to interrupt the ex command.

When the ex command finishes, and the user is prompted to resume visual mode, it is also possible to enter another ":" character followed by another ex command.

Line:
The current line is set as described for the ex command.
Column:
The current column is set as described for the ex command.
Options:
Affected as described for the ex command.

[count] ; Command

Repeat the last character find counttimes. The last character find is one of the F, f, T or t commands. It is an error if a F, f, T or t command has not been performed yet.

The ; command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the searched-for character for the F and f commands, before the character for the t command and after the character for the T command.
Options:
None.

[count] < motion Command
[count] > motion Command
Shift lines left or right. Shift the number of lines in the region specified by the countand motionleft (for the < command) or right (for the > command) by the number of columns specified by the shiftwidth option. Only whitespace characters are deleted when shifting left. Once the first character in the line no longer contains a whitespace character, the command will succeed, but the line will not be modified.
Line:
Unchanged.
Column:
Set to the first nonblank character in the line.
Options:
Affected by the shiftwidth option.

@@ buffer Command

Execute a named buffer. Execute the named buffer as vi commands. The buffer may include ex commands, too, but they must be expressed as a : command. If the buffer is line oriented, <newline>characters are logically appended to each line of the buffer. If the buffer is character oriented, <newline>characters are logically appended to all but the last line in the buffer.

If the buffer name is "@", or "*", then the last buffer executed shall be used. It is an error to specify "@@" or "@*" if there were no previous buffer executions. The text of a buffer may contain a @ command, and it is possible to create infinite loops in this manner. (The <interrupt>character may be used to interrupt the loop.)

Line:
The current line is set as described for the command(s).
Column:
The current column is set as described for the command(s).
Options:
None.

[count] A Command

Enter input mode, appending the text after the end of the line. If countis specified, the text is repeatedly input count - 1more times after input mode is exited.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[count] B Command

Move backward countbigwords. Move the cursor backward to the beginning of a bigword by repeating the following algorithm: if the current position is at the beginning of a bigword or the character at the current position cannot be part of a bigword, move to the first character of the preceding bigword. Otherwise, move to the first character of the bigword at the current position. If no preceding bigword exists on the current line, move to the first character of the last bigword on the first preceding line that contains a bigword.

The B command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Set to the line containing the word selected.
Column:
Set to the first character of the word selected.
Options:
None.

[buffer] [count] C Command

Change text from the current position to the end-of-line. If countis specified, the input text replaces from the current position to the end-of-line, plus count - 1subsequent lines.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[buffer] D Command

Delete text from the current position to the end-of-line.

It is not an error to execute the D command on an empty line.

Line:
Unchanged.
Column:
Set to the character before the current character, or, column 1 if the cursor was on column 1.
Options:
None.

[count] E Command

Move forward countend-of-bigwords. Move the cursor forward to the end of a bigword by repeating the following algorithm: if the current position is the end of a bigword or the character at that position cannot be part of a bigword, move to the last character of the following bigword. Otherwise, move to the last character of the bigword at the current position. If no succeeding bigword exists on the current line, move to the last character of the first bigword on the next following line that contains a bigword.

The E command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Set to the line containing the word selected.
Column:
Set to the last character of the word selected.
Options:
None.

[count] F Command

Search counttimes backward through the current line for <character>.

The F command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the searched-for character.
Options:
None.

[count] G Command

Move to line count, or the last line of the file if countnot specified.

The G command is an absolute movement. The G command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to count, if specified, otherwise, the last line.
Column:
Set to the first nonblank character in the line.
Options:
None.

[count] H Command

Move to the screen line count - 1lines below the top of the screen.

The H command is an absolute movement. The H command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the line count - 1lines below the top of the screen.
Column:
Set to the first nonblank character of the screen line.
Options:
None.

[count] I Command

Enter input mode, inserting the text at the beginning of the line. If countis specified, the text input is repeatedly input count - 1more times.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
None.

[count] J Command

Join lines. If countis specified, countlines are joined; a minimum of two lines are always joined, regardless of the value of count.

If the current line ends with a whitespace character, all whitespace is stripped from the next line. Otherwise, if the next line starts with a open parenthesis "(" do nothing. Otherwise, if the current line ends with a question mark "?", period "." or exclamation point "!", insert two spaces. Otherwise, insert a single space.

It is not an error to join lines past the end of the file, i.e. lines that do not exist.

Line:
Unchanged.
Column:
Set to the character after the last character of the next-to-last joined line.
Options:
None.

[count] L Command

Move to the screen line count - 1lines above the bottom of the screen.

The L command is an absolute movement. The L command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Line:
Set to the line count - 1lines above the bottom of the screen.
Column:
Set to the first nonblank character of the screen line.
Options:
None.

M Command

Move to the screen line in the middle of the screen.

The M command is an absolute movement. The M command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

Historically, any countspecified to the M command was ignored.

Line:
Set to the line in the middle of the screen.
Column:
Set to the first nonblank character of the screen line.
Options:
None.

[count] O Command

Enter input mode, appending text in a new line above the current line. If countis specified, the text input is repeatedly input count - 1more times.

Historically, any countspecified to the O command was ignored.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[buffer] P Command

Insert text from a buffer. Text from the buffer (the unnamed buffer by default) is inserted before the current column or, if the buffer is line oriented, before the current line.

Line:
Set to the lowest numbered line insert, if the buffer is line oriented, otherwise unchanged.
Column:
Set to the first nonblank character of the appended text, if the buffer is line oriented, otherwise, the last character of the appended text.
Options:
None.

Q Command

Exit vi (or visual) mode and switch to ex mode.

Line:
Unchanged.
Column:
No longer relevant.
Options:
None.

[count] R Command

Enter input mode, replacing the characters in the current line. If countis specified, the text input is repeatedly input count - 1more times.

If the end of the current line is reached, no more characters are replaced and any further characters input are appended to the line.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[buffer] [count] S Command

Substitute countlines.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[count] T Command

Search backward, counttimes, through the current line for the character after the specified <character>.

The T command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the character after the searched-for character.
Options:
None.

U Command

Restore the current line to its state before the cursor last moved to it.

Line:
Unchanged.
Column:
The first character in the line.
Options:
None.

[count] W Command

Move forward countbigwords. Move the cursor forward to the beginning of a bigword by repeating the following algorithm: if the current position is within a bigword or the character at that position cannot be part of a bigword, move to the first character of the next bigword. If no subsequent bigword exists on the current line, move to the first character of the first bigword on the first following line that contains a bigword.

The W command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
The line containing the word selected.
Column:
The first character of the word selected.
Options:
None.

[buffer] [count] X Command

Delete countcharacters before the cursor. If the number of characters to be deleted is greater than or equal to the number of characters to the beginning of the line, all of the characters before the current cursor position, to the beginning of the line, are deleted.

Line:
Unchanged.
Column:
Set to the current character minus count, or the first character if count is greater than the number of characters in the line before the cursor.
Options:
None.

[buffer] [count] Y Command

Copy (or "yank") countlines into the specified buffer.

Line:
Unchanged.
Column:
Unchanged.
Options:
None.

ZZ Command

Write the file and exit vi. The file is only written if it has been modified since the last complete write of the file to any file.

The ZZ command will exit the editor after writing the file, if there are no further files to edit. Entering two "quit" commands (i.e. wq, quit, xit or ZZ) in a row will override this check and the editor will exit, ignoring any files that have not yet been edited.

Line:
Unchanged.
Column:
Unchanged.
Options:
None.

[count] [[ Command

Back up countsection boundaries.

The [[ command is an absolute movement. The [[ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting position is column 0, in which case it is line oriented.

It is an error if the movement is past the beginning of the file.

Line:
Set to the previous line that is countsection boundaries back, or the first line of the file if no more section boundaries exist preceding the current line.
Column:
Set to the first nonblank character in the line.
Options:
Affected by the sections option.

[count] ]] Command

Move forward countsection boundaries.

The ]] command is an absolute movement. The ]] command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented, unless the starting position is column 0, in which case it is line oriented.

It is an error if the movement is past the end of the file.

Line:
Set to the line that is countsection boundaries forward, or to the last line of the file if no more section boundaries exist following the current line.
Column:
Set to the first nonblank character in the line.
Options:
Affected by the sections option.

^ Command

Move to first nonblank character on the current line.

The ^ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the first nonblank character of the current line.
Options:
None.

[count] _ Command

Move down count - 1lines, to the first nonblank character. The _ command may be used as the motion component of other vi commands, in which case any text copied into a buffer is line oriented.

It is not an error to execute the _ command when the cursor is on the first character in the line.

Line:
The current line plus count - 1.
Column:
The first nonblank character in the line.
Options:
None.

[count] a Command

Enter input mode, appending the text after the cursor. If countis specified, the text input is repeatedly input count - 1more times.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[count] b Command

Move backward countwords. Move the cursor backward to the beginning of a word by repeating the following algorithm: if the current position is at the beginning of a word, move to the first character of the preceding word. Otherwise, the current position moves to the first character of the word at the current position. If no preceding word exists on the current line, move to the first character of the last word on the first preceding line that contains a word.

The b command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Set to the line containing the word selected.
Column:
Set to the first character of the word selected.
Options:
None.

[buffer] [count] c motion Command

Change the region of text specified by the countand motion. If only part of a single line is affected, then the last character being changed is marked with a "$". Otherwise, the region of text is deleted, and input mode is entered.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[buffer] [count] d motion Command

Delete the region of text specified by the countand motion.

Line:
Set to the line where the region starts.
Column:
Set to the first character in the line after the last character in the region. If no such character exists, set to the last character before the region.
Options:
None.

[count] e Command

Move forward countend-of-words. Move the cursor forward to the end of a word by repeating the following algorithm: if the current position is the end of a word, move to the last character of the following word. Otherwise, move to the last character of the word at the current position. If no succeeding word exists on the current line, move to the last character of the first word on the next following line that contains a word.

The e command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Set to the line containing the word selected.
Column:
Set to the last character of the word selected.
Options:
None.

[count] f Command

Search forward, counttimes, through the rest of the current line for <character>.

The f command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the searched-for character.
Options:
None.

[count] i Command

Enter input mode, inserting the text before the cursor. If countis specified, the text input is repeatedly input count - 1more times.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

m Command

Save the current context (line and column) as <character>. The exact position is referred to by "`<character>". The line is referred to by "'<character>".

Historically, <character>was restricted to lower-case letters. Nvi permits the use of any character.

Line:
Unchanged.
Column:
Unchanged.
Options:
None.

[count] o Command

Enter input mode, appending text in a new line under the current line. If countis specified, the text input is repeatedly input count - 1more times.

Historically, any countspecified to the o command was ignored.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[buffer] p Command

Append text from a buffer. Text from the buffer (the unnamed buffer by default) is appended after the current column or, if the buffer is line oriented, after the current line.

Line:
Set to the first line appended, if the buffer is line oriented, otherwise unchanged.
Column:
Set to the first nonblank character of the appended text if the buffer is line oriented, otherwise, the last character of the appended text.
Options:
None.

[count] r Command

Replace characters. The next countcharacters in the line are replaced with <character>. Replacing characters with <newline>characters results in creating new, empty lines into the file.

If <character>is <escape>, the command is cancelled.

Line:
Unchanged unless the replacement character is a <newline>, in which case it is set to the current line plus count - 1.
Column:
Set to the last character replaced, unless the replacement character is a <newline>, in which case the cursor is in column 1 of the last line inserted.
Options:
None.

[buffer] [count] s Command

Substitute countcharacters in the current line starting with the current character.

Line:
Set to the last line upon which characters were entered.
Column:
Set to the last character entered.
Options:
Affected by the altwerase, autoindent, beautify, showmatch, ttywerase and wrapmargin options.

[count] t Command

Search forward, counttimes, through the current line for the character immediately before <character>.

The t command may be used as the motion component of other vi commands, in which case any text copied into a buffer is character oriented.

Line:
Unchanged.
Column:
Set to the character before the searched-for character.
Options:
None.

u Command

Undo the last change made to the file. If repeated, the u command alternates between these two states, and is its own inverse. When used after an insert that inserted text on more than one line, the lines are saved in the numeric buffers.

The . command, when used immediately after the u command, causes the change log to be rolled forward or backward, depending on the action of the u command.

Line:
Set to the position of the first line changed, if the reversal affects only one line or represents an addition or change; otherwise, the line preceding the deleted text.
Column:
Set to the cursor position before the change was made.
Options:
None.

[count] w Command

Move forward countwords. Move the cursor forward to the beginning of a word by