the reformatted Vi Reference (patchlevel 4)
Maarten Litmaath
maart at cs.vu.nl
Tue Sep 5 12:23:32 AEST 1989
Some small fixes, some additions (Diomidis & me), prints nicely (Blair).
No use to post context diffs. :-)
Your OS should have the `tr' (translate) command, else you must edit the
CTRL_L assignment below to use a hard ^L.
Enjoy.
: This is a shar archive. Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin:/usr/ucb
CTRL_L="`echo L | tr L '\14'`"
echo Extracting 'vi.ref.4'
sed -e 's/^X//' \
-e "s/^Control-L$/$CTRL_L/" > 'vi.ref.4' << '+ END-OF-FILE ''vi.ref.4'
X
X
X
X
X
X ////////////////////////////////////////////////////////////////////////
X / VI REFERENCE (by maart at cs.vu.nl) /
X ////////////////////////////////////////////////////////////////////////
X
X Warning: some vi versions don't support the more esoteric features
X described in this document. You can edit/redistribute this document
X freely, as long as you don't make false claims on original authorship.
X
X default values : 1
X ^X : <ctrl>x
X [*] : * is optional
X <*> : * must not be taken literally
X <sp> : space
X <cr> : carriage return
X <lf> : linefeed
X <ht> : horizontal tab
X <esc> : escape
X <erase> : your erase character
X <kill> : your kill character
X <intr> : your interrupt character
X <a-z> : an element in the range
X N : number (* = allowed, - = not used)
X CHAR : char unequal to <ht>|<sp>
X WORD : word followed by <ht>|<sp>|<lf>
XControl-L
X
X
X
X
X
X /////////////////
X / move commands /
X /////////////////
X
X N | Command | Meaning
X ---+--------------------+-----------------------------------------------
X * | h | ^H | <*> chars to the left
X * | j | <lf> | ^N | <*> lines downward
X * | l | <sp> | <*> chars to the right
X * | k | ^P | <*> lines upward
X * | $ | to the end of line <*> from the cursor
X - | ^ | to the first CHAR of the line
X * | _ | to the first CHAR <*> - 1 lines lower
X * | - | to the first CHAR <*> lines higher
X * | + | <cr> | to the first CHAR <*> lines lower
X - | 0 | to the first char of the line
X * | | | to column <*> (<ht>: only to the endpoint!)
X * | f<char> | <*> <char>s to the right (find)
X * | t<char> | till before <*> <char>s to the right
X * | F<char> | <*> <char>s to the left
X * | T<char> | till after <*> <char>s to the left
X * | ; | repeat latest "f"|"t"|"F"|"T" <*> times
X * | , | idem in opposite direction
X * | w | <*> words forward
X * | W | <*> WORDS forward
X * | b | <*> words backward
X * | B | <*> WORDS backward
X * | e | to the end of word <*> forward
X * | E | to the end of WORD <*> forward
X * | G | go to line <*> (default EOF)
X * | H | to line <*> from top of the screen (home)
X * | L | to line <*> from bottom of the screen (last)
X - | M | to the middle line of the screen
X * | ) | <*> sentences forward
X * | ( | <*> sentences backward
X * | } | <*> paragraphs forward
X * | { | <*> paragraphs backward
X - | ]] | to the next section (default EOF)
X - | [[ | to the previous section (default begin of file)
X - | `<a-z> | to the mark
X - | '<a-z> | to the first CHAR of the line with the mark
X - | `` | to the cursor position before the latest absolute
X | jump (of which are examples "/" and "G")
X - | '' | to the first CHAR of the line on which the cursor
X | was placed before the latest absolute jump
X - | /<string> | to the next occurrence of <string>
X - | ?<string> | to the previous occurrence of <string>
X - | n | repeat latest "/"|"?" (next)
X - | N | idem in opposite direction
X - | % | find the next bracket and go to its match
X | (also { } and [ ])
XControl-L
X
X
X
X
X
X /////////////////////////
X / searching (see above) /
X /////////////////////////
X
X ^] | search in the tags file where the function
X | under the cursor is defined (file, line) and
X | go to it
X :[x,y]g/<string>/<cmd> | search globally [from line x to y] for <string>
X | and execute the "ex" <cmd> on each occurrence
X
X ///////////////////
X / undoing changes /
X ///////////////////
X
X u | undo the latest change
X U | undo all changes on a line, while not having
X | moved off it (unfortunately)
X :q! | quit vi without writing
X :e! | re-edit a messed-up file
X
X ///////////////////////////////////
X / appending text (end with <esc>) /
X ///////////////////////////////////
X
X * | a | <*> times after the cursor
X * | A | <*> times at the end of line
X * | i | <*> times before the cursor (insert)
X * | I | <*> times before the first CHAR of the line
X * | o | on a new line below the current (open)
X | the count is only useful on a slow terminal
X * | O | on a new line above the current
X | the count is only useful on a slow terminal
X * | ><move> | shift the lines described by <*><move> one
X | shiftwidth to the right (layout)
X * | >> | shift <*> lines one shiftwidth to the right
X * | ["<a-z1-9>]p | put the contents of the (default undo)
X | buffer <*> times after the cursor;
X | a buffer containing lines is put only once,
X | below the current line
X * | ["<a-z1-9>]P | put the contents of the (default undo) buffer <*>
X | times before the cursor
X | a buffer containing lines is put only once, above
X | the current line
X * | . | repeat latest command <*> times
X | if the last command before a "." command
X | references a numbered buffer, the buffer number
X | is incremented first (and the count is ignored):
X |
X | "1pu.u.u.u.u - `walk through' buffers 1
X | through 5
X | "1P.... - restore them
XControl-L
X
X
X
X
X
X /////////////////
X / deleting text /
X /////////////////
X
X Everything deleted can be stored into a buffer. This is achieved by
X putting a " and a letter <a-z> before the delete command. The
X deleted text will be in the buffer with the used letter. If <A-Z>
X is used as buffer name, the adjugate buffer <a-z> will be augmented
X instead of overwritten with the text. The undo buffer always
X contains the latest change. Buffers "<1-9> contain the latest 9
X LINE deletions ("1 is most recent).
X
X * | x | delete <*> chars under and after the cursor
X * | X | <*> chars before the cursor
X * | d<move> | from begin to endpoint of <*><move>
X * | dd | <*> lines
X - | D | the rest of the line
X * | <<move> | shift the lines described by <*><move> one
X | shiftwidth to the left (layout)
X * | << | shift <*> lines one shiftwidth to the left
X * | . | repeat latest command <*> times
X
X //////////////////////////////////
X / changing text (end with <esc>) /
X //////////////////////////////////
X
X * | r<char> | replace <*> chars by <char> - no <esc>
X * | R | overwrite the rest of the line,
X | appending change <*> - 1 times
X * | s | substitute <*> chars
X * | S | <*> lines
X * | c<move> | change from begin to endpoint of <*><move>
X * | cc | <*> lines
X * | C | the rest of the line and <*> - 1 next lines
X * | =<move> | if the option 'lisp' is set, this command
X | will realign the lines described by <*><move>
X | as though they had been typed with the option
X | 'ai' set too
X - | ~ | switch lower and upper cases
X * | J | join <*> lines (default 2)
X * | . | repeat latest command <*> times ("J" only once)
X - | & | repeat latest "ex" substitute command, e.g.
X | ":s/wrong/good"
XControl-L
X
X
X
X
X
X ///////////////////////////////////
X / substitute replacement patterns /
X ///////////////////////////////////
X
X The basic metacharacters for the replacement pattern are `&' and `~';
X these are given as `\&' and `\~' when nomagic is set. Each instance
X of `&' is replaced by the characters which the regular expression
X matched. The meta- character `~' stands, in the replacement
X pattern, for the defining text of the previous replacement
X pattern. Other metasequences possible in the replacement pattern
X are always introduced by the escaping character `\'. The sequence
X `\n' (with `n' in [1-9]) is replaced by the text matched by the
X n-th regular subexpression enclosed between `\(' and `\)'. The
X sequences `\u' and `\l' cause the immediately following character
X in the replacement to be converted to upper- or lower-case
X respectively if this character is a letter. The sequences `\U' and
X `\L' turn such conversion on, either until `\E' or `\e' is
X encountered, or until the end of the replacement pattern.
X
X //////////////////////////////
X / remembering text (yanking) /
X //////////////////////////////
X
X With yank commands you can put "<a-z> before the command, just as
X with delete commands. Otherwise you only copy to the undo buffer.
X The use of buffers <a-z> is THE way of copying text to another
X file; see the ":e <file>" command.
X
X * | y<move> | yank from begin to endpoint of <*><move>
X * | yy | <*> lines
X * | Y | idem (should be equivalent to "y$" though)
X - | m<a-z> | mark the cursor position with a letter
X
X ////////////////////////////////////////
X / commands while in append|change mode /
X ////////////////////////////////////////
X
X ^@ | if typed as the first character of the
X | insertion, it is replaced with the previous
X | text inserted (max. 128 chars), after which
X | the insertion is terminated
X ^V | deprive the next char of its special meaning
X | (e.g. <esc>)
X ^D | one shiftwidth to the left
X 0^D | remove all indentation on the current line
X | (there must be no other chars on the line)
X ^^D | idem, except that it is restored on the next line
X ^T | one shiftwidth to the right
X ^H | <erase> | one char back
X ^W | one word back
X <kill> | back to the begin of the change on the
X | current line
X <intr> | like <esc>
XControl-L
X
X
X
X
X
X /////////////////////////////////////////////////
X / writing, editing other files, and quitting vi /
X /////////////////////////////////////////////////
X
X :q | quit vi, unless the buffer has been changed
X :q! | quit vi without writing
X :w | write the file
X :w <name> | write to the file <name>
X :w >> <name> | append the buffer to the file <name>
X :w! <name> | overwrite the file <name>
X :x,y w <name> | write lines x through y to the file <name>
X :wq | write the file and quit vi, WITHOUT
X | checking if the write has been
X | successful (use "ZZ" instead)
X ZZ | write if the buffer has been changed, and
X | quit vi; if you have invoked vi with the "-r"
X | option, you'd better write the file
X | explicitly ("w" or "w!"), or quit the
X | editor explicitly ("q!") if you don't want
X | to overwrite the file - some versions of vi
X | don't handle the "recover" option very well
X :x | idem
X :x! | ":w!" and ":q"
X :e <file> | edit another file without quitting vi - the
X | buffers are not changed (except the undo
X | buffer), so text can be copied from one
X | file to another this way
X :e! <file> | idem, without writing the current buffer
X :e# | edit the previous file
X ^^ | idem
X :rew | edit the first file (when "vi file1 file2 ...")
X :rew! | idem, without writing the current buffer
X :n [<file>] | edit the next file
X :n! [<file>] | idem, without writing the current buffer
XControl-L
X
X
X
X
X
X ////////////////////
X / display commands /
X ////////////////////
X
X ^G | give current line number and relative position
X ^L | refresh the screen (sometimes "^P" or "^R")
X ^R | sometimes vi replaces a deleted line by
X | a '@', to be deleted by "^R" (also with
X | option 'noredraw')
X [*]^E | expose <*> more lines at bottom, cursor
X | stays put (if possible)
X [*]^Y | expose <*> more lines at top, cursor
X | stays put (if possible)
X [*]^D | scroll <*> lines downward
X | (default the number of the previous scroll;
X | initialization: half a page)
X [*]^U | scroll <*> lines upward
X | (default the number of the previous scroll;
X | initialization: half a page)
X [*]^F | <*> pages forward
X [*]^B | <*> pages backward (in older versions "^B" only
X | works without count)
X
X If in the next commands the field <wi> is present, the windowsize
X will change to <wi>. The window will always be displayed at the
X bottom of the screen.
X
X [*]z[wi]<cr> | put line <*> at the top of the window
X | (default the current line)
X [*]z[wi]+ | put line <*> at the top of the window
X | (default the first line of the next page)
X [*]z[wi]- | put line <*> at the bottom of the window
X | (default the current line)
X [*]z[wi]. | put line <*> in the centre of the window
X | (default the current line)
XControl-L
X
X
X
X
X
X ////////////////////////////
X / mapping and abbreviation /
X ////////////////////////////
X
X When mapping take a look at the options 'to' and 'remap' (below).
X
X :map <string> <seq> | <string> is interpreted as <seq>, e.g.
X | ":map ^C :!cc %^V<cr>" to compile from within vi
X | (vi replaces % with the current file name)
X :map | show all mappings
X :unmap <string> | deprive <string> of its mapping
X | when vi complains about non-mapped macros
X | (whereas no typos have been made), first do
X | something like ":map <string> Z", followed
X | by ":unmap <string>" ('Z' must not be a
X | macro itself), or switch to "ex" mode first
X :map! <string> <seq> | mapping in append mode, e.g.
X | ":map! \be begin^V<cr>end;^V<esc>O<ht>"
X | when <string> is preceded by ^V, no
X | mapping is done
X :map! | show all append mode mappings
X :unmap! <string> | deprive <string> of its mapping (see ":unmap")
X :ab <string> <seq> | whenever in append mode <string> is followed
X | by a breakpoint (e.g. <sp> or ','), it is
X | interpreted as <seq>, e.g. ":ab p procedure"
X | a char preceded by ^V is not considered
X | a breakpoint
X :ab | show all abbreviations
X :unab <string> | do not consider <string> an abbreviation
X | anymore (see ":unmap")
X @<a-z> | consider the contents of the named register a
X | command, e.g.:
X | o0^D:s/wrong/good/<esc>"zdd
X | explanation:
X | o - open a new line
X | 0^D - remove indentation
X | :s/wrong/good/ - this input text is an
X | "ex" substitute command
X | <esc> - finish the input
X | "zdd - delete the line just
X | created into register 'z'
X | now you can type @z to substitute `wrong'
X | by `good' on the current line
X @@ | repeat last register command
XControl-L
X
X
X
X
X
X /////////////////////////////
X / switch and shell commands /
X /////////////////////////////
X
X Q | ^\ | <intr><intr> | switch from vi to "ex"
X : | an "ex" command can be given
X :vi | switch from "ex" to vi
X :sh | execute a subshell, back to vi by ^D
X :!<cmd> | execute a shell <cmd>
X :!! | repeat the last shell command
X [*]!<move><cmd> | the shell executes <cmd>, with as standard
X | input the lines described by <*><move>,
X | next the standard output replaces those lines
X | (think of cb, sort, nroff, etc.)
X [*]!<move>!<args> | append <args> to the last <cmd> and execute it,
X | using the lines described by the current
X | <*><move>
X [*]!!<cmd> | give <*> lines as standard input to the
X | shell <cmd>, next let the standard output
X | replace those lines
X [*]!!! [<args>] | use the previous <cmd> (and append <args> to it)
X :x,y w !<cmd> | let lines x to y be standard input for <cmd>
X | (notice the space between 'w' and '!')
X :r!<cmd> | put the output of <cmd> onto a new line
X :r <name> | read the file <name> into the buffer
XControl-L
X
X
X
X
X
X //////////////
X / vi startup /
X //////////////
X
X vi [file] : edit the file and display the first page
X
X The editor can be initialized by the shell variable EXINIT, which
X looks like:
X
X EXINIT='<cmd>|<cmd>|...'
X <cmd>: set options
X map ...
X ab ...
X export EXINIT (in the Bourne shell)
X
X However, the list of initializations can also be put into a file.
X If this file is located in your home directory, and is named
X ".exrc" AND the variable EXINIT is NOT set, the list will be
X executed automatically at startup time. If the 3 conditions are not
X met, you have to give the execute command yourself:
X
X :source file
X or
X :so file
X
X On-line initializations can be given with "vi +<cmd> file", e.g.:
X
X vi +x file | the cursor will immediately jump to line x
X | (default last line)
X vi +/<string> file | ~ to the first occurrence of <string>
X
X You can start at a particular tag with:
X
X vi -t <tag> | starts in the right file in the right place
X
X Sometimes (e.g. if the system crashed while you were editing) it is
X possible to recover files lost in the editor by "vi -r file". If
X you just want to view a file by using vi, and you want to avoid any
X change, instead of vi you can use the "view" or "vi -R" command:
X the option 'readonly' will be set automatically (with ":w!" you can
X override this option).
XControl-L
X
X
X
X
X
X //////////////////////////////
X / the most important options /
X //////////////////////////////
X
X ai | autoindent - in append mode after a <cr> the
X | cursor will move directly below the first
X | CHAR on the previous line. However, if the
X | option 'lisp' is set, the cursor will align
X | at the first argument to the last open list.
X aw | autowrite - write at every shell escape
X | (useful when compiling from within vi)
X dir=<string> | directory - the directory for vi to make
X | temporary files (default /tmp)
X eb | errorbells - beeps when you goof
X | (not on every terminal)
X ic | ignorecase - no distinction between upper and
X | lower cases when searching
X lisp | redefine the following commands:
X | "(", ")" - move backward (forward) over
X | S-expressions
X | "{", "}" - idem, but don't stop at atoms
X | "[[", "]]" - go to previous (next) line
X | beginning with a '('
X | see option 'ai'
X list | <lf> is shown as '$', <ht> as '^I'
X magic | some metachars can be used when searching:
X | ^<string> - <string> must begin the line
X | <string>$ - <string> must end the line
X | . - matches any char
X | [a-z] - matches any char in the range
X | [<string>] - matches any char in <string>
X | [^<string>] - matches any char not in <string>
X | <char>* - 0 or more <char>s
X | \<<string>\> - <string> must be a word
X nu | number - numbers before the lines
X para=<string> | paragraphs - every pair of chars in <string> is
X | considered a paragraph delimiter nroff macro
X | (for "{" and "}").
X | a <sp> preceded by a '\' indicates that
X | the previous char is a single letter
X | macro. ":set para=P\ bp" introduces '.P'
X | and '.bp' as paragraph delimiters.
X | completely empty lines and section
X | boundaries are paragraph boundaries too.
X redraw | the screen remains up to date
X remap | if on (default), macros are repeatedly
X | expanded until they are unchanged.
X | Example: if 'o' is mapped to 'O', and 'O'
X | is mapped to 'I', then 'o' will map to 'I'
X | if "remap" is set, else it will map to 'O'.
X report=<*> | vi reports whenever e.g. a delete
X | or yank command affects <*> or more lines
X ro | readonly - the file is not to be changed
X | however, ":w!" will override this option
XControl-L
X
X
X
X
X
X sect=<string> | sections - gives the section delimiters
X | (for "[[" and "]]"); see option 'para',
X | however a '{' as first char on a line also
X | starts a section (as in C functions)
X sh=<string> | shell - which program is to be used for
X | shell escapes
X sw=<*> | shiftwidth - gives the shiftwidth (default sw=8)
X sm | showmatch - whenever you append a ')', vi
X | tries to show its match by putting the cursor
X | for a moment onto it (also with { })
X terse | short error messages
X to | timeout - if this option is set, append mode
X | mappings will be interpreted only if they're
X | typed fast enough
X ts=<*> | tabstop - the length of a <ht>;
X | warning: this is only IN the editor,
X | outside of it <ht>s have their normal
X | length (default ts=8)
X wa | writeany - no checks when writing (dangerous)
X warn | warn you when you try to quit without writing
X wi=<*> | window - the default number of lines vi shows
X wm=<*> | wrapmargin - when in append mode vi
X | automatically puts a <lf> whenever there is
X | a <sp> or <ht> within <wm> columns from the
X | right margin
X ws | wrapscan - when searching, the end is
X | considered `stuck' to the begin of the file
X
X :set <option> | turn <option> on
X :set no<option> | turn <option> off
X :set <option>=<value> | set <option> to <value>
X :set | show all non-default options and their values
X :set <option>? | show <option>'s value
X :set all | show all options and their values
X
X
X /////////////////
X / contributions /
X /////////////////
X
X Maarten Litmaath <maart at cs.vu.nl>
X Rich Salz <rsalz at bbn.com>
X Eamonn McManus <emcmanus at cs.tcd.ie>
X Diomidis Spinellis <diomidis%ecrcvax.uucp at pyramid.pyramid.com>
X Blair P. Houghton <bph at buengc.bu.edu>
X
X Patchlevel: 4
+ END-OF-FILE vi.ref.4
chmod 'u=rw,g=r,o=r' 'vi.ref.4'
set `wc -c 'vi.ref.4'`
count=$1
case $count in
27632) :;;
*) echo 'Bad character count in ''vi.ref.4' >&2
echo 'Count should be 27632' >&2
esac
exit 0
--
C, the programming language that's the same |Maarten Litmaath @ VU Amsterdam:
in all reference frames. |maart at cs.vu.nl, mcvax!botter!maart
More information about the Comp.unix.questions
mailing list