Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ vi(C) — OpenDesktop 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought


 vi(C)                           19 June 1992                           vi(C)


 Name

    vi, view, vedit - invoke a screen-oriented display editor

 Syntax

    vi [ -option ... ] [ command ... ] [ filename ... ]

    view [ -option ... ] [ command ... ] [ filename ... ]

    vedit [ -option ... ] [ command ... ] [ filename ... ]

 Description

    The vi command offers a powerful set of text editing operations based on
    a set of mnemonic commands.  Most commands are single keystrokes that
    perform simple editing functions.  vi displays a full screen ``window''
    into the file you are editing.  The contents of this window can be
    changed quickly and easily within vi.  While editing, visual feedback is
    provided (the name vi itself is short for ``visual'').

    The view command is the same as vi except that the read-only option (-R)
    is set automatically.  The file cannot be changed with view.

    The vedit command is the same as vi except for differences in the option
    settings.  vedit uses novice mode, turns off the magic option, sets the
    option report=1 and turns on the options showmode and redraw.

    The showmode option informs the vedit user, in a message in the lower
    right hand corner of the screen, which mode is being used. For instance
    after the <Esc>i command is used, the message reads INSERT MODE.

    Note that you can not set the novice option from within vi or ex.  If you
    want to use the novice option you must use the vedit utility.  (It is
    possible to set the nonovice option from within vedit.)

    vi and the line editor ex are one and the same editor:  the names vi and
    ex identify a particular user interface rather than any underlying func-
    tional difference.  The differences in user interface, however, are quite
    striking. ex is a powerful line-oriented editor,  similar to the editor
    ed.  However, in both ex and ed, visual updating of the terminal screen
    is limited, and commands are entered on a command line.  vi, on the other
    hand, is a screen-oriented editor designed so that what you see on the
    screen corresponds exactly and immediately to the contents of the file
    you are editing.  In the following discussion, vi commands and options
    are printed in boldface type.

    Options available on the vi command line include:

    -x          Encryption option; when used, the file will be encrypted as
                it is being written and will require an encryption key to be
                read.  vi makes an educated guess to determine if a file is
                encrypted or not.  See crypt(C).  Also, see the ``Warnings''
                section at the end of this manual page.

    -C          Encryption option; the same as -x except that vi assumes
                files are encrypted.

    -c command  Begin editing by executing the specified editor command (usu-
                ally a search or positioning command).

    -t tag      Equivalent to an initial tag command; edits the file contain-
                ing tag and positions the editor at its definition.

    -r file     Used in recovering after an editor or system crash, retrieves
                the last saved version of the named file.

    -l          Specific to editing LISP, this option sets the showmatch and
                lisp options.

    -L          List the names of all files saved as a result of an editor or
                system crash.  Files may be recovered with the -r option.

    -wn         Sets the default window size to n.  Useful on dialups to
                start in small windows.

    -R          Sets a read-only option so that files can be viewed but not
                edited.

    The editing buffer

    vi performs no editing operations on the file that you name during invo-
    cation.  Instead, it works on a copy of the file in an ``editing
    buffer''.

    When you invoke vi with a single filename argument, the named file is
    copied to a temporary editing buffer.  The editor remembers the name of
    the file specified at invocation, so that it can later copy the editing
    buffer back to the named file.  The contents of the named file are not
    affected until the changes are copied back to the original file.

    Modes of operation

    Within vi there are three distinct modes of operation:

    Command Mode      Within command mode, signals from the keyboard are
                      interpreted as editing commands.

    Insert Mode       Insert mode can be entered by typing any of the vi
                      insert, append, open, substitute, change, or replace
                      commands.  Once in insert mode, letters typed at the
                      keyboard are inserted into the editing buffer.

    ex Escape Mode    The vi and ex editors are one and the same editor
                      differing mainly in their user interface.  In vi, com-
                      mands are usually single keystrokes.  In ex, commands
                      are lines of text terminated by a RETURN.  vi has a
                      special ``escape'' command that gives access to many of
                      these line-oriented ex commands.  To use the ex escape
                      mode, type a colon (:).  The colon is echoed on the
                      status line as a prompt for the ex command.  An execut-
                      ing command can be aborted by pressing INTERRUPT.  Most
                      file manipulation commands are executed in ex escape
                      mode (for example, the commands to read in a file and
                      to write out the editing buffer to a file).

    Special keys

    There are several special keys in vi.  The following keys are used to
    edit, delimit, or abort commands and command lines.

    <Esc>       Used to return to vi command mode or to cancel partially
                formed commands.

    <Return>    Terminates ex commands when in ex escape mode.  Also used to
                start a newline when in insert mode.

    INTERRUPT   Often the same as the <Del> or RUBOUT key on many terminals.
                Generates an interrupt, telling the editor to stop what it is
                doing.  Used to abort any command that is executing.

    /           Used to specify a string to be searched for. The slash
                appears on the status line as a prompt for a search string.
                The question mark (?) works exactly like the slash key,
                except that it is used to search backward in a file instead
                of forward.

    :           The colon is a prompt for an ex command.  You can then type
                in any ex command, followed by an <Esc> or <Return>, and the
                given ex command is executed.

    The following characters are special in insert mode:

    <Bksp>    Backs up the cursor one character on the current line.  The
              last character typed before the <Bksp> is removed from the
              input buffer, but remains displayed on the screen.

    <Ctrl>U   Moves the cursor back to the first character of the insertion
              and restarts insertion.

    <Ctrl>V   Removes the special significance of the next typed character.
              Use <Ctrl>V to insert control characters.  Linefeed and <Ctrl>J
              cannot be inserted in the text except as newline characters.
              Both <Ctrl>Q and <Ctrl>S are trapped by the operating system
              before they are interpreted by vi, so they too cannot be
              inserted as text.

    <Ctrl>W   Moves the cursor back to the first character of the last
              inserted word.

    <Ctrl>T   During an insertion, with the autoindent option set and at the
              beginning of the current line, entering this character will
              insert shiftwidth whitespace.

    <Ctrl>@   If entered as the first character of an insertion, it is
              replaced with the last text inserted, and the insertion ter-
              minates.  Only 128 characters are saved from the last inser-
              tion.  If more than 128 characters were inserted, then this
              command inserts no characters.  A <Ctrl>@ cannot be part of a
              file, even if quoted.

    Starting and exiting vi

    To enter vi, enter:
    vi             Edits empty editing buffer

    vi file        Edits named file

    vi +123 file   Goes to line 123

    vi + 45 file   Goes to line 45

    vi +/word file Finds first occurrence of ``word''

    vi +/tty file  Finds first occurrence of ``tty''

    There are several ways to exit the editor:

    :wq  This command writes the editing buffer to the file you are editing,
         quits the editor, and returns to the UNIX shell.

    ZZ   The editing buffer is written to the file only if any changes were
         made.

    :x   The editing buffer is written to the file only if any changes were
         made.

    :q!  Cancels an editing session.  The exclamation mark (!) tells vi to
         quit unconditionally.  In this case, the editing buffer is not writ-
         ten out.

 vi commands

    vi is a visual editor with a window on the file. What you see on the
    screen is vi's notion of what the file contains.  Commands do not cause
    any change to the screen until the complete command is entered. Most com-
    mands may take a preceding count that specifies repetition of the com-
    mand.  This count parameter is not given in the following command
    descriptions, but is implied unless overridden by some other prefix argu-
    ment.  When vi gets an improperly formatted command, it rings a bell.

    Cursor movement

    The cursor movement keys allow you to move your cursor around in a file.
    Note in particular the direction keys (if available on your terminal),
    the h, j, k, l, and cursor keys, and <Space>, <Bksp>, <Ctrl>N, and
    <Ctrl>P.  These three sets of keys perform identical functions.

    Forward Space - l, <Space>, or right direction key

    Syntax:   l
              <Space>
              right direction key

    Function: Moves the cursor forward one character.  If a count is given,
              move forward count characters.  You cannot move past the end of
              the line.

    Backspace - h, <Bksp>, or left direction key

    Syntax:   h
              <Bksp>
              left direction key

    Function: Moves cursor backward one character.  If a count is given,
              moves backward count characters.  Note that you cannot move
              past the beginning of the current line.

    Next Line - +, <Return>, j, <Ctrl>N, <LF>, and down direction key

    Syntax:   +
              <Return>

    Function: Moves the cursor down to the beginning of the next line.

    Syntax:   j
              <Ctrl>N
              <LF>
              down direction key

    Function: Moves the cursor down one line, remaining in the same column.
              Note the difference between these commands and the preceding
              set of next line commands which move to the beginning of the
              next line.

    Previous Line - k, <Ctrl>P, and up direction key

    Syntax:   k
              <Ctrl>P
              up direction key

    Function: Moves the cursor up one line, remaining in the same column.  If
              a count is given, the cursor is moved count lines.

    Syntax:   -

    Function: Moves the cursor up to the beginning of the previous line.  If
              a count is given, the cursor is moved up count lines.

    Beginning of Line - 0 and ^

    Syntax:   ^
              0

    Function: Moves the cursor to the beginning of the current line.  Note
              that 0 always moves the cursor to the first character of the
              current line. The caret (^) works somewhat differently: it
              moves to the first character on a line that is not a tab or a
              space.  This is useful when editing files that have a great
              deal of indentation, such as program texts.

    End of Line - $

    Syntax:   $

    Function: Moves the cursor to the end of the current line.  Note that the
              cursor resides on top of the last character on the line.  If a
              count is given, the cursor is moved forward count-1 lines to
              the end of the line.

    Goto Line - G

    Syntax:   [linenumber]G

    Function: Moves the cursor to the beginning of the line specified by
              linenumber.  If no linenumber is given, the cursor moves to the
              beginning of the last line in the file.  To find the line num-
              ber of the current line, use <Ctrl>G.

    Column - |

    Syntax:   [column]|

    Function: Moves the cursor to the column in the current line given by
              column.  If no column is given, the cursor is moved to the
              first column in the current line.

    Word Forward - w and W

    Syntax:   w
              W

    Function: Moves the cursor forward to the beginning of the next word.
              The lowercase w command searches for a word defined as a string
              of alphanumeric characters separated by punctuation or whi-
              tespace (that is, tab, newline, or space characters).  The
              uppercase W command searches for a word defined as a string of
              nonwhitespace characters.

    Back Word - b and B

    Syntax:   b
              B

    Function: Moves the cursor backward to the beginning of a word.  The
              lowercase b command searches backward for a word defined as a
              string of alphanumeric characters separated by punctuation or
              whitespace (that is, tab, newline, or space characters).  The
              uppercase B command searches for a word defined as a string of
              non-whitespace characters.  If the cursor is already within a
              word, it moves backward to the beginning of that word.

    End - e and E

    Syntax:   e
              E

    Function: Moves the cursor to the end of a word.  The lowercase e command
              moves the cursor to the last character of a word, where a word
              is defined as a string of alphanumeric characters separated by
              punctuation or whitespace (that is, tab, newline, or space
              characters).  The uppercase E moves the cursor to the last
              character of a word where a word is defined as a string of non-
              whitespace characters.  If the cursor is already within a word,
              it moves to the end of that word.

    Sentence - ( and )

    Syntax:   (
              )

    Function: Moves the cursor to the beginning (left parenthesis) or end of
              a sentence (right parenthesis).  A sentence is defined as a
              sequence of characters ending with a dot (.), question mark
              (?), or exclamation mark (!)  followed by either two spaces or
              a newline.  A sentence begins on the first nonwhitespace char-
              acter following a preceding sentence.  Sentences are also de-
              limited by paragraph and section delimiters. See below.

    Paragraph - { and }

    Syntax:   }
              {

    Function: Moves the cursor to the beginning ``{'' or end ``}'' of a para-
              graph.  A paragraph is  defined with the paragraphs option.  By
              default, paragraphs are delimited by the nroff macros .IP, .LP,
              .P, .QP, and .bp.  Paragraphs also begin after empty lines.

    Section - [[ and ]]

    Syntax:   ]]
              [[

    Function: Moves the cursor to the beginning ``[['' or end ``]]'' of a
              section.  A section is  defined with the sections option.  By
              default, sections are delimited by the nroff macros .NH and
              .SH.  Sections also start at formfeeds (<Ctrl>L) and at lines
              beginning with a brace ({).

    Match Delimiter - %

    Syntax:   %

    Function: Moves the  cursor to a matching delimiter, where a delimiter is
              a parenthesis, a bracket, or a brace.  This is useful when
              matching pairs of nested parentheses, brackets, and braces.

    Home - H

    Syntax:   [offset]H

    Function: Moves the  cursor to the upper left corner of the screen.  Use
              this command to move quickly to the top of the screen.  If an
              offset is given, the cursor is homed offset-1 number of lines
              from the top of the screen.  Note that the command dH deletes
              all lines from the current line to the top line shown on the
              screen.

    Middle Screen - M

    Syntax:   M

    Function: Moves the cursor to the beginning of the screen's middle line.
              Use this command to move quickly to the middle of the screen
              from either the top or the bottom.  Note that the command dM
              deletes from the current line to the line specified by the M
              command.

    Lower Screen - L

    Syntax:   [offset]L

    Function: Moves the  cursor to the lowest line on the screen.  Use this
              command to quickly move to the bottom of the screen.  If an
              offset is given, the cursor is homed offset-1 number of lines
              from the bottom of the screen.  Note that the command dL
              deletes all lines from the current line to the bottom line
              shown on the screen.

    Previous Context - `` and ''

    Syntax:   ''
              'character
              ``
              `character

    Function: Moves the cursor to previous context or to context marked with
              the m command.  If the single quotation mark or back quotation
              mark is doubled, the cursor is moved to previous context.  If a
              single character is given after either quotation mark, the cur-
              sor is moved to the location of the specified mark as defined
              by the m command.  The previous context is the location in the
              file of the last ``nonrelative'' cursor movement.  The single
              quotation mark (') syntax is used to move to the beginning of
              the line representing the previous context. The back quotation
              mark (`) syntax is used to move to the previous context within
              a line.

    The screen commands

    The screen commands are not cursor movement commands and cannot be used
    in delete commands as the delimiters of text objects.  However, the
    screen commands do move the cursor and are useful in paging or scrolling
    through a file.  These commands are described below:

    Scroll- <Ctrl>U and <Ctrl>D

    Syntax:   [size]<Ctrl>U
              [size]<Ctrl>D

    Function: Scrolls the screen up a half window (<Ctrl>U) or down a half
              window (<Ctrl>D).  If size is given, the scroll is size number
              of lines.  This value is remembered for all later scrolling
              commands.

    Page - <Ctrl>F and <Ctrl>B

    Syntax:   <Ctrl>F
              <Ctrl>B

    Function: Pages screen forward and backward.  Two lines of continuity are
              kept between pages if possible.  A preceding count gives the
              number of pages to move forward or backward.

    Status - <Ctrl>G

    Syntax:   BELL
              <Ctrl>G

    Function: Displays vi status on status line.  This gives you the name of
              the file you are editing, whether it has been modified, the
              current line number, the number of lines in the file, and the
              percentage of the file (in lines) that precedes the cursor.

    Zero Screen - z

    Syntax:   [linenumber]z[size]<Return>
              [linenumber]z[size].
              [linenumber]z[size]-

    Function: Redraws the display with the current line placed at or
              ``zeroed'' at the top, middle, or bottom of the screen, respec-
              tively.  If you give a size, the number of lines displayed is
              equal to size.  If a preceding linenumber is given, the given
              line is placed at the top of the screen.  If the last argument
              is a <Return>, the current line is placed at the top of the
              screen.  If the last argument is a dot (.), the current line is
              placed in the middle of the screen.  If the last argument is a
              minus sign (-), the current line is placed at the bottom of the
              screen.

    Redraw - <Ctrl>R or <Ctrl>L

    Syntax:   <Ctrl>R
              <Ctrl>L
              (Command depends on terminal type.)

    Function: Redraws the screen.  Use this command to erase any system mes-
              sages or line noise that may scramble your screen. Note that
              system messages do not affect the file you are editing.


    Text insertion

    The text insertion commands always place you in insert mode.  Exit from
    insert mode is always done by pressing <Esc>.  The following insertion
    commands are pure insertion commands; no text is deleted when you use
    them.  This differs from the text modification commands, change, replace,
    and substitute, which delete and then insert text in one operation.

    Insert - i and I

    Syntax:   i[text]<Esc>
              I[text]<Esc>

    Function: Insert text in editing buffer.  The lowercase i command places
              you in insert mode.  Text is inserted before the character
              beneath the cursor.  To insert a newline, press a <Return>.
              Exit insert mode by typing the <Esc> key.  The uppercase I com-
              mand places you in insert mode, but begins text insertion at
              the beginning of the current line, rather than before the cur-
              sor.  (The beginning of the line here is the first non-blank
              character on the line.)

    Append - a and A

    Syntax:   a[text]<Esc>
              A[text]<Esc>

    Function: Appends text to the editing buffer.  The lowercase a command
              works exactly like the lowercase i command, except that text
              insertion begins after the cursor and not before.  This is the
              only way to add text to the end of a line.  The uppercase A
              command begins appending text at the end of the current line
              rather than after the cursor.

    Open New Line - o and O

    Syntax:   o[text]<Esc>
              O[text]<Esc>

    Function: Opens a new line and inserts text.  The lowercase o command
              opens a new line below the current line; uppercase O opens a
              new line above the current line.  After the new line has been
              opened, both these commands work like the I command.

    Text deletion

    Many of the text deletion commands use the ``d'' key as an operator.
    This operator deletes text objects delimited by the cursor and a cursor
    movement command.  Deleted text is always saved in a buffer.  The delete
    commands are described below:

    Delete Character - x and X

    Syntax:   x
              X

    Function: Deletes a character.  The lowercase x command deletes the char-
              acter beneath the cursor.  With a preceding count, count char-
              acters are deleted to the right beginning with the character
              beneath the cursor.  This is a quick and easy way to delete a
              few characters.  The uppercase X command deletes the character
              just before the cursor.  With a preceding count, count charac-
              ters are deleted backward, beginning with the character just
              before the cursor.

    Delete - d and D

    Syntax:   dcursor-movement
              dd
              D

    Function: Deletes a text object.  The lowercase d command takes a
              cursor-movement as an argument.  If the cursor-movement is an
              intraline command, deletion takes place from the cursor to the
              end of the text object delimited by the cursor-movement.  Dele-
              tion forward deletes the character beneath the cursor; deletion
              backward does not.  If the cursor-movement is a multi-line com-
              mand, deletion takes place from and including the current line
              to the text object delimited by the cursor-movement.

              The dd command deletes whole lines.  The uppercase D command
              deletes from and including the cursor to the end of the current
              line.

              Deleted text is automatically pushed on a stack of buffers num-
              bered 1 through 9.  The most recently deleted text is also
              placed in a special delete buffer that is logically buffer 0.
              This special buffer is the default buffer for all (put) com-
              mands using the double quotation mark (") to specify the number
              of the buffer for delete, put, and yank commands.  The buffers
              1 through 9 can be accessed with the p and P (put) commands by
              appending the double quotation mark (") to the number of the
              buffer.  For example:

                 "4p

              puts the contents of delete buffer number 4 in your editing
              buffer just below the current line.  Note that the last deleted
              text is ``put'' by default and does not need a preceding buffer
              number.

    Text modification

    The text modification commands all involve the replacement of text with
    other text.  This means that some text will necessarily be deleted. All
    text modification commands can be ``undone'' with the u command:

    Undo - u and U

    Syntax:   u
              U

    Function: Undoes the last insert or delete command.  The lowercase u com-
              mand undoes the last insert or delete command.  This means that
              after an insert, u deletes text; and after a delete, u inserts
              text.  For the purposes of undo, all text modification commands
              are considered insertions.

              The uppercase U command restores the current line to its state
              before it was edited, no matter how many times the current line
              has been edited since you moved to it.

    Repeat -.

    Syntax:   .

    Function: Repeats the last insert or delete command.  A special case
              exists for repeating the p and P ``put'' commands.  When these
              commands are preceded by the name of a delete buffer, succes-
              sive u commands display the contents of the delete buffers.

    Change - c and C

    Syntax:   ccursor-movement text <Esc>
              Ctext <Esc>
              cctext <Esc>

    Function: Changes a text object and replaces it with text.  Text is
              inserted as with the i command.  A dollar sign ($) marks the
              extent of the change.  The c command changes arbitrary text
              objects delimited by the cursor and a cursor-movement.  C
              affects from the cursor to the end of the line, cc affects the
              whole line; otherwise, they are identical in function.

    Replace - r and R

    Syntax:   rchar
              Rtext <Esc>

    Function: Overstrikes character or line with char or text, respectively.
              Use r to overstrike a single character and R to overstrike a
              whole line.  A count multiplies the replacement text count
              times.

    Substitute - s and S

    Syntax:   stext <Esc>
              Stext <Esc>

    Function: Substitutes current character or current line with text.  Use s
              to replace a single character with new text.  Use S to replace
              the current line with new text.  If a preceding count is given,
              text substitutes for count number of characters or lines
              depending on whether the command is s or S, respectively.

    Filter - !

    Syntax:   !cursor-movement cmd <Return>

    Function: Filters the text object delimited by the cursor and cursor-
              movement through the UNIX command, cmd.  For example, the fol-
              lowing command sorts all lines between the cursor and the bot-
              tom of the screen, substituting the designated lines with the
              sorted lines:

                 !Lsort

              Arguments and shell metacharacters may be included as part of
              cmd; however, standard input and output are always associated
              with the text object being filtered.

    Join Lines - J

    Syntax:   J

    Function: Joins the current line with the following line.  If a count is
              given, count lines are joined.

    Shift - < and >

    Syntax:   >[cursor-movement]
              <[cursor-movement]
              >>
              <<

    Function: Shifts text right (>) or left (<).  Text is shifted by the
              value of the option shiftwidth, which is normally set to eight
              spaces.  Both the > and < commands shift all lines in the text
              object delimited by the current line and cursor-movement.  The
              >> and << commands affect whole lines.  All versions of the
              command can take a preceding count that acts to multiply the
              number of objects affected.

    Text movement

    The text movement commands move text in and out of the named buffers a-z
    and out of the delete buffers 1-9.  These commands either ``yank'' text
    out of the editing buffer and into a named buffer or ``put'' text into
    the editing buffer from a named buffer or a delete buffer.  By default,
    text is put and yanked from the ``unnamed buffer'', which is also where
    the most recently deleted text is placed.  Thus it is quite reasonable to
    delete text, move your cursor to the location where you want the deleted
    text placed, and then put the text back into the editing buffer at this
    new location with the p or P command.

    The named buffers are most useful for keeping track of several sections
    of text that you want to keep on hand for later access, movement, or
    rearrangement.  These buffers are named with the letters a through z. To
    refer to one of these buffers (or one of the numbered delete buffers) in
    a command, use a quotation mark.  For example, to yank a line into the
    buffer named a, enter:

       "ayy

    To put this text back into the file, enter:

       "ap

    If you delete text in the buffer named A rather than a, text is appended
    to the buffer named a (that is, A and a refer to the same buffer but are
    handled differently).

    Note that the contents of the named buffers are not destroyed when you
    switch files.  Therefore, you can delete or yank text into a buffer,
    switch files, and then do a put. Buffer contents are destroyed when you
    exit the editor, so be careful.

    Put - p and P

    Syntax:   ["alphanumeric]p
              ["alphanumeric]P

    Function: Puts text from a buffer into the editing buffer.  If no buffer
              name is specified, text is put from the unnamed buffer.  The
              lowercase p command puts text either below the current line or
              after the cursor, depending on whether the buffer contains a
              partial line or not.  The uppercase P command puts text either
              above the current line or before the cursor, again depending on
              whether the buffer contains a partial line or not.

    Yank - y and Y

    Syntax:   ["letter]ycursor-movement
              ["letter]yy
              ["letter]

    Function: Copies text in the editing buffer to a named buffer.  If no
              buffer name is specified, text is yanked into the unnamed
              buffer.  If an uppercase letter is used, text is appended to
              the buffer and does not overwrite and destroy the previous con-
              tents.  When a cursor-movement is given as an argument, the de-
              limited text object is yanked.  The Y and yy commands yank a
              single line, or, if a preceding count is given, multiple lines
              can be yanked.

    Searching

    The search commands search either forward or backward in the editing
    buffer for text that matches a given regular expression.

    Search - / and ?

    Syntax:   /[pattern]/[offset]<Return>
              /[pattern]<Return>
              ?[pattern]?[offset]<Return>
              ?[pattern]<Return>

    Function: Searches forward (/) or backward (?) for pattern.  A string is
              actually a regular expression.  The trailing delimiter is not
              required.  If no pattern is given, then the last pattern
              searched for is used.  After the second delimiter, an offset
              may be given, specifying the beginning of a line relative to
              the line on which pattern was found.  For example:

                 /word/-

              finds the beginning of the line immediately preceding the line
              containing word and the following command:

                 /word/+2

              finds the beginning of the line two lines after the line con-
              taining word.  See also the ignorecase and magic options.

    Next String - n and N

    Syntax:   n
              N

    Function: Repeats the last search command.  The n command repeats the
              search in the same direction as the last search command.  The N
              command repeats the search in the opposite direction of the
              last search command.

    Find Character - f and F

    Syntax:   fchar
              Fchar
              ;
              ,

    Function: Finds character char on the current line.  The lowercase f
              searches forward on the line; the uppercase F searches back-
              ward.  The semicolon (;) repeats the last character search.
              The comma (,) reverses the direction of the search.

    To Character - t and T

    Syntax:   tchar
              Tchar
              ;
              ,

    Function: Moves the cursor up to but not on char.  The semicolon (;)
              repeats the last character search.  The comma (,) reverses the
              direction of the search.

    Mark - m

    Syntax:   mletter

    Function: Marks a place in the file with a lowercase letter.  You can
              move to a mark using the ``to mark'' commands described below.
              It is often useful to create a mark, move the cursor, and then
              delete from the cursor to the mark ``a'' with the following
              command:

                 d'a

    To Mark - ' and `

    Syntax:   'letter
              `letter

    Function: Move to letter.  These commands let you move to the location of
              a mark.  Marks are denoted by single lowercase alphabetic char-
              acters.  Before you can move to a mark, it must first be creat-
              ed with the m command.  The back quotation mark (`) moves you
              to the exact location of the mark within a line; the forward
              quotation mark (') moves you to the beginning of the line con-
              taining the mark. Note that these commands are also legal cur-
              sor movement commands.

    Exit and escape commands

    There are several commands that are used to escape from vi command mode
    and to exit the editor.  These are described in the following section.

    ex Escape - :

    Syntax:   :

    Function: Enters ex escape mode to execute an ex command.  The colon
              appears on the status line as a prompt for an ex command.  You
              then can enter an ex command line terminated by either a
              <Return> or an <Esc> and the ex command will execute.  You are
              then prompted to type <Return> to return to vi command mode.
              During the input of the ex command line or during execution of
              the ex command, you may press INTERRUPT to stop what you are
              doing and return to vi command mode.

    Exit Editor - ZZ

    Syntax:   ZZ

    Function: Exit vi and write out the file if any changes have been made.
              This returns you to the shell from which you started vi.

    Quit to ex - Q

    Syntax:   Q

    Function: Enters the ex editor.  When you do this, you will still be
              editing the same file.  You can return to vi by entering the vi
              command from ex.

 ex commands

    Entering the colon (:) escape command when in command mode produces a
    colon prompt on the status line. This prompt is for a command available
    in the line-oriented editor, ex.  In general, ex commands let you write
    out or read in files, escape to the shell, or switch editing files.

    Many of these commands perform actions that affect the ``current'' file
    by default.  The current file is normally the file that you named when
    you started vi, although the current file can be changed with the
    ``file'' command, f, or with the ``next'' command, n.  In most respects,
    these commands are identical to similar commands for the editor, ed.  All
    such ex commands are aborted by either <Return> or INTERRUPT.  We shall
    use <Return> in our examples.  Command entry is terminated by typing
    INTERRUPT.

    Command structure

    Most ex command names are English words, and initial prefixes of the
    words are acceptable abbreviations.  In descriptions, only the abbrevia-
    tion is discussed, since this is the most frequently used form of the
    command.  The ambiguity of abbreviations is resolved in favor of the more
    commonly used commands.  As an example, the command substitute can be
    abbreviated s, while the shortest available abbreviation for the set com-
    mand is se.

    Most commands accept prefix addresses specifying the lines in the file
    that they are to affect.  A number of commands also may take a trailing
    count specifying the number of lines to be involved in the command.
    Counts are rounded down if necessary.  Thus, the command 10p displays the
    tenth line in the buffer while move 5 moves the current line after line
    5.

    Some commands take other information or parameters, stated after the com-
    mand name.  Examples might be option names in a set command, such as set
    number, a filename in an edit command, a regular expression in a substi-
    tute command, or a target address for a copy command. For example:

       1,5 copy 25

    A number of commands have variants.  The variant form of the command is
    invoked by placing an exclamation mark (!) immediately after the command
    name.  Some of the default variants may be controlled by options; in this
    case, the exclamation mark turns off the meaning of the default.

    In addition, many commands take flags, including the characters p and l.
    A p or l must be preceded by a blank or tab.  In this case, the command
    abbreviated by these characters is executed after the command completes.
    Since ex normally displays the new current line after each change, p is
    rarely necessary.  Any number of plus (+) or minus (-) characters may
    also be given with these flags.  If they appear, the specified offset is
    applied to the current line value before the printing command is exe-
    cuted.

    Most commands that change the contents of the editor buffer give feedback
    if the scope of the change exceeds a threshold given by the report
    option.  This feedback helps to detect undesirably large changes so that
    they may be quickly and easily reversed with the undo command.  After
    commands with global effect, you will be informed if the net change in
    the number of lines in the buffer during this command exceeds this
    threshold.

    Command addressing

    The following specifies the line addressing syntax for ex commands:

    .              The current line.  Most commands leave the current line as
                   the last line which they affect.  The default address for
                   most commands is the current line, thus ``.'' is rarely
                   used alone as an address.

    n              The nth line in the editor's buffer, lines being numbered
                   sequentially from 1.

    $              The last line in the buffer.

    %              An abbreviation for ``1,$'', the entire buffer.

    +n or -n       An offset, n relative to the current buffer line.  The
                   forms ``.+3'' ``+3'' and ``+++'' are all equivalent.  If
                   the current line is line 100 they all address line 103.

    /pattern/ or ?pattern?
                   Scan forward and backward respectively for a text matching
                   the regular expression given by pattern.  Scans normally
                   wrap around the end of the buffer.  If all that is desired
                   is to print the next line containing pattern, the trailing
                   slash (/) or question mark (?) may be omitted.  If pattern
                   is omitted or explicitly empty, the string matching the
                   last specified regular expression is located.  The forms
                   ``<Return>'' and ``?<Return>'' scan using the last named
                   regular expression. After a substitute, ``<Return>'' and
                   ``??<Return>'' would scan using that substitute's regular
                   expression.

    '' or 'x       Before each nonrelative motion of the current line dot
                   (.), the previous current line is marked with a label,
                   subsequently referred to with two single quotation marks
                   ('').  This makes it easy to refer or return to this pre-
                   vious context.  Marks are established with the vi m com-
                   mand, using a single lowercase letter as the name of the
                   mark.  Marked lines are later referred to with the follow-
                   ing notation:

                      'x.

                   where x is the name of a mark.

    Addresses to commands consist of a series of addresses, separated by a
    comma (,) or a semicolon (;).  Such address lists are evaluated left to
    right.  When addresses are separated by a semicolon (;) the current line
    (.)  is set to the value of the previous addressing expression before the
    next address is interpreted.  If more addresses are given than the com-
    mand requires, all but the last one or two are ignored.  If the command
    takes two addresses, the first addressed line must precede the second in
    the buffer.  Null address specifications are permitted in a list of
    addresses, the default in this case is the current line (.); thus
    ``,100'' is equivalent to ``.,100''.  It is an error to give a prefix
    address to a command which expects none.

    Command format

    The following is the format for all ex commands:

       [address] [command] [!] [parameters] [count] [flags]

    All parts are optional depending on the particular command and its
    options. The following section describes specific commands.

    Argument list commands

    The argument list commands allow you to work on a set of files, by
    remembering the list of filenames that are specified when you invoke vi.
    The args command lets you examine this list of filenames.  The file com-
    mand gives you information about the current file.  The n (next) command
    lets you either edit the next file in the argument list or change the
    list.  The rewind command lets you restart editing the files in the list.
    All of these commands are described below:

    args          The members of the argument list are displayed, with the
                  current argument delimited by brackets.

                  For example, a list might look like this:

                     file1 file2 [file3] file4 file5

                  The current file is file3.

    f             Displays the current filename, whether it has been modified
                  since the last write command, whether it is read-only, the
                  current linenumber, the number of lines in the buffer, and
                  the percentage of the buffer that you have edited.  In the
                  rare case that the current file is ``[Not edited]'', this
                  is noted also; in this case you have to use w!  to write to
                  the file, since the editor is not sure that a w command
                  will not destroy a file unrelated to the current contents
                  of the buffer.

    f file        The current filename is changed to file which is considered
                  ``[Not edited]''.

    n             The next file in the command line argument list is edited.

    n!            This variant suppresses warnings about the modifications to
                  the buffer not having been written out, discarding irre-
                  trievably any changes that may have been made.

    n [+command] filelist
                  The specified filelist is expanded and the resulting list
                  replaces the current argument list; the first file in the
                  new list is then edited.  If command is given (it must con-
                  tain no spaces), then it is executed after editing the
                  first such file.

    rew           The argument list is rewound, and the first file in the
                  list is edited.

    rew!          Rewinds the argument list discarding any changes made to
                  the current buffer.

    If you use C-Shell and set the prompt variable to output a prompt for
    non-interactive shells, the prompt is interpreted as a filename when you
    use these commands.  This causes unexpected problems.  To avoid these
    problems, the default prompt should be set as shown in
    /usr/lib/mkuser/csh/cshrc.

    Edit commands

    To edit a file other than the one you are currently editing, you will
    often use one of the variations of the e command.

    In the following discussions, note that the name of the current file is
    always remembered by vi and is specified by a percent sign (%).  The name
    of the previous file in the editing buffer is specified by a number sign
    (#).

    The edit commands are described below:

    e file      Used to begin an editing session on a new file.  The editor
                first checks to see if the buffer has been modified since the
                last w command was issued.  If it has been, a warning is
                issued and the command is aborted.  The command otherwise
                deletes the entire contents of the editor buffer, makes the
                named file the current file, and displays the new filename.
                After ensuring that this file is sensible, (that is, it is
                not a binary file, directory, or a device), the editor reads
                the file into its buffer.  If the read of the file completes
                without error, the number of lines and characters read is
                displayed on the status line.  If no errors occurred, the
                file is considered edited.  If the last line of the input
                file is missing the trailing newline character, it is sup-
                plied and a complaint issued.  The current line is initially
                the first line of the file.

    e! file     This variant form suppresses the complaint about
                modifications having been made and not written from the edi-
                tor buffer, thus discarding all changes that have been made
                before editing the new file.

    e +n file   Causes the editor to begin editing at line n rather than at
                the first line.  The argument n may also be an editor command
                containing no spaces; for example, ``+/pattern''.

    <Ctrl>^     This is a shorthand equivalent for :e #<Return> which returns
                to the previous position in the last edited file.  If you do
                not want to write the file, you should use :e! #<Return>
                instead.

    Write commands

    The write commands let you write out all or part of your editing buffer
    to either the current file or to some other file.  These are described
    below:

    w file         Writes changes made back to file, displaying the number of
                   lines and characters written.  Normally, file is omitted
                   and the buffer is written to the name of the current file.
                   If file is specified, text is written to that file.  The
                   editor writes to a file only if it is the current file and
                   is edited, or if the file does not exist.  Otherwise, you
                   must give the variant form w! to force the write.  If the
                   file does not exist it is created.  The current filename
                   is changed only if there is no current filename; the
                   current line is never changed.

                   If an error occurs while writing the current and edited
                   file, the editor displays:

                      No write since last change

                   even if the buffer had not previously been modified.

    w>> file       Appends the buffer contents at the end of an existing
                   file.  Previous file contents are not destroyed.

    w! name        Overrides the checking of the normal write command, and
                   writes to any file that the system permits.

    w !command     Writes the specified lines into command.  Note the differ-
                   ence in spacing between

                      w! file

                   which overrides checks and

                      w !cmd

                   which writes to a command. (A blank or tab before the exc-
                   lamation mark is mandatory.)  The output of this command
                   is displayed on the screen and not inserted in the editing
                   buffer.

    Read commands

    The read commands let you read text into your editing buffer at any loca-
    tion you specify.  The text you read in must be at least one line long,
    and can be either a file or the output from a command.

    r file         Places a copy of the text of the given file in the editing
                   buffer after the specified line.  If no file is given, the
                   current filename is used.  The current filename is not
                   changed unless there is none, in which case the file
                   becomes the current name.  If the file buffer is empty and
                   there is no current name, this is treated as an e command.

                   Address 0 is legal for this command and causes the file to
                   be read at the beginning of the buffer.  Statistics are
                   given as for the e command when the r successfully ter-
                   minates.  After an r the current line is the last line
                   read.

    r !command     Reads the output of command into the buffer after the
                   specified line.  A blank or tab before the exclamation
                   mark (!) is mandatory.

    Quit commands

    There are several ways to exit vi.  Some abort the editing session, some
    write out the editing buffer before exiting, and some warn you if you
    decide to exit without writing out the buffer.  All of these ways of
    exiting are described below:

    q           Exits vi.  No automatic write of the editor buffer to a file
                is performed.  However, vi displays a warning message if the
                file has changed since the last w command was issued, and
                does not quit.  vi also displays a diagnostic if there are
                more files in the argument list left to edit.  Normally, you
                will wish to save your changes, and you should enter a w com-
                mand.  If you wish to discard them, enter the q! command
                variant.

    q!          Quits from the editor, discarding changes to the buffer
                without complaint.

    wq name     Like a w and then a q command.

    wq! name    Overrides checking normally made before execution of the w
                command to any file.  For example, if you own a file but do
                not have write permission turned on, the wq!  allows you to
                update the file anyway.

    x name      If any changes have been made and not written, writes the
                buffer out and then quits.  Otherwise, it just quits.

    Global and substitute commands

    The global and substitute commands allow you to perform complex changes
    to a file in a single command.  Learning how to use these commands is a
    must for an experienced vi user.

    g/pattern/cmds The g command has two distinct phases.  In the first
                   phase, each line matching pattern in the editing buffer is
                   marked.  Next, the given command list is executed with the
                   current line, dot (.), initially set to each marked line.

                   The command list consists of the remaining commands on the
                   current input line and may continue to multiple lines by
                   ending all but the last such line with a backslash (\).
                   This multiple-line option will not work from within vi.
                   You must switch to ex to do it. The vi command Q can be
                   used to exit to ex, and the ex command vi will return you
                   to visual mode.  If cmds (or the trailing slash (/) delim-
                   iter) is omitted, each line matching pattern is displayed.

                   The g command itself may not appear in cmds.  The options
                   autoprint and autoindent are inhibited during a global
                   command and the value of the report option is temporarily
                   infinite, in deference to a report for the entire global.
                   Finally, the context mark ( ' ) or ( ` ) is set to the
                   value of the current line (.)  before the global command
                   begins and is not changed during a global command.

                   The following global commands, most of them substitutions,
                   cover the most frequent uses of the global command.

    g/s1/p         This command simply prints all lines that contain the
                   string s1.

    g/s1/s//s2/    This command substitutes the first occurrence of s1 on all
                   lines that contain it with the string s2.

    g/s1/s//s2/g   This command substitutes all occurrences of s1 with the
                   string s2.  This includes multiple occurrences of s1 on a
                   line.

    g/s1/s//s2/gp  This command works the same as the preceding example,
                   except that in addition, all changed lines are displayed
                   on the screen.

    g/s1/s//s2/gc  This command prompts you to confirm that you want to make
                   each substitution of the string s1 with the string s2.  If
                   you enter a Y, the given substitution is made, otherwise
                   it is not.

    g/s0/s/s1/s2/g This command marks all those lines that contain the string
                   s0, and then for those lines only, substitutes all occur-
                   rences of the string s1 with s2.

    g!/pattern/cmds
                   This variant form of g runs cmds at each line not matching
                   pattern.

    g/^/s// /g     This command inserts blank spaces at the beginning of each
                   line in a file.

    s/pattern/repl/options
                   On each specified line, the first instance of text match-
                   ing the regular expression pattern is replaced by the
                   replacement text repl.  If the global indicator option
                   character g appears, all instances on a line are substi-
                   tuted.  If the confirm indication character c appears,
                   before each substitution the line to be substituted is
                   printed on the screen with the string to be substituted
                   marked with caret (^) characters.  By entering Y, you
                   cause the substitution to be performed; any other input
                   causes no change to take place.  After an s command, the
                   current line is the last line substituted.

    v/pattern/cmds A synonym for the global command variant g!, running the
                   specified cmds on each line that does not match pattern.

    Text movement commands

    The text movement commands are largely superseded by commands available
    in vi command mode.  However, the following two commands are still quite
    useful:

    co addr flags  A copy of the specified lines is placed after addr, which
                   may be ``0''.  The current line (.)  addresses the last
                   line of the copy.

    [range]maddr   The m command moves the lines specified by range after the
                   line given by addr.  For example, m+ swaps the current
                   line and the following line, since the default range is
                   just the current line.  The first of the moved lines
                   becomes the current line (dot).

    Shell escape commands

    You will often want to escape from the editor to execute normal UNIX com-
    mands. You may also want to change your working directory so that your
    editing can be done with respect to a different working directory.  These
    operations are described below:

    cd directory   The specified directory becomes the current directory.  If
                   no directory is specified, the current value of the home
                   option is used as the target directory.  After a cd, the
                   current file is not considered to have been edited so that
                   write restrictions on preexisting files still apply.

    sh             A new shell is created.  You  may invoke as many commands
                   as you like in this shell.  To return to vi, enter a
                   <Ctrl>D to terminate the shell.

    !command       The remainder of the line after the exclamation (!)  is
                   sent to a shell to be executed.  Within the text of com-
                   mand, the characters ``%'' and ``#'' are expanded as the
                   filenames of the current file and the last edited file and
                   the character ``!'' is replaced with the text of the pre-
                   vious command.  Thus, in particular, ``!!'' repeats the
                   last such shell escape.  If any such expansion is per-
                   formed, the expanded line is echoed.  The current line is
                   unchanged by this command.

    If there has been ``[No write]'' of the buffer contents since the last
    change to the editing buffer, a diagnostic is displayed before the com-
    mand is executed, as a warning.  A single exclamation (!) is displayed
    when the command completes.

    If you use C-Shell and set the prompt variable to output a prompt for
    non-interactive shells, the prompt is interpreted as an argument for com-
    mand in shell escapes.  This causes unexpected problems.  To avoid these
    problems, use the default prompt value as shown in
    /usr/lib/mkuser/csh/cshrc.

    Other commands

    The following command descriptions explain how to use miscellaneous ex
    commands that do not fit into the above categories.

    The abbr, map, and set commands can also be defined with the EXINIT
    environment variable, which is read by the editor each time it starts up.
    For more information, see environ(M).  Alternatively, these commands can
    be placed in a .exrc file in your home directory, which the editor reads
    if EXINIT is not defined.

    abbr          Maps the first argument to the following string. For exam-
                  ple, the following command

                     :abbr rainbow yellow green blue red

                  maps ``rainbow'' to ``yellow green blue red''.  Abbrevia-
                  tions can be turned off with the unabbreviate command, as
                  in:

                     :una rainbow


    map, map!     Maps any character or escape sequence to a command
                  sequence.  For example, the following command maps the
                  <Ctrl>A key to a shell escape that runs the clear(C) com-
                  mand:

                     map ^A:!clear^M

                  To include the <Ctrl>A and <Ctrl>M characters in the map-
                  ping, you must use vi's <Ctrl>V escape.

                  Characters mapped with map work in command mode, while
                  characters mapped with map! work in insert mode.  Charac-
                  ters mapped with map! cannot be unmapped using unmap.

    nu            Displays each specified line preceded by its buffer line
                  number.  The current line is left at the last line dis-
                  played.  To get automatic line numbering of lines in the
                  buffer, set the number option.

    preserve      The current editor buffer is saved as though the system had
                  just crashed.  This command is for use only in emergencies
                  when a w command has resulted in an error and you do not
                  know how to save your work.

    =             Displays the line number of the addressed line.  The
                  current line is unchanged.

    recover file  Recovers  file from the system save area.  The system saves
                  a copy of the editing buffer only if you have made changes
                  to the file, the system crashes, or you execute a preserve
                  command. When you use preserve, you are notified by mail.

    set argument  With no arguments, set displays those options whose values
                  have been changed from their defaults; with the argument
                  all, it displays all of the option values.

                  Giving an option name followed by a question mark (?)
                  causes the current value of that option to be displayed.
                  The question mark is unnecessary unless the option is a
                  Boolean value.  Switch options are given values either
                  with:

                     set option

                  to turn them on or:

                     set nooption

                  to turn them off.  String and numeric options are assigned
                  with:

                     set option=value

                  More than one option can be given to set; all are inter-
                  preted from left to right.  See ``Options'' for a complete
                  list and descriptions.

    tag label     The focus of editing switches to the location of label.  If
                  necessary, vi will switch to a different file in the
                  current directory to find label.  If you have modified the
                  current file before giving a tag command, you must first
                  write it out. If you give another tag command with no argu-
                  ment, the previous label is used.

                  Similarly, if you press <Ctrl>], vi searches for the word
                  immediately after the cursor as a tag.  This is equivalent
                  to entering ``:tag'', the word following the cursor, and
                  then pressing the <Return> key.

                  The tags file is normally created by a program such as
                  ctags, and consists of a number of lines with three fields
                  separated by blanks or tabs. The first field gives the name
                  of the tag, the second the name of the file where the tag
                  resides, and the third gives an addressing form which can
                  be used by the editor to find the tag.  This field is usu-
                  ally a contextual scan using /pattern/ to be immune to
                  minor changes in the file. Such scans are always performed
                  as if the nomagic option was set.  The tag names in the
                  tags file must be sorted alphabetically.

    unmap         Unmaps any character or escape sequence that has been
                  mapped using the map command.

    Options

    There are a number of options that can be set to affect the vi environ-
    ment.  These can be set with the ex set command while editing, with the
    EXINIT environment variable, or in the vi start-up file, .exrc.  This
    file normally sets the user's preferred options so that they do not need
    to be set manually each time you invoke vi.

    The first thing that must be done before you can use vi, is to set the
    terminal type so that vi understands how to talk to the particular termi-
    nal you are using.

    There are only two kinds of options: switch options and string options.
    A switch option is either on or off.  A switch is turned off by prefixing
    the word no to the name of the switch within a set command.  String
    options are strings of characters that are assigned values with the syn-
    tax option=string.  Multiple options may be specified on a line.  vi
    options are listed below:

    autoindent, ai  (default: noai)
       Can be used to ease the preparation of structured program text.  For
       each line created by an append, change, insert, open, or substitute
       operation, vi looks at the preceding line to determine and insert an
       appropriate amount of indentation.  To back the cursor up to the
       preceding tab stop, press <Ctrl>D.  The tab stops going backward are
       defined as multiples of the shiftwidth option.  You cannot backspace
       over the indent, except by pressing <Ctrl>D.

       Specially processed in this mode is a line with no characters added to
       it, which turns into a completely blank line (the whitespace provided
       for the autoindent is discarded).  Also, specially processed in this
       mode are lines beginning with a caret (^) and immediately followed by
       a <Ctrl>D.  This causes the input to be repositioned at the beginning
       of the line, but retains the previous indent for the next line.  Simi-
       larly, a ``0'' followed by a <Ctrl>D, repositions the cursor at the
       beginning without retaining the previous indent.  Autoindent does not
       happen in global commands.

    autoprint ap   (default: ap)
       Causes the current line to be displayed after each ex copy, move, or
       substitute command.  This has the same effect as supplying a trailing
       ``p'' to each such command.  Autoprint is suppressed in globals, and
       only applies to the last command on a line.

    autowrite, aw  (default: noaw)
       Causes the contents of the buffer to be automatically written to the
       current file if you have modified it when you give a next, rewind,
       tag, or ! command, or a <Ctrl>^ (switch files) or <Ctrl>] (goto tag)
       command.

    beautify, bf  (default: nobeautify)
       Causes all control characters except tab, newline and formfeed to be
       discarded from the input.  A complaint is registered the first time a
       backspace character is discarded.  Beautify does not apply to command
       input.

    directory, dir  (default: dir=/tmp)
       Specifies the directory in which vi places the editing buffer file.
       If the directory does not have write permission, the editor will exit
       abruptly when it fails to write to the buffer file.

    edcompatible  (default: noedcompatible)
       Causes the presence or absence of g and c suffixes on substitute com-
       mands to be remembered, and to be toggled on and off by repeating the
       suffixes. The suffix r causes the substitution to be like the tilde
       (~) command, instead of like the ampersand (&) command.

    errorbells, eb  (default: noeb)
       Error messages are preceded by a bell. If possible, the editor always
       places the error message in inverse video instead of ringing the bell.

    hardtabs, ht  (default: ht=8)
       Gives the boundaries on which terminal hardware tabs are set or on
       which tabs the system expands.

    ignorecase, ic  (default: noic)
       Maps all uppercase characters in the text to lowercase in regular
       expression matching.  In addition, all uppercase characters in regular
       expressions are mapped to lowercase except in character class specifi-
       cations enclosed in brackets.

    lisp  (default: nolisp)
       Autoindent indents appropriately for LISP code, and the ( ) { } [[ and
       ]] commands are modified to have meaning for LISP.

    list  (default: nolist)
       All printed lines are displayed, showing tabs and end-of-lines.

    magic  (default: magic)
       If nomagic is set, the number of regular expression metacharacters is
       greatly reduced, with only caret (^) and dollar sign ($) having spe-
       cial effects.  In addition, the metacharacters tilde (~) and ampersand
       (&) in replacement patterns are treated as normal characters.  All the
       normal metacharacters may be made magic when nomagic is set by preced-
       ing them with a backslash (\).

    mesg  (default: nomesg)
       Causes write permission to be turned off to the terminal while you are
       in visual mode, if nomesg is set.  This prevents people writing to
       your screen with the UNIX write command and scrambling your screen as
       you edit.

    number, n  (default: nonumber)
       Causes all output lines to be printed with their line numbers.

    optimize, opt  (default: optimize)
       Output of text to the screen is expedited by setting the terminal so
       that it does not perform automatic carriage returns when displaying
       more than one line of output, thus greatly speeding output on termi-
       nals without addressable cursors when text with leading whitespace is
       printed.

    paragraphs, para  (default: para =IPLPPPQPP TPbp)
       Specifies paragraph delimiters for the { and } operations.  The pairs
       of characters in the option's value are the names of the nroff macros
       that start paragraphs.

    prompt  (default: prompt)
       ex input is prompted for with a colon (:).  If noprompt is set, when
       ex command mode is entered with the Q command, no colon prompt is dis-
       played on the status line.

    redraw  (default: noredraw)
       The editor simulates (using great amounts of output), an intelligent
       terminal on a dumb terminal.  Useful only at very high speed.

    remap  (default: remap)
       If on, mapped characters are repeatedly tried until they are
       unchanged. For example, if o is mapped to O and O is mapped to I, o
       will map to I if remap is set, and to O if noremap is set.

    report  (default: report=5)
       Specifies a threshold for feedback from commands.  Any command that
       modifies more than the specified number of lines will provide feedback
       as to the scope of its changes.  For global commands and the undo com-
       mand, the net change in the number of lines in the buffer is presented
       at the end of the command.  Thus notification is suppressed during a g
       command on the individual commands performed.

    scroll  (default: scroll=1/2 window)
       Determines the number of logical lines scrolled when <Ctrl>D is
       received from a terminal input in command mode, and the number of
       lines displayed by a command mode z command (double the value of
       scroll).

    sections  (default: sections=SHNHH HU)
       Specifies the section macros for the [[ and ]] operations.  The pairs
       of characters in the option's value are the names of the nroff macros
       that start sections.

    shell, sh  (default: sh=/bin/sh)
       Gives the pathname of the shell forked for the shell escape (!) com-
       mand, and by the shell command.  The default is taken from SHELL in
       the environment, if present.

    shiftwidth, sw  (default:sw=8)
       Gives the width of a software tab stop, used in reverse tabbing with
       <Ctrl>D when using autoindent to append text, and by the shift com-
       mands.

    showmatch, sm  (default: nosm)
       When a ``)'' or ``}'' is typed, moves the cursor to the matching ``(''
       or ``{'' for one second if this matching character is on the screen.
    showmode  (default:noshowmode)
       Causes the message INPUT MODE to appear on the lower right corner of
       the screen when insert mode is activated.

    slowopen  (default: noslowopen)
       Postpones update of the display during inserts.

    tabstop, ts  (default: ts=8)
       The editor expands tabs in the input file to be on n boundaries for
       the purposes of display.

    taglength, tl  (default: tl=0)
       The first n characters in a tag name are significant, but all others
       are ignored.  A value of zero (the default) means that all characters
       are significant.

    tags  (default: tags=tags /usr/lib/tags)
       A path of files to be used as tag files for the tag command.  A
       requested tag is searched for in the specified files, sequentially.
       By default, files named tags are searched for in the current directory
       and in /usr/lib.

    term  (default=value of shell TERM variable)
       The terminal type of the output device.

    terse  (default: noterse)
       Shorter error diagnostics are produced for the experienced user.

    timeout [=n], to [=n]  (default: to=xxx)
       Milliseconds to wait for subsequent input characters.  This is the
       maximum allowed waiting time between characters in ``multicharacter''
       sequences, such as arrow keys or :map functions.  If no value is
       given, vi determines the timeout period from the type and speed of the
       terminal connection; setting notimeout requires the next character to
       be input, and is not the same as setting timeout to ``0'' (never wait-
       ing).

    warn (default: warn)
       Warn if there has been ``[No write since last change]'' before a shell
       escape command !.

    window  (default: window = speed dependent)
       This specifies the number of lines in a text window.  The default is 8
       at slow speeds (600 baud or less), 16 at medium speed (1200 baud), and
       the full screen (minus one line) at higher speeds.

    w300, w1200, w9600
       These are not true options but set window (above) only if the speed is
       slow (300), medium (1200), or high (9600), respectively.

    wrapscan, ws  (default: ws)
       Searches, using the regular expressions in addressing, will wrap
       around past the end of the file.

    wrapmargin, wm  (default: wm=0)
       Defines the margin for automatic insertion of newlines during text
       input.  The value specified is the width of the margin at the right-
       hand side of the screen within which word wrap will be carried out.  A
       newline will be inserted immediately after a word that ends in the
       margin.  A value of zero specifies no wrap margin.

    writeany, wa  (default: nowa)
       Inhibits the checks normally made before write commands, allowing a
       write to any file that the system protection mechanism will allow.

 Regular expressions

    A regular expression specifies a set of strings of characters.  A member
    of this set of strings is said to be ``matched'' by the regular expres-
    sion. vi remembers two previous regular expressions:  the previous regu-
    lar expression used in a substitute command and the previous regular
    expression used elsewhere, referred to as the previous scanning regular
    expression.  The previous regular expression can always be referred to by
    a null regular expression:  for example, ``//'' or ``??''.

    The regular expressions allowed by vi are constructed in one of two ways
    depending on the setting of the magic option.  The ex and vi default set-
    ting of magic gives quick access to a powerful set of regular expression
    metacharacters.  The disadvantage of magic is that the user must remember
    that these metacharacters are magic and precede them with the backslash
    (\) to use them as ``ordinary'' characters.  With nomagic set, regular
    expressions are much simpler, there being only two metacharacters.  The
    power of the other metacharacters is still available by preceding the now
    ordinary character with a ``\''.  Note that ``\'' is always a metacharac-
    ter.  In this discussion, the magic option is assumed. With nomagic, the
    only special characters are the caret (^) at the beginning of a regular
    expression, the dollar sign ($) at the end of a regular expression, and
    the backslash (\).  The tilde (~) and the ampersand (&) also lose their
    special meanings related to the replacement pattern of a substitute.

    The following basic constructs are used to construct magic mode regular
    expressions.

    char    An ordinary character matches itself.  Ordinary characters are
            any characters except a caret (^) at the beginning of a line, a
            dollar sign ($) at the end of line, a star (*) as any character
            other than the first, and any of the following characters:

               .   \   [   ~

            These characters must be preceded by a backslash (\) if they are
            to be treated as ordinary characters.

    ^       At the beginning of a pattern, forces the match to succeed only
            at the beginning of a line.

    $       At the end of a regular expression, forces the match to succeed
            only at the end of the line.

    .       Matches any single character except the newline character.

    \<      Forces the match to occur only at the beginning of a ``word'';
            that is, either at the beginning of a line, or just before a
            letter, digit, or underline and after a character not one of
            these.

    \>      Similar to \<, but matching the end of a ``word'', that is,
            either the end of the line or before a character which is not a
            letter, a digit, or the underline character.

    [string]
            Matches any single character in the class defined by string.
            Most characters in string define themselves.  A pair of charac-
            ters separated by a dash (-) in string defines the set of charac-
            ters between the specified lower and upper bounds, thus ``[a-z]''
            as a regular expression matches any single lowercase letter.  If
            the first character of string is a caret (^) then the construct
            matches those characters which it otherwise would not.  Thus
            ``[^a-z]'' matches anything but a lowercase letter or a newline.
            To place any of the characters caret, left bracket, or dash in
            string they must be escaped with a preceding backslash (\).

    The concatenation of two regular expressions first matches the leftmost
    regular expression and then the longest string that can be recognized as
    a regular expression.  The first part of this new regular expression
    matches the first regular expression and the second part matches the
    second.  Any of the single character matching regular expressions men-
    tioned above may be followed by a star (*) to form a regular expression
    that matches zero or more adjacent occurrences of the characters matched
    by the prefixing regular expression.  The tilde (~) may be used in a reg-
    ular expression to match the text that defined the replacement part of
    the last s command.  A regular expression may be enclosed between the
    sequences ``\('' and ``\)'' to remember the text matched by the enclosed
    regular expression.  This text can later be interpolated into the
    replacement text using the following notation:

       \digit

    where digit enumerates the set of remembered regular expressions.

    The basic metacharacters for the replacement pattern are the ampersand
    (&) and the tilde (~); these are given as ``\&'' and ``\~'' when nomagic
    is set.  Each instance of the ampersand is replaced by the characters
    matched by the search pattern.  In the replacement pattern, the tilde
    stands for the text of the previous replacement pattern.

    Other metasequences possible in the replacement pattern are always intro-
    duced by a backslash (\).  The sequence ``\n'' is replaced by the text
    matched by the nth regular subexpression enclosed between ``\('' and
    ``\)''.  When nested, parenthesized subexpressions are present, n is
    determined by counting occurrences of ``\('' starting from the left.  The
    sequences ``\u'' and ``\l'' cause the immediately following character in
    the replacement to be converted to uppercase or lowercase, respectively,
    if this character is a letter.  The sequences ``\U'' and ``\L'' turn such
    conversion on, either until ``\E'' or ``\e'' is encountered, or until the
    end of the replacement pattern.

 Files


    /tmp                     default directory where temporary work files are
                             placed; it can be changed using the directory
                             option (see the ex(C) set command).

    /usr/lib/terminfo/?/*    compiled terminal description database

 Credit

    This utility was developed at the University of California at Berkeley
    and is used with permission.

 Notes

    The /usr/lib/expreserve program can be used to restore vi buffer files
    that were lost as a result of a system crash. The program searches the
    /tmp directory for vi buffer files and places them in the directory
    /usr/preserve. The owner can retrieve these files using the -r option.

    The /usr/lib/expreserve program must be placed in the system startup
    file, /etc/rc.d/3/recovery, before the command that cleans out the /tmp
    directory.  See the System Administrator's Guide for more information on
    the /etc/rc2 scripts.

    Two options, although they continue to be supported, have been replaced
    in the documentation by the options that follow the Command Syntax Stan-
    dard (see Intro(C)).  A -r option that is not followed with an argument
    has been replaced by -L, and +command has been replaced by -c command.

    vi does not strip the high bit from 8-bit characters read in from text
    files, text insertion, and editing commands. It does not look for ``magic
    numbers'' of object files when reading in a text file.  It also writes
    out text and displays text without stripping the high bit.

    vi uses the LCCTYPE environment variable to determine if a character is
    printable, displaying the octal codes of non-printable 8-bit characters.
    It also uses LCCTYPE and LANG to convert between upper and lowercase
    characters for the tilde command and for the ignorecase option.

    When the percent sign (%) is used in a shell escape from vi via the exc-
    lamation mark (!), the ``%'' is replaced with the name of the file being
    edited. In previous versions of vi, each character in this replacement
    had the high bit set to 1 to quote it; in the current version of vi it is
    left alone.

 Warnings

    Tampering with the entries in /usr/lib/terminfo/?/* (for example, chang-
    ing or removing an entry) can affect programs such as vi that expect all
    entries to be present and correct.  In particular, removing the ``dumb''
    terminal entry may cause unexpected problems.

    Software tabs using ^T work only immediately after the autoindent.

    Left and right shifts on intelligent terminals do not make use of insert
    and delete operations in the terminal.

    Refer to the crypt(C) page for information about restrictions on the
    availability of encryption options.

 Standards conformance

    vedit and view are conformant with:

    AT&T SVID Issue 2.

    vi is conformant with:

    AT&T SVID Issue 2;
    and X/Open Portability Guide, Issue 3, 1989.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026