     [file ref.texi not included]

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:

     8-bit clean data, large lines, files

     Nex,nvi will edit any format file. Line lengths are limited by available memory, and file sizes are limited by available disk space. The vi text input mode command <control-X> can insert any possible character value into the text. Background and foreground screens

     The bg command backgrounds the current screen, and the fg command foregrounds backgrounded screens. The display command can be used to list the background screens. Command Editing

     You can enter a normal editing window on the collected commands that you've entered on the vi colon command-line, and then modify and/or execute the commands. See the cedit edit option for more information. Displays

     The display command can be used to display the current buffers, the backgrounded screens, and the tags stack. Extended Regular Expressions

     The extended option causes Regular Expressions to be interpreted as as Extended Regular Expressions, (i.e. egrep(1) style Regular Expressions). File Name Completion

     It is possible to do file name completion and file name displays when entering commands on the vi colon command-line. See the filec option for more information. Infinite undo

     Changes made during an edit session may be rolled backward and forward. A . command immediately after a u command continues either forward or backward depending on whether the u command was an undo or a redo. Left-right scrolling

     The leftright option causes nvi to do left-right screen scrolling, instead of the traditional vi line wrapping. Message Catalogs

     It is possible to display informational and error messages in different languages by providing a catalog of messages. See the msgcat option and the file catalog/READMEfor more information. Incrementing numbers

     The # command increments or decrements the number under the cursor. Previous file

     The previous command edits the previous file from the argument list. Scripting languages

     The :pe[rl] cmd, :perld[o] cmd and :tc[l] cmd commands execute Perl and Tcl/Tk commands, respectively, on lines from the edit buffer. See the Scripting Languages section and the specific commands for more information.

     Split screens

     The Edit  , Ex  , Next  , Previous  , Tag and Visual (in vi mode) commands divide the screen into multiple editing regions and then perform their normal function in a new screen area. The <control-W> command rotates between the foreground screens. The resize command can be used to grow or shrink a particular screen. Tag stacks

     Tags are now maintained in a stack. The <control-T> command returns to the previous tag location. The tagpop command returns to the most recent tag location by default, or, optionally to a specific tag number in the tag stack, or the most recent tag from a specified file. The display command can be used to list the tags stack. The tagtop command returns to the top of the tag stack. Usage information

     The exusage and viusage commands provide usage information for all of the ex and vi commands by default, or, optionally, for a specific command or key. Word search

     The <control-A> command searches for the word referenced by the cursor.

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  .

     cs[cope] a[dd] file

     The add command attaches to the specified cscope database. The file name is expanded using the standard filename expansions. If file is a directory, the file cscope.out in that directory is used as the database.

     After nvi attaches to a new database, all subsequent cscope queries will be asked of that database. The result of any single query is the collection of response to the query from all of the attached databases.

     If the CSCOPE_DIRS environmental variable is set when nvi is run, it is expected to be a <colon> or <blank>-separated list of cscope databases or directories containing cscope databases, to which the user wishes to attach. :cs[cope] f[ind] c|d|e|f|g|i|s|t buffer|pattern

     The find command is the cscope query command for nvi  . For this command, nvi queries all attached cscope databases for the pattern. If the pattern is a double-quote character followed by a valid buffer name (e.g., LI"<character>" ), then the contents of the named buffer are used as the pattern. Otherwise, the pattern is a Regular Expression.

     The find command pushes the current location onto the tags stack, and switches to the first location resulting from the query, if the query returned at least one result.

     File names returned by the cscope query, if not absolute paths, are searched for relative to the directory where the cscope database is located. In addition, if the file cscope.tpath appears in the same directory as the cscope database, it is expected to contain a colon-separated list of directory names where files referenced by its associated cscope database may be found.

     The find subcommand is one of the following:

     c
          Find callers of the name.

     d
          Find all function calls made from name.

     e
          Find pattern.

     f
          Find files with name as substring.

     g
          Find definition of name.

     i
          Find files #including name.

     s
          Find all uses of name.

     t
          Find assignments to name.

     :cs[cope] h[elp] [command]

     List the cscope commands, or optionally list usage help for any single cscope command. :display c[onnections]

     Display the list of cscope databases to which nvi is currently connected. :cs[cope] k[ill] #

     Disconnect from a specific cscope database. The connection number is the one displayed by the ex display connections command. :cs[cope] r[eset]

     Disconnect from all attached cscope databases.

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/abc\e(.*\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''.

     viFindScreen file

     Return the screenIdassociated with file. viAppendLine screenId lineNumber text

     Append textas a new line after line number lineNumber, in the screen screenId. viDelLine screenId lineNum

     Delete the line lineNumberfrom the screen screenId. viGetLine screenId lineNumber

     Return the line lineNumberfrom the screen screenId. viInsertLine screenId lineNumber text

     Insert textas a new line before line number lineNumberin the screen screenId. viLastLine screenId

     Return the line number of the last line in the screen screenId. viSetLine screenId lineNumber text

     Change the line lineNumberin the screen screenIdto match the specified text. viGetMark screenId mark

     Return the current line and column for the specified markfrom the screen screenId. viSetMark screenId mark line column

     Set the specified markto be at line line, column column, in the screen screenId. viGetCursor screenId

     Return the current line and column for the cursor in the screen screenId. viSetCursor screenId line column

     Set the cursor in the screen screenIdto the specified lineand column. viMsg screenId text

     Display the specified textas a vi message in the screen screenId. viNewScreen screenId [file]

     Create a new screen. viEndScreen screenId

     Exit the screen screenId. viSwitchScreen screenId screenId

     Switch from the screen screenIdto the screen screenId. viMapKey screenId key tclproc

     Map the specified keyin the screen screenIdto the Tcl procedure tclproc. viUnmMapKey screenId key

     Unmap the specified keyin the screen screenIdviGetOpt screenId option

     Return the value of the specified optionfrom the screen screenId. viSetOpt screenId command

     Set one or more options in the screen screenId.

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:

     <interrupt>

     The interrupt character is used to interrupt the current operation. Normally <control-C>, whatever character is set for the current terminal is used. <literal-next>

     The literal next character is used to escape the subsequent character from any special meaning. This character is always <control-V>. If the terminal is not set up to do XON/XOFF flow control, then <control-Q>is used to mean literal next as well. current pathname

     The pathname of the file currently being edited by vi. When the percent character % appears in a file name entered as part of an ex command argument, it is replaced by the current pathname. (The % character can be escaped by preceding it with a backslash.) alternate pathname

     The name of the last file name mentioned in an ex command, or, the previous current pathname if the last file mentioned becomes the current file. When the hash mark character # appears in a file name entered as part of an ex command argument, it is replaced by the alternate pathname. (The # character can be escaped by preceding it with a backslash.) buffer

     One of a number of named areas for saving copies of text. Commands that change or delete text can save the changed or deleted text into a specific buffer, for later use, if the command allows it (i.e. the ex change command cannot save the changed text in a named buffer). Buffers are named with a single character, preceded by a double quote, e.g. LI"<character>" in vi and without the double quote, e.g. <character>, in ex  . (The double quote isn't necessary for ex because buffers names are denoted by their position in the command line.) Historic implementations of ex,vi limited <character>to the alphanumeric characters; nex,nvi permits the use of any character without another meaning in the position where a buffer name is expected.

     Buffers named by uppercase characters are the same as buffers named by lowercase characters, e.g. the buffer named by the English character A is the same as the buffer named by the character a, with the exception that, if the buffer contents are being changed (as with a text deletion or vi change command), the text is appended to the buffer, instead of replacing the current contents.

     The buffers named by the numeric characters (in English, 1 through 9), are special. If a region of text including characters from more than one line, or a single line of text specified by using a line-oriented motion, is changed or deleted in the file using the vi change or delete commands, a copy of the text is placed into the numeric buffer 1, regardless of the user specifying another buffer in which to save it. In addition, there are a few commands which, when used as a motionwith the vi change and delete commands, always copy the specified region of text into the numeric buffers regardless of the region including characters from more than one line. These commands are:

     <control-A>   %   (   )
     `<character>   /   ?   N
     n   {   }

     Before this copy is done, the previous contents of buffer 1 are moved into buffer 2, 2 into buffer 3, and so on. The contents of buffer 9 are discarded. In vi  , text may be explicitly stored into the numeric buffers. In this case, the buffer rotation described above occurs before the replacement of the buffer's contents. The numeric buffers are only available in visualand openmodes, and are not accessible by ex in any way, although changed and deleted text is still stored there while in ex mode.

     When a vi command synopsis shows both a [buffer]and a [count], they may be presented in any order.

     Finally, all buffers are either line or character oriented. All ex commands which store text into buffers are line oriented. Some vi commands which store text into buffers are line oriented, and some are character oriented; the description for each applicable vi command notes whether text copied into buffers using the command is line or character oriented. In addition, the vi command display buffers displays the current orientation for each buffer. Generally, the only importance attached to this orientation is that if the buffer is subsequently inserted into the text, line oriented buffers create new lines for each of the lines they contain, and character oriented buffers create new lines for any lines other than the first and last lines they contain. The first and last lines are inserted into the text at the current cursor position, becoming part of the current line. If there is more than one line in the buffer, however, the current line itself will be split. unnamed buffer

     The unnamed buffer is a text storage area which is used by commands that use or operate on a buffer when no buffer is specified by the user. If the command stores text into a buffer, the text is stored into the unnamed buffer even if a buffer is also specified by the user. It is not possible to append text to the unnamed buffer. If text is appended to a named buffer, the named buffer contains both the old and new text, while the unnamed buffer contains only the new text. There is no way to explicitly reference the unnamed buffer.

     Historically, the contents of the unnamed buffer were discarded by many different commands, even ones that didn't store text into it. Nex,nvi never discards the contents of the unnamed buffer until new text replaces them. whitespace

     The characters <tab> and <space>. <carriage-return>

     The character represented by an ASCII <control-M>. This character is almost always treated identically to a <newline>character, but differs in that it can be escaped into the file text or into a command. <newline>

     The character represented by an ASCII <control-J>. This character is almost always treated identically to a <control-M>character, but differs in that it cannot be escaped into the file text or into a command.

     [file vi.cmd.texi not included]

Ex Addressing
*************

Addressing in ex (and when ex commands are executed from vi  ) relates to the current line. In general, the current line is the last line affected by a command. The exact effect on the current line is discussed under the description of each command. When the file contains no lines, the current line is zero.

Addresses are constructed by one or more of the following methods:

 1. The address . refers to the current line.

 2. The address $ refers to the last line of the file.

 3. The address N, where Nis a positive number, refers to the N-th line of the file.

 4. The address '<character> or `<character> refers to the line marked with the name <character>. (See the k or m commands for more information on how to mark lines.)

 5. A regular expression (RE) enclosed by slashes / is an address, and it refers to the first line found by searching forward from the line after the current line toward the end of the file, and stopping at the first line containing a string matching the RE. (The trailing slash can be omitted at the end of the command line.)

     If no RE is specified, i.e. the pattern is //, the last RE used in any command is used in the search.

     If the extended option is set, the RE is handled as an extended RE, not a basic RE. If the wrapscan option is set, the search wraps around to the beginning of the file and continues up to and including the current line, so that the entire file is searched.

     The form \e/ is accepted for historic reasons, and is identical to //.

 6. An RE enclosed in question marks ? addresses the first line found by searching backward from the line preceding the current line, toward the beginning of the file and stopping at the first line containing a string matching the RE. (The trailing question mark can be omitted at the end of a command line.)

     If no RE is specified, i.e. the pattern is ??, the last RE used in any command is used in the search.

     If the extended option is set, the RE is handled as an extended RE, not a basic RE. If the wrapscan option is set, the search  wraps around from the beginning of the file to the end of the file and continues up to and including the current line, so that the entire file is searched.

     The form \e? is accepted for historic reasons, and is identical to ??.

 7. An address followed by a plus sign + or a minus sign - followed by a number is an offset address and refers to the address plus (or minus) the indicated number of lines. If the address is omitted, the addition or subtraction is done with respect to the current line.

 8. An address of + or - followed by a number is an offset from the current line. For example, -5 is the same as .-5.

 9. An address ending with + or - has 1 added to or subtracted from the address, respectively. As a consequence of this rule and of the previous rule, the address - refers to the line preceding the current line. Moreover, trailing + and - characters have a cumulative effect. For example, ++-++ refers to the current line plus 3.

 10. A percent sign % is equivalent to the address range 1,$.

Ex commands require zero, one, or two addresses. It is an error to specify an address to a command which requires zero addresses.

If the user provides more than the expected number of addresses to any ex command, the first addresses specified are discarded. For example, 1,2,3,5print prints lines 3 through 5, because the print command only takes two addresses.

The addresses in a range are separated from each other by a comma , or a semicolon ;. In the latter case, the current line . is set to the first address, and only then is the second address calculated. This feature can be used to determine the starting line for forward and backward searches (see rules (5) and (6) above). The second address of any two-address sequence corresponds to a line that follows, in the file, the line corresponding to the first address. The first address must be less than or equal to the second address. The first address must be greater than or equal to the first line of the file, and the last address must be less than or equal to the last line of the file.
     [file ex.cmd.texi not included]
     [file set.opt.texi not included]