\documentstyle[11pt]{article}
\addtolength{\textheight}{2cm}
\addtolength{\textwidth}{2cm}
\addtolength{\oddsidemargin}{-1cm}
\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt}
\begin{document}

%
% LaTex version by Frank Wouters
%
 
\thispagestyle{empty}
\vspace*{4cm}
        
\begin{flushright}
\Huge\bf
Vi Manual\\[2cm]     
\LARGE\bf
Vi Tutorial\\[0.6cm]
\large\bf
Lee Sailer\\[1.2cm]

\LARGE\bf
Vi Reference\\[0.6cm]
\large\bf
Version 7.0\\[0.6cm]
Maarten Litmaath
\end{flushright}
\normalsize\rm

\newpage
\section{Tutorial}

\subsection{Introduction}
Vi is a text editor that will be found on nearly all Unix
machines you will ever encounter.  Even if you find another
editor you like better, it is handy to know vi for those
occasions when you find yourself using another machine.  More
importantly, many other applications you will find on Unix
machines model their user interface after vi, so good vi skills
will transfer to other programs, too.

To learn vi (short for "visual"--people in the know say "vee
eye") you can start by reading this file and trying the things
that are suggested.

Good luck!\\[2ex]
Lee Sailer,  National Fuel Gas.


\subsection{Moving through the file}
You can use {\it $\hat{}$ U} \footnote{$\hat{}$ U is an abbreviation
for $<$ctrl$>$U, pressing both the $<$ctrl$>$ and the $<$U$>$ keys
at the same time.} and {\it $\hat{}$ D} to move back and forth through 
the file.
Try it a few times.  They move by half screens. {\it $\hat{}$ F} and 
{\it $\hat{}$ B} move by full screens.

You can go directly to the twentieth line by typing {\it 20G} (that's
G, not g).  Any line number will work.  No line number defaults
to the last line in the file.  Try {\it G} and {\it 1G}, and then come back
here for more.

\subsection{Modes in vi}
There are three "modes" of operation in vi.  Right now you are in
{\bf command} mode.  Everything you type will be interpreted as a
command.  Most editors treat the characters you type as text to
be inserted, so this is one way that vi is different, and it
takes some getting used to.  In a minute, we'll see {\bf insert} mode,
which is how you create new text.  The third mode is a 
{\bf line editor} mode.

\subsection{Moving around the screen}
Another thing you need to know is how to move the cursor around
the screen.  The simplest way is to use the {\it h}, {\it j}, {\it k}, and {\it l} keys.
They work like you'd expect arrow keys to work.  Try typing the {\it j}
key a few times now and see what happens.  Then try {\it h}, {\it k}, and {\it l},
too.  The {\it j} and {\it k} keys (up and down, right?) try to stay in the
same column if they can, but will jump to the left if they
encounter a short line that is not padded out with blanks.  Also,
if a line is so loooooooooooong that vi has to wrap it around so that you can
read it (like this one), then it is still only one
line, so that {\it j} and {\it k} will skip over the second part of it.

Also handy are the 0 (zero) which moves to the start of a line, \$
which moves to the end, and {\it $\hat{} $} (it's over the 6, usually) that
moves to the first non blank in a line.

\footnotesize
\begin{verbatim}
     Try typing 0, ^, and $ on this line to see how they work.
\end{verbatim}
\normalsize

Try the {\it w}, {\it b}, and {\it e} commands to move to the beginning of the next
word, beginning of the previous word, or to the end of the
current word.

Now try typing the parentheses `(' and `)' and the braces `\{' and `\}'.
They move by sentence and block of text, more or less.

There are lots more commands like these, but that's enough for
now.

\subsection{Creating new text}
The three most used commands for inserting new text into a file
are {\it i} (insert), {\it a} (append), and {\it o} (open).  When you type an {\it i}, vi
starts inserting new text just before the place where the cursor
is. {\bf Remember} that while you are inserting text, the commands we
just learned in command mode no longer work. In insert mode,
everything you type will be inserted as text.

To get back to command mode, type the {\it $<$esc$>$} key.  In other
words, type an {\it i}, then some text, and then an {\it $<$esc$>$} to return to
command mode.  Try the {\it i} command now.  Move up a few lines, type
an {\it i} followed by some text, and then an {\it $<$esc$>$}, and see what
happens.  You can type pages and pages of text while in insert
mode.

The {\it a} command works the same way, except that it begins inserting
text just after the cursor.  The {\it o} command creates a new blank
line just below the current line, and begins inserting text
there.  There is also an {\it O} command, that opens a blank line just
above the current line.  Try {\it a}, {\it o}, and {\it O} now.

\subsection{Deleting text}
While you are in insert mode, the backspace key works the usual
way.  Also, {\it $\hat{}$ W} deletes the previous word, and your 'kill'
character backs up to the beginning of the current line. (The
kill character is usually @ or {\it $\hat{}$ U}, but might be something else. Use
{\it stty -a} to see.)

Otherwise, to delete text you should usually be in command mode
(so type {\it $<$esc$>$}). An {\it x} deletes the current character.  Type {\it dw}
to  delete to the beginning of the next word, {\it d}) to delete to the
end  of the sentence, and {\it d}\} to delete to the end of the block of
text.  In fact, a {\it d} followed by almost any cursor moving command
such as {\it b}, {\it e}, or `\{`  will delete the stuff the cursor would have
moved over.  One that is not so obvious is {\it dd}, which deletes the
entire current line.

\subsection{Oops}
Some commands modify the text that you are working on.  The {\it u}
command will undo the most recent text modifying command.
Especially useful when you accidently delete the 10 pages you
just typed in.  Just type {\it u} to get it back.

\subsection{Starting a vi session}
The command to start vi is

\footnotesize
\begin{verbatim}
    $ vi [file ...]
\end{verbatim}
\normalsize

at the command prompt.  You can type the names of zero or more files
after vi.  If you don't type any filename, vi will show you an
empty buffer to work in, and you can write it to a file later.
If you give it the name of a file that doesn't exist, it will
create it for you.  If you give vi more than one file name, you
can edit them one after another.

Vi does not modify the file on the disk until you tell it to do
so.  All operations are done on a copy of the file kept in main
memory.  Note that this sometimes places a limit on the maximum
size file vi can handle, though it helps make vi pretty fast.
                                 
\subsection{Ending a session}
To modify the file on disk, so that it includes all your edits,
you need to use the third mode, line editing.  Type a `:' to enter
line mode.  To write the buffer out to the file, type a {\it w},
followed by a carriage return (or whatever it is called on your
terminal).  All the `:' commands need a carriage return at the
end--look for $<$cr$>$ in this tutorial.

Vi does {\bf not}, repeat {\bf not not not}, make a backup copy of your file in
its original state.  As soon as you do the {\it :w} command, the
original version of the file is replaced with the current
version.  If you want a backup copy, make one yourself with a
command such as

\footnotesize
\begin{verbatim}
    $ cp april.data april.data.bak
\end{verbatim}
\normalsize

You can even do this while in vi, before the first time you write
with a {\it :w} by "forking a shell."  The `:!' command allows you
to execute any Unix shell command from within vi, so

\footnotesize
\begin{verbatim}
    :!cp file file.bak<cr>
\end{verbatim}
\normalsize

will create a backup file,

\footnotesize
\begin{verbatim}
    :!ls -l<cr>
\end{verbatim}
\normalsize

will show you a directory
listing, and

\footnotesize
\begin{verbatim}
    :!vi anotherfile<cr>
\end{verbatim}
\normalsize

will even start up another vi session in the middle of the
current one.

To exit from vi, use the {\it :q} command.  If the file has been
modified, vi will warn you.  If you really want to quit without
saving the modified file, add the "I really mean it" command like
this

\footnotesize
\begin{verbatim}
    :q!<cr>
\end{verbatim}
\normalsize

You can combine {\it :w} and {\it :q} into one command,

\footnotesize
\begin{verbatim}
    :wq<cr>
\end{verbatim}
\normalsize

which will write the buffer and then quit.  If you are editing a
list of more than one file, you can go to the next with the

\footnotesize
\begin{verbatim}
    :n<cr>
\end{verbatim}
\normalsize

command.

At any time, you can write the current buffer into or over some
other file by adding a filename to the {\it :w} command.  If you want
to write this buffer out to a file in your current directory
named tutbuf, just use

\footnotesize
\begin{verbatim}
    :w tutbuf<cr>
\end{verbatim}
\normalsize

\subsection{Searching}
The search commands are a handy way to make big jumps around a
file.  Searching can be done from wither command mode or line
mode.  In command mode, the `/' searches forward in the file and
the ? searches backwards.  Try typing

\footnotesize
\begin{verbatim}
    ?tutbuf<cr>
\end{verbatim}
\normalsize

now, to  search backwards for the string tutbuf.  Vi remembers
the last  string you searched for, so now another ?{\it $<$cr$>$} will
search again.   The `/' works the same way in the forward
direction.  By the way,  vi searches wrap around to the other end
of the file when they  hit the end.

Suppose you wanted to go back to the section on delete.  Just search for some
pattern that you guess appears there--how about "delete"?
Search for "delete" with

\footnotesize
\begin{verbatim}
    /delete<cr>
\end{verbatim}
\normalsize

and see what happens.

The pattern you search for can use the (almost) standard Unix
pattern matching language. It is very powerful, so we won't
consider it in detail here, but as useless but neat examples,

\footnotesize
\begin{verbatim}
    /Th[^e]<cr>
\end{verbatim}
\normalsize

will search for any "Th" followed by any character except an
"e", and

\footnotesize
\begin{verbatim}
    /^[A-Z].*\. *$<cr>
\end{verbatim}
\normalsize

will find any line that begins with a capital letter and ends
with a period and any number of blanks.  Try it.  Then try
something like

\footnotesize
\begin{verbatim}
    /"e"<cr>
\end{verbatim}
\normalsize

to get back here.

The same pattern matching can be used in line mode.  For example,
to change the first occurrence of "the" on the current line to
"that", you can type

\footnotesize
\begin{verbatim}
    :s/the/fathead/<cr>
\end{verbatim}
\normalsize

and to change all the occurrences, you add the "global" modifier,

\footnotesize
\begin{verbatim}
    :s/the/fathead/g<cr>
\end{verbatim}
\normalsize

\subsection{Line mode commands}
The commands that are introduced with the `:' throw vi into a
version of Unix's venerable old line editor, ed.  The current
version is named ex.  Ex and vi are really two modes in one
editor.  There are many powerful commands in line mode.  One that
is used often is two substitute one string for every occurrence
of another, not just in one line but in the entire file.  The {\it :s}
command above can be modified by putting line numbers in front of
the {\it s}.  To change all "the" into "fathead" in every line of the
file, try

\footnotesize
\begin{verbatim}
    :1,$s/the/fathead/g
\end{verbatim}
\normalsize

You can type {\it u} to undo it.  The {\it 1,\$} in front of the {\it s} says
"starting at line 1 and continuing to the last line of the file".
If you wanted to do the substitution in lines 10 through 20, just
use 10,20.  In this context, the . means the current line, so if
you just want to do the subs in the first through the current
line, use 1,. and so on.

Another handy line mode command is delete, {\it :d}.  For example

\footnotesize
\begin{verbatim}
    :d              delete current line
    :1,3d           delete lines 1 to 3
    :1,.d           delete first through current line
    :.,$d           delete current through last line
    :.,/fathead/d   delete current through next line that
                           contains the pattern "fathead"
\end{verbatim}
\normalsize

On last handy line mode command finds all the lines in the file
that match a pattern, and preints them on the screen without
modifying the file.  Try this command to get all the lines that
include the word "fathead".

\footnotesize
\begin{verbatim}
    :g/fathead/p
\end{verbatim}
\normalsize


\subsection{More editing}
There are other useful commands.  The {\it c} command lets you change
text.  For example, if you type {\it cw}, a dollar sign will appear at
the end of the current word, and you will be put in insert mode.
Everything you type will replace the current word when you type
{\it $<$esc$>$}.  Likewise, {\it c)} will allow you to change the rest of the
sentence, {\it c(} will change the first part of the sentence, {\it ct}, will
change everything up to the next comma, and more.  The {\it cc} command
changes the whole line.  You can put a small number at the
beginning of any of these commands: {\it 3cw} changes the next three
words, and so on.

When characters are deleted from the buffer, they go into an
unnamed area from which they can be recalled.  Suppose you delete
three lines with a {\it 3dd} command.  Later, a {\it p} command will put
those three lines immediately after the current line.  Try it.
A {\it P} command puts the lines before the current line.

\subsection{Vi meets the shell}
The Unix shell offers many useful utilities such as sort, awk,
wc, plus dozens of others.  These commands can be "integrated"
into vi using the `!' command (not to be confused with the `:!' line
mode command.  Using `!' and a cursor motion command, you can send
portions of your buffer to a Unix command and get the stdout of
the command back in your file.  Suppose you have a list of names
you've typed

\footnotesize
\begin{verbatim}
    Lou
    Lee
    Jim
    Mark
    Glenn
\end{verbatim}
\normalsize

(only many more names) and now you wish they were sorted.  Since
the lines make up a block of text, you can use the `!'\} command to
send them to sort.  Just move the cursor to the line containing
"Lou" and type

\footnotesize
\begin{verbatim}
    !}sort              "send block to sort"
\end{verbatim}
\normalsize

and the lines will be replaced with

\footnotesize
\begin{verbatim}
    Glenn
    Jim
    Lee
    Lou
    Mark
\end{verbatim}
\normalsize

There are five names.  Want the names back?  Use {\it u} to undo.

Say you needed to know how many names there were.  The wc -l
command counts the number of lines in its input, so send the
block to wc.  Use !\}{\it wc -l}.  The block is removed from the text,
sent to wc, and the output of wc replaces the original text.

\subsection{Macros and abbreviations}
You can define simple macros with the {\it :map} command. Suppose we
used the block sort above a lot.  Then we might use
    
\footnotesize
\begin{verbatim}
    :map <^K> !}sort
\end{verbatim}
\normalsize

to define {\it $\hat{}$ K} to be the sorter.  (You cannot type a {\it $\hat{}$ M} directly.
Use {\it $\hat{}$ V} to quote the {\it $\hat{}$ M} so that vi will ignore it.)

Are you sick and tired of typing National Fuel Gas?  Try an
abbreviation

\footnotesize
\begin{verbatim}
    :abbr nfg National Fuel Gas
\end{verbatim}
\normalsize

Now, every time you type the word, {\it nfg}, it is replaced magically
by National Fuel Gas.

\subsection{What next}
Practice makes perfect.  Use vi to create files, even if there is
a better way to do it.  You need the practice so that when you
need to do heavy modifications to that TSE input file, you can do
them quickly and efficiently.

The other thing to do is to read whatever vi manual you can find.
     
\newpage
\section{VI Reference}
%
\subsection{VI Reference}
Warning: some vi versions don't support the more esoteric features
described in this document.  You can edit/redistribute this document
freely, as long as you don't make false claims on original authorship.
             
\subsection{Legenda}

\footnotesize
\begin{verbatim}
    default values          : 1
    <*>                     : `*' must not be taken literally
    [*]                     : `*' is optional
    ^X                      : <ctrl>X
    <sp>                    : Space
    <cr>                    : Carriage return
    <lf>                    : Linefeed
    <ht>                    : Horizontal tab
    <esc>                   : Escape
    <erase>                 : Your erase character
    <kill>                  : Your kill character
    <intr>                  : Your interrupt character
    <a-z>                   : An element in the range
    N                       : Number (`*' = allowed, `-' = not appropriate)
    CHAR                    : Char unequal to <ht>|<sp>
    WORD                    : Word followed by <ht>|<sp>|<lf>
\end{verbatim}
\normalsize
            
\newpage
\subsection{Move commands (See also Display commands)}

\footnotesize
\begin{verbatim}
     N | Command            | Meaning
    ---+--------------------+-----------------------------------------------
     * | h | ^H | <erase>   | <*> chars to the left.
     * | j | <lf> | ^N      | <*> lines downward.
     * | l | <sp>           | <*> chars to the right.
     * | k | ^P             | <*> lines upward.
     * | $                  | To the end of line <*> from the cursor.
     - | ^                  | To the first CHAR of the line.
     * | _                  | To the first CHAR <*> - 1 lines lower.
     * | -                  | To the first CHAR <*> lines higher.
     * | + | <cr>           | To the first CHAR <*> lines lower.
     - | 0                  | To the first char of the line.
     * | |                  | To column <*> (<ht>: only to the endpoint).
     * | f<char>            | <*> <char>s to the right (find).
     * | t<char>            | Till before <*> <char>s to the right.
     * | F<char>            | <*> <char>s to the left.
     * | T<char>            | Till after <*> <char>s to the left.
     * | ;                  | Repeat latest `f'|`t'|`F'|`T' <*> times.
     * | ,                  | Idem in opposite direction.
     * | w                  | <*> words forward.
     * | W                  | <*> WORDS forward.
     * | b                  | <*> words backward.
     * | B                  | <*> WORDS backward.
     * | e                  | To the end of word <*> forward.
     * | E                  | To the end of WORD <*> forward.
     * | G                  | Go to line <*> (default EOF).
     * | H                  | To line <*> from top of the screen (home).
     * | L                  | To line <*> from bottom of the screen (last).
     - | M                  | To the middle line of the screen.
     * | )                  | <*> sentences forward.
     * | (                  | <*> sentences backward.
     * | }                  | <*> paragraphs forward.
     * | {                  | <*> paragraphs backward.
     - | ]]                 | To the next section (default EOF).
     - | [[                 | To the previous section (default begin of file).
     - | `<a-z>             | To the mark.
     - | '<a-z>             | To the first CHAR of the line with the mark.
     - | ``                 | To the cursor position before the latest absolute
                            |   jump (of which are examples `/' and `G').
     - | ''                 | To the first CHAR of the line on which the cursor
                            |   was placed before the latest absolute jump.
     - | /<string>          | To the next occurrence of <string>.
     - | ?<string>          | To the previous occurrence of <string>.
     - | n                  | Repeat latest `/'|`?' (next).
     - | N                  | Idem in opposite direction.
     - | %                  | Find the next bracket and go to its match
                            |   (also with `{'|`}' and `['|`]').
\end{verbatim}
\normalsize

\subsection{Searching}

\footnotesize
\begin{verbatim}
    :ta <name>              | Search in the tags file[s] where <name> is
                            |   defined (file, line), and go to it.
    ^]                      | Use the name under the cursor in a `:ta' command.
    ^T                      | Pop the previous tag off the tagstack and return
                            |   to its position.
    :[x,y]g/<string>/<cmd>  | Search globally [from line x to y] for <string>
                            |   and execute the `ex' <cmd> on each occurrence.
    :[x,y]v/<string>/<cmd>  | Execute <cmd> on the lines that don't match.
\end{verbatim}
\normalsize

\subsection{Undoing changes}

\footnotesize
\begin{verbatim}
    u                       | Undo the latest change.
    U                       | Undo all changes on a line, while not having
                            |   moved off it (unfortunately).
    :q!                     | Quit vi without writing.
    :e!                     | Re-edit a messed-up file.
\end{verbatim}
\normalsize

\subsection{Appending text}
End appending text with $<$esc$>$

\footnotesize
\begin{verbatim}
     * | a                  | <*> times after the cursor.
     * | A                  | <*> times at the end of line.
     * | i                  | <*> times before the cursor (insert).
     * | I                  | <*> times before the first CHAR of the line
     * | o                  | On a new line below the current (open).
                            |   The count is only useful on a slow terminal.
     * | O                  | On a new line above the current.
                            |   The count is only useful on a slow terminal.
     * | ><move>            | Shift the lines described by <*><move> one
                            |   shiftwidth to the right.
     * | >>                 | Shift <*> lines one shiftwidth to the right.
     * | ["<a-zA-Z1-9>]p    | Put the contents of the (default undo) buffer
                            |   <*> times after the cursor.
                            |   A buffer containing lines is put only once,
                            |   below the current line.
     * | ["<a-zA-Z1-9>]P    | Put the contents of the (default undo) buffer
                            |   <*> times before the cursor.
                            |   A buffer containing lines is put only once,
                            |   above the current line.
     * | .                  | Repeat previous command <*> times.  If the last
                            |   command before a `.' command references a
                            |   numbered buffer, the buffer number is
                            |   incremented first (and the count is ignored):
                            |
                            |   "1pu.u.u.u.u      - `walk through' buffers 1
                            |                       through 5
                            |   "1P....           - restore them
\end{verbatim}
\normalsize

\subsection{Deleting text}
Everything deleted can be stored into a buffer. This is achieved by
putting a `"' and a letter $<$a-z$>$ before the delete command. The
deleted text will be in the buffer with the used letter. If $<$A-Z$>$
is used as buffer name, the adjugate buffer $<$a-z$>$ will be augmented
instead of overwritten with the text. The undo buffer always
contains the latest change. Buffers $<$1-9$>$ contain the latest 9
LINE deletions (`"1' is most recent).

\footnotesize
\begin{verbatim}
     * | x                  | Delete <*> chars under and after the cursor.
     * | X                  | <*> chars before the cursor.
     * | d<move>            | From begin to endpoint of <*><move>.
     * | dd                 | <*> lines.
     - | D                  | The rest of the line.
     * | <<move>            | Shift the lines described by <*><move> one
                            |   shiftwidth to the left.
     * | <<                 | Shift <*> lines one shiftwidth to the left.
     * | .                  | Repeat latest command <*> times.
\end{verbatim}
\normalsize
                         
\subsection{Changing text}
End changing text with $<$esc$>$

\footnotesize
\begin{verbatim}
     * | r<char>            | Replace <*> chars by <char> - no <esc>.
     * | R                  | Overwrite the rest of the line,
                            |   appending change <*> - 1 times.
     * | s                  | Substitute <*> chars.
     * | S                  | <*> lines.
     * | c<move>            | Change from begin to endpoint of <*><move>.
     * | cc                 | <*> lines.
     * | C                  | The rest of the line and <*> - 1 next lines.
     * | =<move>            | If the option `lisp' is set, this command
                            |   will realign the lines described by <*><move>
                            |   as though they had been typed with the option
                            |   `ai' set too.
     - | ~                  | Switch lower and upper cases
                            |   (should be an operator, like `c').
     * | J                  | Join <*> lines (default 2).
     * | .                  | Repeat latest command <*> times (`J' only once).
     - | &                  | Repeat latest `ex' substitute command, e.g.
                            |   `:s/wrong/good'.
     - | :[x,y]s/<p>/<r>/<f>| Substitute (on lines x through y) the pattern <p>
                            |   (default the last pattern) with <r>.  Useful
                            |   flags <f> are `g' for `global' (i.e. change
                            |   every non-overlapping occurrence of <p>) and
                            |   `c' for `confirm' (type `y' to confirm a
                            |   particular substitution, else <cr>).  Instead
                            |   of `/' any punctuation CHAR unequal to <lf>
                            |   can be used as delimiter.
\end{verbatim}
\normalsize

\subsection{Substitute replacement patterns}
The basic meta-characters for the replacement pattern are `\&' and ` $\tilde{}$ ';
these are given as `$\backslash$\&' and `$\backslash \tilde{}$ ' when nomagic is set.  Each instance
of `\&' is replaced by the characters which the regular expression
matched.  The meta-character ` $\tilde{}$ ' stands, in the replacement
pattern, for the defining text of the previous replacement
pattern.  Other meta-sequences possible in the replacement pattern
are always introduced by the escaping character `$\backslash$'.  The sequence
`$\backslash$n' (with `n' in [1--9]) is replaced by the text matched by the
n--th regular subexpression enclosed between `$\backslash$(' and `$\backslash$)'.  The
sequences `$\backslash$u' and `$\backslash$l' cause the immediately following character
in the replacement to be converted to upper- or lower-case
respectively if this character is a letter.  The sequences `$\backslash$U' and
`$\backslash$L' turn such conversion on, either until `$\backslash$E' or `$\backslash$e' is
encountered, or until the end of the replacement pattern.

\subsection{Remembering text (yanking)}
With yank commands you can put `"$<$a--zA--Z$>$' before the command, just as
with delete commands.  Otherwise you only copy to the undo buffer.
The use of buffers $<$a-z$>$ is {\bf the} way of copying text to another file;
see the `:e $<$file$>$' command.

\footnotesize
\begin{verbatim}
     * | y<move>            | Yank from begin to endpoint of <*><move>.
     * | yy                 | <*> lines.
     * | Y                  | Idem (should be equivalent to `y$' though).
     - | m<a-z>             | Mark the cursor position with a letter.
\end{verbatim}
\normalsize

\subsection{Commands while in append or change mode}

\footnotesize
\begin{verbatim}
    ^@                      | If typed as the first character of the
                            |   insertion, it is replaced with the previous
                            |   text inserted (max. 128 chars), after which
                            |   the insertion is terminated.
    ^V                      | Deprive the next char of its special meaning
                            |   (e.g. <esc>).
    ^D                      | One shiftwidth to the left.
    0^D                     | Remove all indentation on the current line
                            |   (there must be no other chars on the line).
    ^^D                     | Idem, but it is restored on the next line.
    ^T                      | One shiftwidth to the right
    ^H | <erase>            | One char back.
    ^W                      | One word back.
    <kill>                  | Back to the begin of the change on the
                            |   current line.
    <intr>                  | Like <esc> (but you get a beep as well).
\end{verbatim}
\normalsize

\subsection{Writing, editing other files, and quitting vi}
In `:' `ex' commands `\%' denotes the current file, `\#' is a synonym for
the alternate file (which normally is the previous file).
Marks can be used for line numbers too: '$<$a-z$>$.
In the `:w' $\mid$ `:f' $\mid$ `:cd' $\mid$ `:e' $\mid$ `:n' commands shell 
meta-characters can be used.

\footnotesize
\begin{verbatim}                                    
    :q                      | Quit vi, unless the buffer has been changed.
    :q!                     | Quit vi without writing.
    ^Z                      | Suspend vi.
    :w                      | Write the file.
    :w <name>               | Write to the file <name>.
    :w >> <name>            | Append the buffer to the file <name>.
    :w! <name>              | Overwrite the file <name>.
    :x,y w <name>           | Write lines x through y to the file <name>.
    :wq                     | Write the file and quit vi; some versions quit
                            |   even if the write was unsuccessful!
                            |   Use `ZZ' instead.
    ZZ                      | Write if the buffer has been changed, and
                            |   quit vi.  If you have invoked vi with the `-r'
                            |   option, you'd better write the file
                            |   explicitly (`w' or `w!'), or quit the
                            |   editor explicitly (`q!') if you don't want
                            |   to overwrite the file - some versions of vi
                            |   don't handle the `recover' option very well.
    :x [<file>]             | Idem [but write to <file>].
    :x! [<file>]            | `:w![<file>]' and `:q'.
    :pre                    | Preserve the file - the buffer is saved as if
                            |   the system had just crashed; for emergencies,
                            |   when a `:w' command has failed and you don't
                            |   know how to save your work (see `vi -r').
    :f <name>               | Set the current filename to <name>.
    :cd [<dir>]             | Set the working directory to <dir>
                            |   (default home directory).
    :cd! [<dir>]            | Idem, but don't save changes.
    :e [+<cmd>] <file>      | Edit another file without quitting vi - the
                            |   buffers are not changed (except the undo
                            |   buffer), so text can be copied from one file to
                            |   another this way.  [Execute the `ex' command
                            |   <cmd> (default `$') when the new file has been
                            |   read into the buffer.]  <cmd> must contain no
                            |   <sp> or <ht>.  See `vi startup'.
    :e! [+<cmd>] <file>     | Idem, without writing the current buffer.
    ^^                      | Edit the alternate (normally the previous) file.
    :rew                    | Rewind the argument list, edit the first file.
    :rew!                   | Idem, without writing the current buffer.
    :n [+<cmd>] [<files>]   | Edit next file or specify a new argument list.
    :n! [+<cmd>] [<files>]  | Idem, without writing the current buffer.
    :args                   | Give the argument list, with the current file
                            |   between `[' and `]'.
\end{verbatim}
\normalsize

\subsection{Display commands (See also Move commands)}

\footnotesize
\begin{verbatim}
    ^G                      | Give file name, status, current line number
                            |   and relative position.
    ^L                      | Refresh the screen (sometimes `^P' or `^R').
    ^R                      | Sometimes vi replaces a deleted line by a `@',
                            |   to be deleted by `^R' (see option `redraw').
    [*]^E                   | Expose <*> more lines at bottom, cursor
                            |   stays put (if possible).
    [*]^Y                   | Expose <*> more lines at top, cursor
                            |   stays put (if possible).
    [*]^D                   | Scroll <*> lines downward
                            |   (default the number of the previous scroll;
                            |   initialization: half a page).
    [*]^U                   | Scroll <*> lines upward
                            |   (default the number of the previous scroll;
                            |   initialization: half a page).
    [*]^F                   | <*> pages forward.
    [*]^B                   | <*> pages backward (in older versions `^B' only
                            |   works without count).
\end{verbatim}
\normalsize

If in the next commands the field $<$wi$>$ is present, the windowsize
will change to $<$wi$>$. The window will always be displayed at the
bottom of the screen.

\footnotesize
\begin{verbatim}                                           
    [*]z[wi]<cr>            | Put line <*> at the top of the window
                            |   (default the current line).
    [*]z[wi]+               | Put line <*> at the top of the window
                            |   (default the first line of the next page).
    [*]z[wi]-               | Put line <*> at the bottom of the window
                            |   (default the current line).
    [*]z[wi]^               | Put line <*> at the bottom of the window
                            |   (default the last line of the previous page).
    [*]z[wi].               | Put line <*> in the centre of the window
                            |   (default the current line).
\end{verbatim}
\normalsize

\newpage
\subsection{Mapping and abbreviation}
When mapping take a look at the options `to' and `remap' (below).

\footnotesize
\begin{verbatim}
    :map <string> <seq>     | <string> is interpreted as <seq>, e.g.
                            |   `:map ^C :!cc %^V<cr>' to invoke `cc' (the C
                            |   compiler) from within the editor
                            |   (vi replaces `%' with the current file name).
    :map                    | Show all mappings.
    :unmap <string>         | Deprive <string> of its mapping.  When vi
                            |   complains about non-mapped macros (whereas no
                            |   typos have been made), first do something like
                            |   `:map <string> Z', followed by
                            |   `:unmap <string>' (`Z' must not be a macro
                            |   itself), or switch to `ex' mode first with `Q'.
    :map! <string> <seq>    | Mapping in append mode, e.g.
                            |   `:map! \be begin^V<cr>end;^V<esc>O<ht>'.
                            |   When in append mode <string> is preceded by
                            |   `^V', no mapping is done.
    :map!                   | Show all append mode mappings.
    :unmap! <string>        | Deprive <string> of its mapping (see `:unmap').
    :ab <string> <seq>      | Whenever in append mode <string> is preceded and
                            |   followed by a breakpoint (e.g. <sp> or `,'), it
                            |   is interpreted as <seq>, e.g.
                            |   `:ab ^P procedure'.  A `^V' immediately
                            |   following <string> inhibits expansion.
    :ab                     | Show all abbreviations.
    :unab <string>          | Do not consider <string> an abbreviation
                            |   anymore (see `:unmap').
    @<a-z>                  | Consider the contents of the named register a
                            |   command, e.g.:
                            |       o0^D:s/wrong/good/<esc>"zdd
                            |   Explanation:
                            |       o              - open a new line
                            |       0^D            - remove indentation
                            |       :s/wrong/good/ - this input text is an
                            |                        `ex' substitute command
                            |       <esc>          - finish the input
                            |       "zdd           - delete the line just
                            |                        created into register `z'
                            |   Now you can type `@z' to replace `wrong'
                            |   with `good' on the current line.
    @@                      | Repeat last register command.
\end{verbatim}
\normalsize

\newpage
\subsection{Switch and shell commands}

\footnotesize
\begin{verbatim}
    Q | ^\ | <intr><intr>   | Switch from vi to `ex'.
    :                       | An `ex' command can be given.
    :vi                     | Switch from `ex' to vi.
    :sh                     | Execute a subshell, back to vi by `^D'.
    :[x,y]!<cmd>            | Execute a shell <cmd> [on lines x through y;
                            |   these lines will serve as input for <cmd> and
                            |   will be replaced by its standard output].
    :[x,y]!! [<args>]       | Repeat last shell command [and append <args>].
    :[x,y]!<cmd> ! [<args>] | Use the previous command (the second `!') in a
                            |   new command.
    [*]!<move><cmd>         | The shell executes <cmd>, with as standard
                            |   input the lines described by <*><move>,
                            |   next the standard output replaces those lines
                            |   (think of `cb', `sort', `nroff', etc.).
    [*]!<move>!<args>       | Append <args> to the last <cmd> and execute it,
                            |   using the lines described by the current
                            |   <*><move>.
    [*]!!<cmd>              | Give <*> lines as standard input to the
                            |   shell <cmd>, next let the standard output
                            |   replace those lines.
    [*]!!! [<args>]         | Use the previous <cmd> [and append <args> to it].
    :x,y w !<cmd>           | Let lines x to y be standard input for <cmd>
                            |   (notice the <sp> between the `w' and the `!').
    :r!<cmd>                | Put the output of <cmd> onto a new line.
    :r <name>               | Read the file <name> into the buffer.
\end{verbatim}
\normalsize

\newpage
\subsection{Vi startup}

\footnotesize
\begin{verbatim}
    vi [<files>]            | Edit the files, start with the first page of
                            |   the first file.
\end{verbatim}
\normalsize

The editor can be initialized by the shell variable `EXINIT', which
looks like:

\footnotesize
\begin{verbatim}
            EXINIT='<cmd>|<cmd>|...'
            <cmd>: set options
                   map ...
                   ab ...
            export EXINIT (in the Bourne shell)
\end{verbatim}
\normalsize

However, the list of initializations can also be put into a file.
If this file is located in your home directory, and is named `.exrc'
{\bf and} the variable `EXINIT' is {\bf not} set, the list will be executed
automatically at startup time. However, vi will always execute the
contents of a `.exrc' in the current directory, if you own the file.
Else you have to give the execute (`source') command yourself:

\footnotesize
\begin{verbatim}
            :so file
\end{verbatim}
\normalsize

In a `.exrc' file a comment is introduced with a double quote character:
the rest of the line is ignored.  Exception: if the last command on the
line is a `map[!]' or `ab' command or a shell escape, a trailing comment
is not recognized, but considered part of the command.

On-line initializations can be given with `vi $+<$cmd$>$ file', e.g.:

\footnotesize
\begin{verbatim}
    vi +x file              | The cursor will immediately jump to line x
                            |   (default last line).
    vi +/<string> file      | Jump to the first occurrence of <string>.
\end{verbatim}
\normalsize

You can start at a particular tag with:

\footnotesize
\begin{verbatim}
    vi -t <tag>             | Start in the right file in the right place.
\end{verbatim}
\normalsize
 
Sometimes (e.g. if the system crashed while you were editing) it is
possible to recover files lost in the editor by `vi -r file'.  A plain
`vi -r' command shows the files you can recover.
If you just want to view a file by using vi, and you want to avoid any
change, instead of vi you can use the `view' or `vi -R' command:
the option `readonly' will be set automatically (with `:w!' you can
override this option).

\newpage
\subsection{The most important options}

\footnotesize
\begin{verbatim}  
    ai                      | autoindent - In append mode after a <cr> the
                            |   cursor will move directly below the first
                            |   CHAR on the previous line.  However, if the
                            |   option `lisp' is set, the cursor will align
                            |   at the first argument to the last open list.
    aw                      | autowrite - Write at every shell escape
                            |   (useful when compiling from within vi).
    dir=<string>            | directory - The directory for vi to make
                            |   temporary files (default `/tmp').
    eb                      | errorbells - Beeps when you goof
                            |   (not on every terminal).
    ic                      | ignorecase - No distinction between upper and
                            |   lower cases when searching.
    lisp                    | Redefine the following commands:
                            |   `(', `)'   - move backward (forward) over
                            |                S-expressions
                            |   `{', `}'   - idem, but don't stop at atoms
                            |   `[[', `]]' - go to previous (next) line
                            |                beginning with a `('
                            |   See option `ai'.
    list                    | <lf> is shown as `$', <ht> as `^I'.
    magic                   | If this option is set (default), the chars `.',
                            |   `[' and `*' have special meanings within search
                            |   and `ex' substitute commands.  To deprive such
                            |   a char of its special function it must be
                            |   preceded by a `\'.  If the option is turned off
                            |   it's just the other way around.  Meta-chars:
                            |   ^<string>    - <string> must begin the line
                            |   <string>$    - <string> must end the line
                            |   .            - matches any char
                            |   [a-z]        - matches any char in the range
                            |   [^a-z]       - any char not in the range
                            |   [<string>]   - matches any char in <string>
                            |   [^<string>]  - any char not in <string>
                            |   <char>*      - 0 or more <char>s
                            |   \<<string>   - <string> must begin a word
                            |   <string>\>   - <string> must end a word
    modeline                | When you read an existing file into the buffer,
                            |   and this option is set, the first and last 5
                            |   lines are checked for editing commands in the
                            |   following form:
                            |
                            |     <sp>vi:set options|map ...|ab ...|!...:
                            |
                            |   Instead of <sp> a <ht> can be used, instead of
                            |   `vi' there can be `ex'.  Warning: this option
                            |   could have nasty results if you edit a file
                            |   containing `strange' modelines.
    nu                      | number - Numbers before the lines.
    para=<string>           | paragraphs - Every pair of chars in <string> is
                            |   considered a paragraph delimiter nroff macro
                            |   (for `{' and `}').  A <sp> preceded by a `\'
                            |   indicates the previous char is a single letter
                            |   macro.  `:set para=P\ bp' introduces `.P' and
                            |   `.bp' as paragraph delimiters.  Empty lines and
                            |   section boundaries are paragraph boundaries
                            |   too.
    redraw                  | The screen remains up to date.
    remap                   | If on (default), macros are repeatedly
                            |   expanded until they are unchanged.
                            |   Example: if `o' is mapped to `A', and `A'
                            |   is mapped to `I', then `o' will map to `I'
                            |   if `remap' is set, else it will map to `A'.
    report=<*>              | Vi reports whenever e.g. a delete
                            |   or yank command affects <*> or more lines.
    ro                      | readonly - The file is not to be changed.
                            |   However, `:w!' will override this option.
    sect=<string>           | sections - Gives the section delimiters (for `[['
                            |   and `]]'); see option `para'. A `{' beginning a
                            |   line also starts a section (as in C functions).
    sh=<string>             | shell - The program to be used for shell escapes
                            |   (default `$SHELL' (default `/bin/sh')).
    sw=<*>                  | shiftwidth - Gives the shiftwidth (default 8
                            |   positions).
    sm                      | showmatch - Whenever you append a `)', vi shows
                            |   its match if it's on the same page; also with
                            |   `{' and `}'.  If there's no match at all, vi
                            |   will beep.
    taglength=<*>           | The number of significant characters in tags
                            |   (0 = unlimited).
    tags=<string>           | The space-separated list of tags files.
    terse                   | Short error messages.
    to                      | timeout - If this option is set, append mode
                            |   mappings will be interpreted only if they're
                            |   typed fast enough.
    ts=<*>                  | tabstop - The length of a <ht>; warning: this is
                            |   only IN the editor, outside of it <ht>s have
                            |   their normal length (default 8 positions).
    wa                      | writeany - No checks when writing (dangerous).
    warn                    | Warn you when you try to quit without writing.
    wi=<*>                  | window - The default number of lines vi shows.
    wm=<*>                  | wrapmargin - In append mode vi automatically
                            |   puts a <lf> whenever there is a <sp> or <ht>
                            |   within <wm> columns from the right margin
                            |   (0 = don't put a <lf> in the file, yet put it
                            |   on the screen).
    ws                      | wrapscan - When searching, the end is
                            |   considered `stuck' to the begin of the file.
    :set <option>           | Turn <option> on.
    :set no<option>         | Turn <option> off.
    :set <option>=<value>   | Set <option> to <value>.
    :set                    | Show all non-default options and their values.
    :set <option>?          | Show <option>'s value.
    :set all                | Show all options and their values.
\end{verbatim}
\normalsize

\end{document}
