#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	vi.tut
#	vi.advanced
#	vi.beginner
# This archive created: Thu Feb  1 12:41:54 1996
export PATH; PATH=/bin:$PATH
echo shar: extracting "'vi.tut'" '(407 characters)'
if test -f 'vi.tut'
then
	echo shar: will not over-write existing file "'vi.tut'"
else
sed 's/^X//' << \SHAR_EOF > 'vi.tut'
X#
X#This makes the user's EXINIT variable set to the 'correct' things.
X#I don't know what will happen if they also have a .exrc file!
Xif ($1 != "beginner" && $1 != "advanced") then
X  echo Usage: $0 beginner or $0 advanced
X  exit
Xendif
X
Xif ($?EXINIT) then
X  set oexinit="$EXINIT"
X  setenv EXINIT 'se ts=4 wm=8 sw=4'
Xendif
X
Xvi /usr/local/bin/vi.{$1}
X
Xonintr:
Xif($?oexinit)then
X  setenv EXINIT "$oexinit"
Xendif
SHAR_EOF
if test 407 -ne "`wc -c < 'vi.tut'`"
then
	echo shar: error transmitting "'vi.tut'" '(should have been 407 characters)'
fi
chmod +x 'vi.tut'
fi # end of overwriting check
echo shar: extracting "'vi.advanced'" '(70997 characters)'
if test -f 'vi.advanced'
then
	echo shar: will not over-write existing file "'vi.advanced'"
else
sed 's/^X//' << \SHAR_EOF > 'vi.advanced'
XSection 26: Index to the rest of the tutorial
X
XThe remainder of the tutorial can be perused at your leisure.  Simply find the
Xtopic of interest in the following list, and {/Section xx:/^M} to get to the
Xappropriate section.  (Remember that ^M means the return key) 
X
XThe material in the following sections is not necessarily in a bottom up
Xorder.  It should be fairly obvious that if a section mentions something with
Xwhich you are not familiar, say, buffers, you might {/buffer/^M} followed by
Xseveral {n} to do a keyword search of the file for more details on that item.
XAnother point to remember is that commands are surrounded by curly-braces and
Xcan therefore be found rather easily.  To see where, say, the X command is
Xused try {/{X}/^M}.  Subsequent {n} will show you other places the command was
Xused.  We have tried to maintain the convention of placing the command letter
Xsurrounded by curly-braces on the section line where that command is
Xmentioned.
X
XFinally, you should have enough 'savvy' at this point to be able to do your
Xown experimentation with commands without too much hand-holding on the part of
Xthe tutorial.  Experimentation is the best way to learn the effects of the
Xcommands.
X
X Section      Topic - description
X -------      -------------------
X(Sections 1 through 25 are located in the file vi.beginner.)
X    1         introduction: {^F} {ZZ}
X    2         introduction (con't) and positioning: {^F} {^B}
X    3         introduction (con't) and positioning: {^F} {^B}
X    4         positioning: {^F} {^B} ^M (return key)
X    5         quitting: {:q!} ^M key
X    6         marking, cursor and screen positioning: {m} {G} {'} {z}
X    7         marking, cursor and screen positioning: {m} {G} {'} {z}
X    8         marking, cursor and screen positioning: {z} {m} {'}
X    9         marking and positioning: {m} {''}
X   10         line positioning: {^M} {-}
X   11         scrolling with {^M}
X   12         scrolling with {-} and screen adjustment {z}
X   13         notes on use of tutorial
X   14         other scrolling and postioning commands: {^E} {^Y} {^D} {^U}
X   15         searching: {/ .. /^M}
X   16         searching: {? .. ?^M} {n} (in search strings ^ $)
X   17         searching: \ and magic-characters in search strings
X   18         colon commands, exiting: {:} {ZZ}
X   19         screen positioning: {H} {M} {L}
X   20         character positioning: {w} {b} {0} {W} {B} {e} {E} {'} {`}
X   21         cursor positioning: {l} {k} {j} {h}
X   22         adding text: {i} {a} {I} {A} {o} {O} ^[ (escape key)
X   23         character manipulation: {f} {x} {X} {w} {l} {r} {R} {s} {S} {J}
X   24         undo: {u} {U}
X   25         review
X(The following sections are in this file.)
X   26         Index to the rest of the tutorial ******** YOU ARE HERE *******
X   27         discussion of repeat counts and the repeat command: {.}
X   28         more on low-level character motions: {t} {T} {|}
X   29         advanced correction operators: {d} {c}
X   30         updating the screen: {^R}
X   31         text buffers: {"}
X   32         rearranging and duplicating text: {p} {P} {y} {Y}
X   33         recovering lost lines
X   34         advanced file manipulation with vi
X   34.1          more than one file at a time: {:n}
X   34.2          reading files and command output: {:r}
X   34.3          invoking vi from within vi: {:e} {:vi}
X   34.4          escaping to a shell: {:sh} {:!}
X   34.5          writing parts of a file: {:w}
X   34.6          filtering portions of text: {!}
X   35         advanced searching: magic patterns 
X   36         advanced substitution: {:s} 
X   37         advanced line addressing: {:p} {:g} {:v}
X   38         higher level text objects and nroff: ( ) { } [[ ]]
X   39         more about inserting text
X   40         more on operators: {d} {c} {<} {>} {!} {=} {y}
X   41         abbreviations: {:ab}
X   42         vi's relationship with the ex editor: {:}
X   43         vi on hardcopy terminals and dumb terminals: open mode
X   44         options: {:set} {setenv EXINIT}
X   44.1          autoindent
X   44.2          autoprint
X   44.3          autowrite
X   44.4          beautify
X   44.5          directory
X   44.6          edcompatible
X   44.7          errorbells
X   44.8          hardtabs
X   44.9          ignorecase
X   44.10         lisp
X   44.11         list
X   44.12         magic
X   44.13         mesg                    
X   44.14         number
X   44.15         open
X   44.16         optimize
X   44.17         paragraphs
X   44.18         prompt
X   44.19         readonly
X   44.20         redraw
X   44.21         remap
X   44.22         report
X   44.23         scroll
X   44.24         sections
X   44.25         shell
X   44.26         shiftwidth
X   44.27         showmatch
X   44.28         slowopen
X   44.29         tabstop
X   44.30         tags
X   44.31         taglength
X   44.32         term
X   44.33         terse
X   44.34         timeout
X   44.35         ttytype
X   44.36         warn
X   44.37         window
X   44.38         wrapscan
X   44.39         wrapmargin
X   44.40         writeany
X   44.41         w300, w1200, w9600
X
XSection 27: repetition counts and the repeat command {.}
X
XMost vi commands will use a preceding count to affect their behavior in some
Xway.  We have already seen how {3x} deletes three characters, and {22G} moves
Xus to line 22 of the file.  For almost all of the commands, one can survive by
Xthinking of these leading numbers as a 'repeat count' specifying that the
Xcommand is to be repeated so many number of times.
X
XOther commands use the repeat count slightly differently, like the {G} command
Xwhich use it as a line number.
X
XFor example:
X
X{3^D} means scroll down in the file three lines.  Subsequent {^D} OR {^U} will
Xscroll only three lines in their respective directions!
X
X{3z^M} says put line three of the file at the top of the screen, while {3z.}
Xsays put line three as close to the middle of the screen as possible.
X
X{50|} moves the cursor to column fifty in the current line.
X
X{3^F} says move forward 3 screenfulls.  This is a repetition count.  The
Xdocuments advertise that {3^B} should move BACK three screenfulls, but I
Xcan't get it to work.
X
XPosition the cursor on some text and try {3r.}.  This replaces three characters
Xwith '...'.  However, {3s.....^[} is the same as {3xi.....^[}.
X
XTry {10a+----^[}.
X
XA very useful instance of a repetition count is one given to the '.' command,
Xwhich repeats the last 'change' command.  If you {dw} and then {3.}, you will
Xdelete first one and then three words.  You can then delete two more words with
X{2.}.  If you {3dw}, you will delete three words.  A subsequent {.} will delete
Xthree more words.  But a subsequent {2.} will delete only two words, not three
Xtimes two words.
X
XCaveat: The author has noticed that any repetition count with {^B} will NOT
Xwork: indeed, if you are at the end of your file and try {3^B} sufficiently
Xoften, the editor will hang you in an infinite loop.  Please don't try it:
Xtake my word for it.
X
XSection 28: {t} {T} {|}
X
XPosition the cursor on line 13 below:
X
XLine 13: Four score and seven years ago, our forefathers brought ...
X
XNote that {fv} moves the cursor on/over the 'v' in 'seven'.  Do a {0} to return
Xto the beginning of the line and try a {tv}.  The cursor is now on/over the
Xfirst 'e' in 'seven'.  The {f} command finds the next occurrence of the
Xspecified letter and moves the cursor to it.  The {t} command finds the
Xspecified letter and moves the cursor to the character immediately preceding
Xit.  {T} searches backwards, as does {F}.
X
XNow try {60|}: the cursor is now on the 'o' in 'brought', which is the
Xsixtieth character on the line.
X
XSection 29: {d} {c}
X
XDue to their complexity we have delayed discussion of two of the most powerful
Xoperators in vi until now.  Effective use of these operators requires more
Xexplanation than was deemed appropriate for the first half of the tutorial.
X
X{d} and {c} are called operators instead of commands because they consist of
Xthree parts: a count specification or a buffer specification (see section
X#BUFFERS), the {d} or {c}, and the object or range description.  We will not
Xdiscuss buffers at this stage, but will limit ourselves to count
Xspecifications.  Examples speak louder than words: position the cursor at the
Xbeginning of line 14:
X
XLine 14: Euclid alone has looked on beauty bear.
X
XObviously, there is something wrong with this quotation.  Type {2fb} to
Xposition the cursor on the 'b' of 'bear'.  Now, type {cwbare^[}
Xand observe the results.  The {cw} specifies that the change command {c} is to
Xoperate on a word object.  More accurately, it specifies that the range of the
Xchange command includes the next word.
X
XPosition the cursor on the period in Line 14. (one way is to use {f.})
XNow, type {cbbeast^[}.  This specifies the range of the change command to be the
Xprevious word (the 'b' reminiscent of the {b} command).  If we had wished to
Xdelete the word rather than change it, we would have used the {d} operator,
Xrather than the {c} operator.
X
XPosition the cursor at the beginning of the line with {0}.  Type
X{d/look/^M}.  The search string specified the range of the delete.
XEverything UP TO the word 'looking' was deleted from the line.
X
XIn general, almost any command that would move the cursor will specify a range
Xfor these commands.  The most confusing exception to this rule is when {dd} or
X{cc} is entered: they refer to the whole line.  Following is a summary of the
Xsuffixes (suffices? suffici?) and the ranges they specify:
X
X    suffix        will delete{d}/change{c}
X    ------        ------------------------
X      ^[            cancels the command
X      w             the word to the right of the cursor
X      W             ditto, but ignoring punctuation
X      b             the word to the left of the cursor
X      B             ditto, but ignoring punctuation
X      e             see below.
X      E               ditto
X      (space)       a character
X      $             to the end of the line
X      ^             to the beginning of the line
X      / .. /        up to, but not including, the string
X      ? .. ?        back to and including the string
X      fc            up to and including the occurrence of c 
X      Fc            back to and including the occurrence of c
X      tc            up to but not including the occurrence of c
X      Tc            back to but not including the occurrence of c
X      ^M            TWO lines (that's right: two)
X      (number)^M    that many lines plus one
X      (number)G     up to and including line (number)
X      (             the previous sentence if you are at the beginning of
X                    the current sentence, or the current sentence up to where 
X                    you are if you are not at the beginning of the current 
X                    sentence.  Here, 'sentence' refers to the intuitive
X                    notion of an English sentence, ending with '!', '?',
X                    or '.' and followed by an end of line or two spaces.
X      )             the rest of the current sentence
X      {             analogous to '(', but in reference to paragraphs:
X                    sections of text surrounded by blank lines
X      }             analogous to ')', but in reference to paragraphs
X      [[            analogous to '(', but in reference to sections
X      ]]            analogous to ')', but in reference to sections
X      H             the first line on the screen
X      M             the middle line on the screen
X      L             the last line on the screen
X      3L            through the third line from the bottom of the screen
X      ^F            forward a screenful
X      ^B            backward a screenful
X      :
X      :  etc. etc. etc.
X
XThis list is not exhaustive, but it should be sufficient to get the idea
Xacross: after the {c} or {d} operator, you can specify a range with another
Xmove-the-cursor command, and that is the region of text over which the command
Xwill be effective.
X
XSection 30: updating the screen {^R}
X
XVi tries to be very intelligent about the type of terminal you are working on
Xand tries to use the in-terminal computing power (if any) of your terminal.
XAlso if the terminal is running at a low baud rate (say 1200 or below), vi sets
Xvarious parameters to make things easier for you.  For example, if you were
Xrunning on a 300 baud terminal (that's 30 characters per second transmission
Xrate) not all 24 lines of the screen would be used by vi.  In addition, there
Xis a large portion of the editor keeping track of what your screen currently
Xlooks like, and what it would look like after a command has been executed.  Vi
Xthen compares the two, and updates only those portions of the screen that have
Xchanged.
X
XFurthermore, some of you may have noticed (it depends on your terminal) that 
Xdeleting lines or changing large portions of text may leave some lines on the 
Xscreen looking like: 
X@ 
Xmeaning that this line of the screen does not correspond to any line in your
Xfile. It would cost more to update the line than to leave it blank for the
Xmoment.  If you would like to see your screen fully up-to-date with the
Xcontents of your file, type {^R}.
X
XTo see it in action, delete several lines with {5dd}, type {^R}, and then type
X{u} to get the lines back.
X
XHere is as good a place as any to mention that if the editor is displaying the
Xend of your file, there may be lines on the screen that look like: 
X~ 
Xindicating that that screen line would not be affected by {^R}.  These lines
Xsimply indicate the end of the file.
X
XSection 31: text buffers {"}
X
XVi gives you the ability to store text away in "buffers".  This feature is very
Xconvenient for moving text around in your file.  There are a total of thirty-
Xfive buffers available in vi.  There is the "unnamed" buffer that is used by all
Xcommands that delete text, including the change operator {c}, the substitute
Xand replace commands {s} and {r}, as well as the delete operator {d} and delete
Xcommands {x} and {X}.  This buffer is filled each time any of these commands
Xare used. However, the undo command {u} has no effect on the unnamed buffer.
X
XThere are twenty-six buffers named 'a' through 'z' which are available for the
Xuser.  If the name of the buffer is capitalized, then the buffer is not
Xoverwritten but appended to.  For example, the command {"qdd} will delete one
Xline and store that line in the 'q' buffer, destroying the previous contents of
Xthe buffer.  However, {"Qdd} will delete one line of text and append that line
Xto the current contents of the 'q' buffer.
X
XFinally, there are nine buffers named '1' through '9' in which the last nine
Xdeletes are stored.  Buffer 1 is the default buffer for the modify commands and
Xis sometimes called the unnamed buffer.
X
XTo reference a specific buffer, use the double-quote command {"} followed by
Xthe name of the buffer.  The next two sections show how buffers can be used to
Xadvantage.
X
XSection 32: rearranging and duplicating text: {y} {Y} {p} {P}
X
XPosition yourself on line 15 below and {z^M}:
X
XLine 15: A tree as lovely as a poem ...
XLine 16: I think that I shall never see
X
XType {dd}.  Line 15 has disappeared and been replaced with the empty line (one
Xwith the single character @ on it) or (again depending on your terminal) Line
X16 has moved up and taken its place.  We could recover Line 15 with an undo
X{u} but that would simply return it to its original location.  Obviously, the
Xtwo lines are reversed, so we want to put line 15 AFTER line 16.  This is
Xsimply done with the put command {p}, which you should type now.  What has
Xhappened is that {dd} put Line 15 into the unnamed buffer, and the {p} command
Xretrieved the line from the unnamed buffer.
X
XNow type {u} and observe that Line 15 disappears again (the put was undone
Xwithout affecting the unnamed buffer).  Type {P} and see that the capital {P}
Xputs the line BEFORE the cursor.
X
XTo get Line 15 where it belongs again type {dd}{p}.
X
XAlso in Line 15 note that the words 'tree' and 'poem' are reversed.  Using the
Xunnamed buffer again: {ft}{dw}{ma}{fp}{P}{w}{dw}{`aP} will set things aright 
X(note the use of the reverse quote).
X
XThe put commands {p} and {P} do not affect the contents of the buffer.
XTherefore, multiple {p} or {P} will put multiple copies of the unnamed buffer
Xinto your file.
X
XExperiment with {d} and {p} on words, paragraphs, etc.  Whatever {d}
Xdeletes, {p} can put.
X
XPosition the cursor on Line 17 and {z^M}:
X
XLine 17: interest apple cat elephant boy dog girl hay farmer
X
XOur task is to alphabetize the words on line 17.  With the named buffers (and a
Xcontrived example) it is quite easy:
X
X{"idw}{"adw}{"cdw}{"edw}{"bdw}{"ddw}{"gdw}{"hdw}{"fdw}
X
Xstores each of the words in the named buffer corresponding to the first letter
Xof each of the words ('interest' goes in buffer "i, 'apple' goes in buffer "a,
Xetc.).  Now to put the words in order type:
X
X{"ap$}{"bp$}{"cp$}{"dp$}{"ep$}{"fp$}{"gp$}{"hp$}{"ip$}
X
XNotice that, because 'farmer' was at the end of the line, {dw} did not include
Xa space after it, and that, therefore, there is no space between 'farmer' and
X'girl'.  This is corrected with {Fg}{i ^[}.
X
XThis example could have been done just as easily with lines as with
Xwords.
X
XYou do not have to delete the text in order to put it into a buffer.  If all
Xyou wish to do is to copy the text somewhere else, don't use {d}, rather use
Xthe yank commands {y} or {Y}.  {y} is like {d} and {c} - an operator rather
Xthan a command.  It, too, takes a buffer specification and a range
Xspecification.  Therefore, instead of {dw}{P} to load the unnamed buffer with a
Xword without deleting the word, use {yw} (yank a word).
X
X{Y} is designed yank lines, and not arbitrary ranges.  That is, {Y} is
Xequivalent to {yy} (remember that operators doubled means the current line),
Xand {3Y} is equivalent to {3yy}.
X
XIf the text you yank or modify forms a part of a line, or is an object such as
Xa sentence which partially spans more than one line, then when you put the text
Xback, it will be placed after the cursor (or before if you use {P}).  If the
Xyanked text forms whole lines, they will be put back as whole lines, without
Xchanging the current line.  In this case, the put acts much like the {o} or {O}
Xcommand.
X
XThe named buffers "a through "z are not affected by changing edit files.
XHowever, the unnamed buffer is lost when you change files, so to move text from
Xone file to another you should use a named buffer.
X
XSection 33: recovering lost lines
X
XVi also keeps track of the last nine deletes, whether you ask for it or not.
XThis is very convenient if you would like to recover some text that was
Xaccidentally deleted or modified.  Position the cursor on line 18 following,
Xand {z^M}.
X
X
XLine 18: line 1
XLine 19: line 2
XLine 20: line 3
XLine 21: line 4
XLine 22: line 5
XLine 23: line 6
XLine 24: line 7
XLine 25: line 8
XLine 26: line 9
XType {dd} nine times: now don't cheat with {9dd}!  That is totally different.
X
XThe command {"1p} will retrieve the last delete.  Furthermore, when the
Xnumbered buffers are used, the repeat-command command {.} will increment the
Xbuffer numbers before executing, so that subsequent {.} will recover all nine
Xof the deleted lines, albeit in reverse order.  If you would like to review the
Xlast nine deletes without affecting the buffers or your file, do an undo {u}
Xafter each put {p} and {.}:
X
X{"1p}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}{u}{.}
X
Xwill show you all the buffers and leave them and your file intact.
X
XIf you had cheated above and deleted the nine lines with {9dd}, all nine lines
Xwould have been stored in both the unnamed buffer and in buffer number 1. 
X(Obviously, buffer number 1 IS the unnamed buffer and is just the default
Xbuffer for the modify commands.)
X
XSection 34: advanced file manipulation: {:r} {:e} {:n} {:w} {!} {:!}
X
XWe've already looked at writing out the file you are editing with the
X{:w} command.  Now let's look at some other vi commands to make editing
Xmore efficient.
X
XSection 34.1: more than one file at a time {:n} {:args}
X
XMany times you will want to edit more than one file in an editing session.
XInstead of entering vi and editing the first file, exiting, entering vi and
Xediting the second, etc., vi will allow you to specify ALL files that you wish
Xto edit on the invocation line.  Therefore, if you wanted to edit file1 and
Xfile2:
X
X% vi file1 file2
X
Xwill set up file1 for editing.  When you are done editing file one, write it
Xout {:w^M} and then type {:n^M} to get the next file on the list.  On large
Xprogramming projects with many source files, it is often convenient just to
Xspecify all source files with, say:
X
X% vi *.c
X
XIf {:n^M} brings in a file that does not need any editing, another {:n^M}
Xwill bring in the next file.
X
XIf you have made changes to the first file, but decide to discard these changes
Xand proceed to the next file, {:n!^M} forces the editor to discard the current
Xcontents of the editor.
X
XYou can specify a new list of files after {:n}; e.g., {:n f1 f2 f3^M}.  This
Xwill replace the current list of files (if any).
X
XYou can see the current list of files being edited with {:args^M}.
X
XSection 34.2: reading files and command output: {:r}
X
XTyping {:r fname^M} will read the contents of file fname into the editor and
Xput the contents AFTER the cursor line.
X
XTyping {:r !cmd^M} will read the output of the command cmd and place that
Xoutput after the cursor line.
X
XSection 34.3: invoking vi from within vi: {:e} {:vi}
X
XTo edit another file not mentioned on the invocation line, type {:e filename^M}
Xor {:vi filename^M}.  If you wish to discard the changes to the current file,
Xuse the exclamation point after the command, e.g. {:e! filename^M}.
X
XSection 34.4: escaping to a shell: {:sh} {:!} {^Z}
X
XOccasionally, it is useful to interrupt the current editing session to perform
Xa UNIX task.  However, there is no need to write the current file out, exit
Xthe editor, perform the task, and then reinvoke the editor on the same file.
XOne thing to do is to spin off another process.  If there are several UNIX
Xcommands you will need to execute, simply create another shell with {:sh^M}.
XAt this point, the editor is put to sleep and will be reawakened when you log
Xout of the shell.
X
XIf it is a single command that you want to execute, type {:!cmd^M}, where cmd
Xis the command that you wish to run.  The output of the command will come to
Xthe terminal as normal, and will not be made part of your file.  The message
X"[Hit return to continue]" will be displayed by vi after the command is
Xfinished.  Hitting return will then repaint the screen.  Typing another
X{:!cmd^M} at this point is also acceptable.
X
XHowever, there is a quicker, easier way: type {^Z}.  Now this is a little
Xtricky, but hang in there.  When you logged into UNIX, the first program you
Xbegan communicating with was a program that is called a "shell" (i.e. it 'lays
Xover' the operating system protecting you from it, sort of like a considerate
Xporcupine).  When you got your first prompt on the terminal (probably a '%'
Xcharacter) this was the shell telling you to type your first command.  When
Xyou typed {vi filename} for some file, the shell did not go away, it just went
Xto sleep.  The shell is now the parent of vi.  When you type {^Z} the editor
Xgoes to sleep, the shell wakes up and says "you rang?" in the form of another
Xprompt (probably '%').  At this point you are talking to the shell again and
Xyou can do anything that you could before including edit another file!  (The
Xonly thing you can't do is log out: you will get the message "There are
Xstopped jobs.")
X
XWhen your business with the shell is done, type {fg} for 'foreground' and the
Xlast process which you ^Z'd out of will be reawakened and the shell will go
Xback to sleep.  I will refer you to the documentation for the Berkeley shell
X'csh' for more information on this useful capability.
X
XSection 34.5: writing parts of a file: {:w}
X
XThe {:w} command will accept a range specifier that will then write only a
Xselected range of lines to a file.  To write this section to a file, position
Xthe cursor on the section line (e.g. {/^Section 34.5:/^M}) and {z^M}.  Now type
X{^G} to find out the line number (it will be something like "line 513").  Now
X{/^Section 34.6:/-1^M} to find the last line of this section, and {^G} to find
Xits line number (it will be something like 542).  To write out this section of
Xtext by itself to a separate file which we will call "sepfile", type
X{:510,542w sepfile^M}.  If sepfile already exists, you will have to use the
Xexclamation point: {:1147,1168w! sepfile^M} or write to a different, non-
Xexistent file.
X
X{:!cat sepfile^M} will display the file just written, and it should be the
Xcontents of this section.
X
XThere is an alternate method of determining the line numbers for the write.
X{:set number^M} will repaint the screen with each line numbered.  When the file
Xis written and the numbers no longer needed, {:set nonumber^M} will remove the
Xnumbers, and {^R} will adjust the screen.
X
XOr, if you remember your earlier lessons about marking lines of text,
Xmark the beginning and ending lines.  Suppose we had used {ma} to mark the
Xfirst line of the section and {mb} to mark the last.  Then the command
X{:'a,'bw sepfile^M} will write the section into "sepfile".  In general,
Xyou can replace a line number with the 'name' of a marked line (a single-quote
Xfollowed by the letter used to mark the line)
X
X
XSection 34.6: filtering portions of text: {!}
X
X{!} is an operator like {c} and {d}.  That is, it consists of a repetition
Xcount, {!}, and a range specifier.  Once the {!} operator is entered in its
Xentirety, a prompt will be given at the bottom of the screen for a UNIX
Xcommand.  The text specified by the {!} operator is then deleted and
Xpassed/filtered/piped to the UNIX command you type.  The output of the UNIX
Xcommand is then placed in your file.  For example, place the cursor at the
Xbeginning of the following line and {z^M}:
X
Xls -l vi.tutorial
X********* marks the bottom of the output from the ls command **********
X
XNow type {!!csh^M}.  The line will be replaced with the output from the ls
Xcommand.  The {u} command works on {!}, also.
X
XHere is an extended exercise to display some of these capabilities.  When this
Xtutorial was prepared, certain auxiliary programs were created to aid in its
Xdevelopment.  Of major concern was the formatting of sections of the tutorial
Xto fit on a single screen, particularly the first few sections.  What was
Xneeded was a vi command that would 'format' a paragraph; that is, fill out
Xlines with as many words as would fit in eighty columns.  There is no such vi
Xcommand.  Therefore, another method had to be found.
X
XOf course, nroff was designed to do text formatting.  However, it produces a
X'page'; meaning that there may be many blank lines at the end of a formatted
Xparagraph from nroff.  The awk program was used to strip these blank lines from
Xthe output from nroff.  Below are the two files used for this purpose: I refer
Xyou to documentation on nroff and awk for a full explanation of their function.
XPosition the cursor on the next line and {z^M}.
X
X******** contents of file f **********
X#
Xnroff -i form.mac | awk "length != 0 { print }"
X***** contents of file form.mac ******
X.na
X.nh
X.ll 79
X.ec 
X.c2 
X.cc 
X**************************************
X
XDetermine the line numbers of the two lines of file f.  They should be
Xsomething like 574 and 575, although you better double check: this file is
Xunder constant revision and the line numbers may change inadvertently.  Then
X{:574,575w f^M}.  Do the same for the lines of file form.mac.  They will be
Xapproximately 577 and 582.  Then {:577,582w form.mac^M}.  File f must have
Xexecute privileges as a shell file: {:!chmod 744 f^M}.
X
XObserve that this paragraph is
Xrather ratty in appearance.  With our newly created files we can
Xclean it up dramatically.  Position the cursor at the beginning
Xof this paragraph and type the following sequence of
Xcharacters 
X(note that we must abandon temporarily our convention
Xof curly braces since the command itself contains a curly brace - we 
Xwill use square brackets for the nonce): [!}f^M].
X
XHere is a brief explanation of what has happened.  By typing [!}f^M] we
Xspecified that the paragraph (all text between the cursor and the first blank
Xline) will be removed from the edit file and piped to a UNIX program called
X"f".  This is a shell command file that we have created.  This shell file runs
Xnroff, pipes its output to awk to remove blank lines, and the output from awk
Xis then read back into our file in the place of the old, ratty paragraph.  The
Xfile form.mac is a list of commands to nroff to get it to produce paragraphs
Xto our taste (the right margin is not justified, the line is 79 characters
Xlong, words are not hyphenated, and three nroff characters are renamed to
Xavoid conflict: note that in this file, the {^G} you see there is vi's display
Xof the control-G character, and not the two separate characters ^ up-arrow and
XG upper-case g).
X
XThis example was created before the existence of the fmt program.  I now type
X[!}fmt^M] to get the same effect much faster.  Actually, I don't type those
Xsix keys each time: I have an abbreviation (which see).
X
XSection 35: searching with magic patterns
X
XThe documentation available for "magic patterns" (i.e. regular expressions) is
Xvery scanty.  The following should explain this possibly very confusing feature
Xof the editor.  This section assumes that the magic option is on.  To make
Xsure, you might want to type {:set magic^M}.
X
XBy "magic pattern" we mean a general description of a piece of text that the
Xeditor attempts to find during a search.  Most search patterns consist of
Xstrings of characters that must be matched exactly, e.g.  {/card/^M} searches
Xfor a specific string of four characters.  Let us suppose that you have
Xdiscovered that you consistently have mistyped this simple word as either ccrd
Xor czrd (this is not so far-fetched for touch typists).  You could {/ccrd/^M}
Xand {n} until there are no more of this spelling, followed by {/czrd/^M} and
X{n} until there are no more of these.  Or you could {/c.rd/^M} and catch all of
Xthem on the first pass.  Try typing {/c.rd/^M} followed by several {n} and
Xobserve the effect.
X
XLine 27: card cord curd ceard
X
XWhen '.' is used in a search string, it has the effect of matching any single
Xcharacter.
X
XThe character '^' (up-arrow) used at the beginning of a search string means
Xthe beginning of the line.  {/^Line 27/^M} will find the example line above,
Xwhile {/Line 27/^M} will find an occurrence of this string anywhere in the
Xline.
X
XSimilarly, {/ the$/^M} will find all occurrences of the word 'the' occurring
Xat the end of a line.  There are several of them in this file.
X
XNote that {:set nomagic^M} will turn off the special meaning of these magic
Xcharacters EXCEPT for '^' and '$' which retain their special meanings at the
Xbeginning and end of a search string.  Within the search string they hold no
Xspecial meaning.  Try {/\/ the$\//^M} and note that the dollar-sign is not the
Xlast character in the search string.  Let the dollar-sign be the last
Xcharacter in the search string, as in {/\/ the$/^M} and observe the result.
X
XObserve the result of {/back.*file/^M}.  This command, followed by sufficient
X{n}, will show you all lines in the file that contain both the words 'back'
Xand 'file' on the same line.  The '*' magic character specifies that the
Xprevious regular expression (the '.' in our example) is to be repeatedly
Xmatched zero or more times.  In our example we specified that the words 'back'
Xand 'file' must appear on the same line (they may be parts of words such as
X'backwards' or 'workfile') separated by any number (including zero) of
Xcharacters.
X
XWe could have specified that 'back' and 'file' are to be words by themselves by
Xusing the magic sequences '\<' or '\>'.  E.g.  {/\<back\>.*\<file\>/^M}.  The
Xsequence '\<' specifies that this point of the search string must match the
Xbeginning of a word, while '\>' specifies a match at the end of a word.  By
Xsurrounding a string with these characters we have specified that they must be
Xwords.
X
XTo find all words that begin with an 'l' or a 'w', followed by an 'a' or an
X'e', and ending in 'ing', try {/\<[lw][ea][a-z]*ing\>/^M}.  This will match
Xwords like 'learning', 'warning', and 'leading'.  The '[..]' notation matches
Xexactly ONE character.  The character matched will be one of the characters
Xenclosed in the square brackets.  The characters may be specified individually
Xas in [abcd] or a '-' may be used to specify a range of characters as in [a-d].
XThat is, [az] will match the letter 'a' OR the letter 'z', while [a-z] will
Xmatch any of the lower case letters from 'a' through 'z'.  If you would like to
Xmatch either an 'a', a '-', or a 'z', then the '-' must be escaped: [a\-z] will
Xmatch ONE of the three characters 'a', '-', or 'z'.
X
XIf you wish to find all Capitalized words, try {/\<[A-Z][a-z]*\>/^M}.  The
Xfollowing will find all character sequences that do NOT begin with an
Xuncapitalized letter by applying a special meaning to the '^' character in
Xsquare brackets: {/\<[^a-z][a-z]*\>/^M}.  When '^' is the first character of a
Xsquare-bracket expression, it specifies "all but these characters".  (No
Xone claimed vi was consistent.)
X
XTo find all variable names (the first character is alphabetic, the remaining
Xcharacters are alphanumeric):  try {/\<[A-Za-z][A-Za-z0-9]*\>/^M}.
X
XIn summary, here are the primitives for building regular expressions:
X
X     ^      at beginning of pattern, matches beginning of line
X     $      at end of pattern, matches end of line
X     .      matches any single character
X     \<     matches the beginning of a word
X     \>     matches the end of a word
X     [str]  matches any single character in str
X     [^str] matches any single character NOT in str
X     [x-y]  matches any character in the ASCII range between x and y
X     *      matches any number (including zero) of the preceding pattern
X
XSection 36: advanced substitution: {:s} 
X
XThe straightforward colon-substitute command looks like the substitute
Xcommand of most line-oriented editors.  Indeed, vi is nothing more than a
Xsuperstructure on the line-oriented editor ex and the colon commands are
Xsimply a way of accessing commands within ex (see section #EX).  This gives us
Xa lot of global file processing not usually found in visual oriented editors.
X
XThe colon-substitute command looks like: {:s/ .. / .. /^M} and will find the
Xpattern specified after the first slash (this is called the search pattern),
Xand replace it with the pattern specified after the second slash (called,
Xobviously enough, the replacement pattern).  E.g. position the cursor on line
X28 below and {:s/esample/example/^M}:
X
XLine 28: This is an esample.
X
XThe {u} and {U} commands work for {:s}.  The first pattern (the search pattern)
Xmay be a regular expression just as for the search command (after all, it IS a
Xsearch, albeit limited to the current line).  Do an {u} on the above line, and
Xtry the following substitute, which will do almost the same thing: 
X{:s/s[^ ]/x/^M}.  
XBetter undo it with {u}.  The first pattern {s[^ ]} matches an 's'
XNOT followed by a blank: the search therefore ignores the 's'es in 'This' and
X'is'.  However, the character matched by {[^ ]} must appear in the replacement
Xpattern.  But, in general, we do not know what that character is!  (In this
Xparticular example we obviously do, but more complicated examples will follow.)
XTherefore, vi (really ex) has a duplication mechanism to copy patterns matched
Xin the search string into the replacement string.  Line 29 below is a copy of
Xline 28 above so you can adjust your screen.
X
XLine 29: This is an esample.
X
XIn general, you can nest parts of the search pattern in \( .. \) and refer to
Xit in the replacement pattern as \n, where n is a digit.  The problem outlined
Xin the previous paragraph is solved with {:s/s\([^ ]\)/x\1/^M}: try it.  Here
X\1 refers to the first pattern grouping \( .. \) in the search string.
X
XObviously, for a single line, this is rather tedious.  Where it becomes
Xpowerful, if not necessary, is in colon-substitutes that cover a range of
Xlines.  (See the next section for a particularly comprehensive example.)
X
XIf the entire character sequence matched by the search pattern is needed in
Xthe replacement pattern, then the unescaped character '&' can be used.  On
XLine 29 above, try {:s/an e.ample/not &/^M}.  If another line is to have the
Xword 'not' prepended to a pattern, then '~' can save you from re-typing the
Xreplacement pattern.  E.g. {:s/some pattern/~/^M} after the previous example
Xwould be equivalent to {:s/some pattern/not &/^M}.
X
XOne other useful replacement pattern allows you to change the case of
Xindividual letters.  The sequences {\u} and {\l} cause the immediately
Xfollowing character in the replacement to be converted to upper- or lower-case,
Xrespectively, if this character is a letter.  The sequences {\U} and {\L} turn
Xsuch conversion on, either until {\E} or {\e} is encountered, or until the end
Xof the replacement pattern.
X
XFor example, position the cursor on a line: pick a line, any line.  Type
X{:s/.*/\U&/^M} and observe the result.  You can undo it with {u}.
X
XThe search pattern may actually match more than once on a single line.
XHowever, only the first pattern is substituted.  If you would like ALL
Xpatterns matched on the line to be substituted, append a 'g' after the
Xreplacement pattern: {:s/123/456/g^M} will substitute EVERY occurrence
Xon the line of 123 with 456.
X
XSection 37: advanced line addressing: {:p} {:g} {:v}
X
XEx (available through the colon command in vi) offers several methods for
Xspecifying the lines on which a set of commands will act.  For example, if you
Xwould like to see lines 50 through 100 of your file: {:50,100p^M} will display
Xthem, wait for you to [Hit return to continue], and leave you on line 100.
XObviously, it would be easier just to do {100G} from within vi.  But
Xwhat if you would like to make changes to just those lines?  Then the
Xaddressing is important and powerful.
X
XLine 30: This is a text.
XLine 31: Here is another text.
XLine 32: One more text line.
X
XThe lines above contain a typing error that the author of this tutorial tends
Xto make every time he attempts to type the word 'test'.  To change all of these
X'text's into 'test's, try the following:
X{:/^Line 30/,/^Line 32/s/text/test/^M}.  This finds the beginning and end of
Xthe portion of text to be changed, and limits the substitution to each of the
Xlines in that range.  The {u} command applies to ALL of the substitutions as 
Xa group.
X
XThis provides a mechanism for powerful text manipulations.
XAnd very complicated examples.
X
XLine 33: This test is a.
XLine 34: Here test is another.
XLine 35: One line more test.
X
XThe above three lines have the second word out of order.  The following command
Xstring will put things right.  Be very careful when typing this: it is very
Xlong, full of special characters, and easy to mess up.  You may want to
Xconsider reading the following section to understand it before trying the
Xexperiment.  Don't worry about messing up the rest of the file, though: the
Xaddress range is specified.
X
X{:/^Line 33/,/^Line 35/s/\([^:]*\): \([^ ]*\) \([^ ]*\) \([^.]*\)/\1: \2 \4 \3/^M}
X
XThere are several things to note about this command string.  First of all, the
Xrange of the substitute was limited by the address specification {/^Line
X33/,/^Line 35/^M}.  It might have been simpler to do {:set number^M} to see the
Xline numbers directly, and then, in place of the two searches, typed
Xthe line numbers, e.g. {1396,1398}.  Or to mark the lines with {ma} and {mb}
Xand use {'a,'b}.
X
XThen follows the substitute pattern itself.  To make it easier to understand
Xwhat the substitute is doing, the command is duplicated below with the various
Xpatterns named for easier reference:
X
X     s/\([^:]*\): \([^ ]*\) \([^ ]*\) \([^.]*\)/\1: \2 \4 \3/
X       |--\1---|  |--\2---| |--\3---| |--\4---|
X      |--------search pattern------------------|-replacement|
X                                               |--pattern---|
X
XIn overview, the substitute looks for a particular pattern made up of 
Xsub-patterns, which are named \1, \2, \3, and \4.  These patterns are specified
Xby stating what they are NOT.  Pattern \1 is the sequence of characters that
Xare NOT colons: in the search string, {[^:]} will match exactly one character
Xthat is not a colon, while appending the asterisk {[^:]*} specifies that the
X'not a colon' pattern is to be repeated until no longer satisfied, and
X{\([^:]*\)} then gives the pattern its name, in this case \1.  Outside of the
Xspecification of \1 comes {: }, specifying that the next two characters must be
Xa colon followed by a blank.
X
XPatterns \2 and \3 are similar, specifying character sequences that are
Xnot blanks.  Pattern \4 matches up to the period at the end of the line.
X
XThe replacement pattern then consists of specifying the new order of the
Xpatterns.
X
XThis is a particularly complicated example, perhaps the most complicated
Xin this tutorial/reference.  For our small examples, it is obviously
Xtedious and error prone.  For large files, however, it may be the most
Xefficient way to make the desired modifications.
X
X(The reader is advised to look at the documentation for awk.  This tool is very
Xpowerful and slightly simpler to use than vi for this kind of file
Xmanipulation.  But, it is another command language to learn.)
X
XMany times, you will not want to operate on every line in a certain
Xrange.  Rather you will want to make changes on lines that satisfy
Xcertain patterns; e.g. for every line that has the string 'NPS' on it,
Xchange 'NPS' to 'Naval Postgraduate School'.  The {:g} addressing
Xcommand was designed for this purpose.  The example of this paragraph
Xcould be typed as {:g/NPS/s//Naval Postgraduate School/^M}.
X
XThe general format of the command is {:g/(pattern)/cmds^M} and it
Xworks in the following way: all lines that match the pattern
Xfollowing the {:g} are 'tagged' in a special way.  Then each of these
Xlines have the commands following the pattern executed over them.
X
XLine 36: ABC rhino george farmer Dick jester lest
XLine 37: george farmer rhino lest jester ABC
XLine 38: rhino lest george Dick farmer ABC jester 
X
XType:
X
X{:g/^Line.*ABC/s/Dick/Harry Binswanger/|s/george farmer/gentleman george/p^M}
X
XThere are several things of note here.  First, lines 36, 37, and 38 above are
Xtagged by the {:g}.  Type {:g/^Line.*ABC/p^M} to verify this.  Second, there
Xare two substitutes on the same line separated by '|'.  In general, any colon
Xcommands can be strung together with '|'.  Third, both substitutes operate on
Xall three lines, even though the first stubstitute works on only two of the
Xlines (36 and 38).  Fourth, the second substitute works on only two lines (36
Xand 37) and those are the two lines printed by the trailing 'p'.
X
XThe {:v} command works similarly to the {:g} command, except that the sense of
Xthe test for 'tagging' the lines is reversed: all lines NOT matching the search
Xpattern are tagged and operated on by the commands.
X
XUsing {^V} to quote carriage return (see section 39) can be used in global
Xsubstitutions to split two lines.  For example, the command 
X{:g/\.  /s//.^V^M/g^M} will change your file so that each sentence is on a 
Xseparate line.  (Note that we have to 'escape' the '.', because '.' by itself
Xmatches any character.  Our command says to find any line which contains a 
Xperiod followed by 2 spaces, and inserts a carriage return after the period.)
X
XCaveat:  In some of the documentation for ex and vi you may find the
Xcomment to the effect that {\^M} can be used between commands following
X{:g}.  The author of this tutorial has never gotten this to work and has
Xcrashed the editor trying.
X
XSection 38: higher level text objects and nroff: {(} {)} [{] [}] {[[} {]]}
X
X(Note: this section may be a little confusing because of our command
Xnotation.  Using curly braces to surround command strings works fine as
Xlong as the command string does not contain any curly braces itself.
XHowever, the curly braces are legitimate commands in vi.  Therefore, for
Xany command sequence that contains curly braces, we will surround that
Xsequence with SQUARE braces, as on the previous Section line.)
X
XIn working with a document, particularly if using the text formatting
Xprograms nroff or troff, it is often advantageous to work in terms of
Xsentences, paragraphs, and sections.  The operations {(} and {)} move to
Xthe beginning of the previous and next sentences, respectively.  Thus
Xthe command {d)} will delete the rest of the current sentence; likewise
X{d(} will delete the previous sentence if you are at the beginning of
Xthe current sentence, or, if you are not at the beginning of a sentence,
Xit will delete the current sentence from the beginning 
Xup to where you are.
X
XA sentence is defined to end at a '.', '!', or '?' which is followed
Xby either the end of a line, or by two spaces.  Any number of closing
X')', ']', '"', and ''' characters may appear after the '.', '!', or '?'
Xbefore the spaces or end of line.  Therefore, the {(} and {)} commands
Xwould recognize only one sentence in the following line, but two
Xsentences on the second following line.
X
XLine 39: This is one sentence. Even though it looks like two.
XLine 40: This is two sentences.  Because it has two spaces after the '.'.
X
XThe operations [{] and [}] move over paragraphs and the operations {[[}
Xand {]]} move over sections.
X
XA paragraph begins after each empty line, and also at each of a set of nroff
Xparagraph macros.  A section begins after each line with a form-feed ^L in the
Xfirst column, and at each of a set of nroff section macros.  When preparing a
Xtext file as input to nroff, you will probably be using a set of nroff macros
Xto make the formatting specifications easier, or more to your taste.  These
Xmacros are invoked by beginning a line with a period followed by the one or two
Xletter macro name. Vi has been programmed to recognize these nroff macros, and
Xif it doesn't recognize your particular macro you can use the {:set paragraphs}
Xor {:set sections} commands so that it will.
X
XSection 39: more about inserting text
X
XThere are a number of characters which you can use to make correnctions
Xduring input mode.  These are summarized in the following table.
X
X    ^H      deletes the last input character
X    ^W      deletes the last input word
X    (erase) same as ^H; each terminal can define its own erase character; 
X            for some it is ^H, for others it is the DELETE key, and for
X            others it is '@'.
X    (kill)  deletes the input on this line; each terminal can define its
X            own line-kill character; for some it is ^U, for others it is
X            '@'; you will need to experiment on your terminal to find
X            out what your line-kill and erase characters are.
X    \       escapes a following ^H, (kill), and (erase) characters: i.e.
X            this is how to put these characters in your file.
X    ^[      escape key; ends insertion mode
X    ^?      the delete key; interrupts an insertion, terminating it
X            abnormally.
X    ^M      the return key; starts a new line.
X    ^D      backtabs over the indentation set by the autoindent option
X    0^D     backtabs over all indentation back to the beginning of the line
X    ^^D     (up-arrow followed by control-d)same as 0^D, except the indentation 
X	    will be restored at the beginning of the next line.
X    ^V      quotes the next non-printing character into the file
X
XIf you wish to type in your erase or kill character (say # or @ or ^U) then you
Xmust precede it with a \, just as you would do at the normal system command
Xlevel.  A more general way of typing non-printing characters into the file is
Xto precede them with a ^V.  The ^V echoes as a ^ character on which the cursor
Xrests.  This indicates that the editor expects you to type a control character
Xand it will be inserted into the file at that point.  There are a few
Xexceptions to note.  The implementation of the editor does not allow the null
Xcharacter ^@ to appear in files.  Also the linefeed character ^J is used by the
Xeditor to separate lines in the file, so it cannot appear in the middle of a
Xline.  (Trying to insert a ^M into a file, or putting it in the replacement 
Xpart of a substitution string will result in the matched line being split in 
Xtwo.  This, in effect, is how to split lines by using a substitution.)  You can 
Xinsert any other character, however, if you wait for the editor to echo the ^ 
Xbefore you type the character.  In fact, the editor will treat a following 
Xletter as a request for the corresponding control character.  This is the only 
Xway to type ^S or ^Q, since the system normally uses them to suspend and resume 
Xoutput and never gives them to the editor to process.
X
XIf you are using the autoindent option you can backtab over the indent which it
Xsupplies by typing a ^D.  This backs up to the boundary specified by the
Xshiftwidth option.  This only works immediately after the supplied autoindent.
X
XWhen you are using the autoindent option you may wish to place a label at the
Xleft margin of a line.  The way to do this easily is to type ^ (up-arrow) and
Xthen ^D.  The editor will move the cursor to the left margin for one line, and
Xrestore the previous indent on the next.  You can also type a 0 followed
Ximmediately by a ^D if you wish to kill all indentation and not have it resume
Xon the next line.
X
XSection 40: more on operators: {d} {c} {<} {>} {!} {=} {y}
X
XBelow is a non-exhaustive list of commands that can follow the operators
Xto affect the range over which the operators will work.  However, note
Xthat the operators {<}, {>}, {!}, and {=} do not operate on any object
Xless than a line.  Try {!w} and you will get a beep.  To get the
Xoperator to work on just the current line, double it.  E.g. {<<}.
X
X    suffix        will operate on
X    ------        ------------------------
X      ^[            cancels the command
X      w             the word to the right of the cursor
X      W             ditto, but ignoring punctuation
X      b             the word to the left of the cursor
X      B             ditto, but ignoring punctuation
X      e             see below.
X      E               ditto
X      (space)       a character
X      $             to the end of the line
X      ^             to the beginning of the line
X      / .. /        up to, but not including, the string
X      ? .. ?        back to and including the string
X      fc            up to and including the occurrence of c 
X      Fc            back to and including the occurrence of c
X      tc            up to but not including the occurrence of c
X      Tc            back to but not including the occurrence of c
X      ^M            TWO lines (that's right: two)
X      (number)^M    that many lines plus one
X      (number)G     up to and including line (number)
X      (             the previous sentence if you are at the beginning of
X                    the current sentence, or the current sentence up to where 
X                    you are if you are not at the beginning of the current 
X                    sentence.  Here, 'sentence' refers to the intuitive
X                    notion of an English sentence, ending with '!', '?',
X                    or '.' and followed by an end of line or two spaces.
X      )             the rest of the current sentence
X      {             analogous to '(', but in reference to paragraphs:
X                    sections of text surrounded by blank lines
X      }             analogous to ')', but in reference to paragraphs
X      [[            analogous to '(', but in reference to sections
X      ]]            analogous to ')', but in reference to sections
X      H             the first line on the screen
X      M             the middle line on the screen
X      L             the last line on the screen
X      3L            through the third line from the bottom of the screen
X      ^F            forward a screenful
X      ^B            backward a screenful
X      :
X      :  etc. etc. etc.
X
XThis list is not exhaustive, but it should be sufficient to get the idea
Xacross: after the operator, you can specify a range with a move-the-cursor
Xcommand, and that is the region of text over which the operator will be
Xeffective.
X
XSection 41: abbreviations: {:ab}
X
XWhen typing large documents you may find yourself typing a large phrase
Xover and over.  Vi gives you the ability to specify an abbreviation for
Xa long string such that typing the abbreviation will automatically
Xexpand into the longer phrase.
X
XType {:ab nps Naval Postgraduate School^M}.  Now type:
X
X{iThis is to show off the nps's UNIX editor.^M^[}
X
XSection 42: vi's relationship with the ex editor: {:}
X
XVi is actually one mode of editing within the editor ex.  When you are
Xrunning vi you can escape to the line oriented editor of ex by giving
Xthe command {Q}.  All of the colon-commands which were introduced above
Xare available in ex.  Likewise, most ex commands can be invoked from vi
Xusing {:}.   
X
XIn rare instances, an internal error may occur in vi.  In this case you
Xwill get a diagnostic and will be left in the command mode of ex.  You can
Xthen save your work and quit if you wish by giving the command {x} after
Xthe colon prompt of ex.  Or you can reenter vi (if you are brave) by
Xgiving ex the command {vi}.
X
XSection 43: vi on hardcopy terminals and dumb terminals: open mode
X
X(The author has not checked the following documentation for accuracy.  It is
Xabstracted from the Introduction to Vi Editing document.)
X
XIf you are on a hardcopy terminal or a terminal which does not have a cursor
Xwhich can move off the bottom line, you can still use the command set of vi,
Xbut in a different mode.  When you give the vi command to UNIX, the editor will
Xtell you that it is using open mode.  This name comes from the open command in
Xex, which is used to get into the same mode.
X
XThe only difference between visual mode (normal vi) and open mode is the way in
Xwhich the text is displayed.
X
XIn open mode the editor uses a single line window into the file, and moving
Xbackward and forward in the file causes new lines to be displayed, always below
Xthe current line.  Two commands of vi work differently in open: {z} and {^R}.
XThe {z} command does not take parameters, but rather draws a window of context
Xaround the current line and then returns you to the current line.
X
XIf you are on a hardcopy terminal, the {^R} command will retype the current
Xline.  On such terminals, the editor normally uses two lines to represent the
Xcurrent line.  The first line is a copy of the line as you started to edit it,
Xand you work on the line below this line.  When you delete characters, the
Xeditor types a number of \'s to show you the characters which are deleted.  The
Xeditor also reprints the current line soon after such changes so that you can
Xsee what the line looks like again.
X
XIt is sometimes useful to use this mode on very slow terminals which can
Xsupport vi in the full screen mode.  You can do this by entering ex and using
Xan {open} command.
X
X*********************************************************************
XSection 44: options: {:set} {setenv EXINIT}
X
XYou will discover options as you need them.  Do not worry about them very much
Xon the first pass through this document.  My advice is to glance through them,
Xnoting the ones that look interesting, ignoring the ones you don't understand,
Xand try re-scanning them in a couple of weeks.
X
XIf you decide that you have a favorite set of options and would like to change
Xthe default values for the editor, place a {setenv EXINIT} command in your
X.login file.  When you are given an account under UNIX your directory has
Xplaced in it a file that is executed each time you log in.  If one of the
Xcommands in this file sets the environment variable EXINIT to a string of vi
Xcommands, you can have many things done for you each time you invoke vi.  For
Xexample, if you decide that you don't like tabstops placed every eight columns
Xbut prefer every four columns, and that you wish the editor to insert linefeeds
Xfor you when your typing gets you close to column 72, and you want
Xautoindentation, then include the following line in your .login file:
X
Xsetenv EXINIT='set tabstop=4 wrapmargin=8 autoindent'
X
Xor equivalently
X
Xsetenv EXINIT='se ts=4 wm=8 ai'
X
XEach time you bring up vi, this command will be executed and the options set.
X
XThere are forty options in the vi/ex editor that the user can set for his/her
Xown convenience.  They are described in more detail in individual sections
Xbelow.  The section line will show the full spelling of the option name, the
Xabbreviation, and the default value of the option.  The text itself
Xcomes from the ex reference manual and is not the epitome of clarity.
X
XSection 44.1: {autoindent}, {ai} default: noai
X
XCan be used to ease the preparation of structured program text.  At the
Xbeginning of each append, change or insert command or when a new line is opened
Xor created by an append, change, insert, or substitute operation within open or
Xvisual mode, ex looks at the line being appended after, the first line changed
Xor the line inserted before and calculates the amount of white space at the
Xstart of the line.  It then aligns the cursor at the level of indentation so
Xdetermined.
X
XIf the user then types lines of text in, they will continue to be justified at
Xthe displayed indenting level.  If more white space is typed at the beginning
Xof a line, the following line will start aligned with the first non-white
Xcharacter of the previous line.  To back the cursor up to the preceding tab
Xstop one can hit {^D}.  The tab stops going backwards are defined at multiples
Xof the shiftwidth option.  You cannot backspace over the indent, except by
Xsending an end-of-file with a {^D}.  A line with no characters added to it
Xturns into a completely blank line (the white space provided for the autoindent
Xis discarded). Also specially processed in this mode are lines beginning with
Xan up-arrow `^' and immediately followed by a {^D}.  This causes the input to
Xbe repositioned at the beginning of the line, but retaining the previous indent
Xfor the next line.  Similarly, a `0' followed by a {^D} repositions at the
Xbeginning but without retaining the previous indent.  Autoindent doesn't happen
Xin global commands or when the input is not a terminal.
X
XSection 44.2: {autoprint}, {ap} default: ap
X
XCauses the current line to be printed after each delete, copy, join, move,
Xsubstitute, t, undo or shift command.  This has the same effect as supplying a
Xtrailing `p' to each such command.  Autoprint is suppressed in globals, and
Xonly applies to the last of many commands on a line.
X
XSection 44.3: {autowrite}, {aw} default: noaw
X
XCauses the contents of the buffer to be written to the current file if you have
Xmodified it and give a next, rewind, stop, tag, or {!} command, or a control-
Xup-arrow {^^} (switch files) or {^]} (tag goto) command in visual.  Note, that
Xthe edit and ex commands do not autowrite.  In each case, there is an
Xequivalent way of switching when autowrite is set to avoid the autowrite
X({edit} for next, rewind!  for rewind, stop!  for stop, tag!  for tag, shell
Xfor {!}, and {:e #} and a {:ta!} command from within visual).
X
XSection 44.4: {beautify}, {bf} default: nobeautify
X
XCauses all control characters except tab ^I, newline ^M and form-feed ^L to be
Xdiscarded from the input.  A complaint is registered the first time a backspace
Xcharacter is discarded.  Beautify does not apply to command input.
X
XSection 44.5: {directory}, {dir} default: dir=/tmp 
X
XSpecifies the directory in which ex places its buffer file.  If this directory
Xin not writable, then the editor will exit abruptly when it fails to be able to
Xcreate its buffer there.
X
XSection 44.6: {edcompatible} default: noedcompatible
X
XCauses the presence or absence of g and c suffixes on substitute commands to be
Xremembered, and to be toggled by repeating the suffices.  The suffix r makes
Xthe substitution be as in the {~} command, instead of like {&}.
X
X[Author's note: this should not concern users of vi.]
X
XSection 44.7: {errorbells}, {eb} default: noeb
X
XError messages are preceded by a bell.  However, bell ringing in open and
Xvisual modes on errors is not suppressed by setting noeb.  If possible the
Xeditor always places the error message in a standout mode of the terminal (such
Xas inverse video) instead of ringing the bell.
X
XSection 44.8: {hardtabs}, {ht} default: ht=8
X
XGives the boundaries on which terminal hardware tabs are set (or on which the
Xsystem expands tabs).
X
XSection 44.9: {ignorecase}, {ic} default: noic
X
XAll upper case characters in the text are mapped to lower case in regular
Xexpression matching.  In addition, all upper case characters in regular
Xexpressions are mapped to lower case except in character class specifications
X(that is, character in square brackets).
X
XSection 44.10: {lisp} default: nolisp
X
XAutoindent indents appropriately for lisp code, and the {(}, {)}, [{], [}],
X{[[}, and {]]} commands in open and visual modes are modified in a
Xstriaghtforward, intuitive fashion to have meaning for lisp.
X
X[Author's note: but don't ask me to define them precisely.]
X
XSection 44.11: {list} default: nolist
X
XAll printed lines will be displayed (more) unambiguously, showing tabs as ^I
Xand end-of-lines with `$'.  This is the same as in the ex command {list}.
X
XSection 44.12: {magic} default: magic for {ex} and {vi}, nomagic for edit.
X
XIf nomagic is set, the number of regular expression metacharacters is greatly
Xreduced, with only up-arrow `^' and `$' having special effects.  In addition
Xthe metacharacters `~' and `&' of the replacement pattern are treated as normal
Xcharacters.  All the normal metacharacters may be made magic when nomagic is
Xset by preceding them with a `\'.
X
X[Author's note: In other words, if magic is set a back-slant turns the magic
Xoff for the following character, and if nomagic is set a back-slant turns the
Xmagic ON for the following character.  And, no, we are not playing Dungeons and
XDragons, although I think the writers of these option notes must have played it
Xall the time.]
X
XSection 44.13: {mesg} default: mesg
X
XCauses write permission to be turned off to the terminal while you are in
Xvisual mode, if nomesg is set.
X
X[Author's note: I don't know if anyone could have made any one sentence
Xparagraph more confusing than this one.  What it says is: mesg allows people to
Xwrite to you even if you are in visual or open mode; nomesg locks your terminal
Xso they can't write to you and mess up your screen.]
X
XSection 44.14: {number, nu} default: nonumber
X
XCauses all output lines to be printed with their line numbers.  In addition
Xeach input line will be prompted with its line number.
X
XSection 44.15: {open} default: open
X
XIf {noopen}, the commands open and visual are not permitted.  This is set for
Xedit to prevent confusion resulting from accidental entry to open or visual
Xmode.
X
X[Author's note: As you may have guessed by now, there are actually three
Xeditors available under Berkeley UNIX that are in reality the same
Xprogram, ex, with different options set: ex itself, vi, and edit.]
X
XSection 44.16: {optimize, opt} default: optimize
X
XThroughput of text is expedited by setting the terminal to not do automatic
Xcarriage returns when printing more than one (logical) line of output, greatly
Xspeeding output on terminals without addressable cursors when text with leading
Xwhite space is printed.
X
X[Author's note: I still don't know what this option does.]
X
XSection 44.17: {paragraphs, para} default: para=IPLPPPQPP LIbp
X
XSpecifies the paragraphs for the [{] and [}] operations in open and visual.
XThe pairs of characters in the option's value are the names of the nroff macros
Xwhich start paragraphs.
X
XSection 44.18: {prompt} default: prompt
X
XCommand mode input is prompted for with a `:'.
X
X[Author's note: Doesn't seem to have any effect on vi.]
X
XSection 44.19: {readonly}, {ro} default: noro, unless invoked with -R 
X                                         or insufficient privileges on file
X
XThis option allows you to guarantee that you won't clobber your file by
Xaccident.  You can set the option and writes will fail unless you use an `!'
Xafter the write.  Commands such as {x}, {ZZ}, the autowrite option, and in
Xgeneral anything that writes is affected.  This option is turned on if you
Xinvoke the editor with the -R flag.
X
XSection 44.20: {redraw} default: noredraw
X
XThe editor simulates (using great amounts of output), an intelligent terminal
Xon a dumb terminal (e.g. during insertions in visual the characters to the
Xright of the cursor position are refreshed as each input character is typed).
XUseful only at very high baud rates, and should be used only if the system is
Xnot heavily loaded: you will notice the performance degradation yourself.
X
XSection 44.21: {remap} default: remap
X
XIf on, macros are repeatedly tried until they are unchanged.  For example, if o
Xis mapped to O, and O is mapped to I, then if remap is set, o will map to I,
Xbut if noremap is set, it will map to O .
X
XSection 44.22: {report} default: report=5 for ex and vi, 2 for edit
X
XSpecifies a threshold for feedback from commands.  Any command which modifies
Xmore than the specified number of lines will provide feedback as to the scope
Xof its changes.  For commands such as global, open, undo, and visual which have
Xpotentially more far reaching scope, the net change in the number of lines in
Xthe buffer is presented at the end of the command, subject to this same
Xthreshold.  Thus notification is suppressed during a global command on the
Xindividual commands performed.
X
XSection 44.23: {scroll} default: scroll=1/2 window
X
XDetermines the number of logical lines scrolled when a {^D} is received from a
Xterminal in command mode, and determines the number of lines printed by a
Xcommand mode z command (double the value of scroll).
X
X[Author's note: Doesn't seem to affect {^D} and {z} in visual (vi) mode.]
X
XSection 44.24: sections {sections} default: sections=SHNHH HU 
X
XSpecifies the section macros from nroff for the {[[} and {]]} operations in
Xopen and visual.  The pairs of characters in the options's value are the names
Xof the macros which start paragraphs.
X
XSection 44.25: {shell}, {sh} default: sh=/bin/sh 
X
XGives the path name of the shell forked for the shell escape command `!', and
Xby the shell command.  The default is taken from SHELL in the environment, if
Xpresent.
X
X[Editor's note: I would suggest that you place the following line in
Xyour .login file:
Xsetenv SHELL '/bin/csh'
X]
X
XSection 44.26: {shiftwidth}, {sw} default: sw=8 
X
XUsed in reverse tabbing with {^D} when using autoindent to append text, and
Xused by the shift commands.  Should probably be the same value as the tabstop
Xoption.
X
XSection 44.27: {showmatch}, {sm} default: nosm 
X
XIn open and visual mode, when a `)' or `}' is typed, if the matching `(' or `{'
Xis on the screen, move the cursor to it for one second.  Extremely useful with
Xcomplicated nested expressions, or with lisp.
X
XSection 44.28: {slowopen}, {slow} default: terminal dependent
X
XAffects the display algorithm used in visual mode, holding off display updating
Xduring input of new text to improve throughput when the terminal in use is both
Xslow and unintelligent.  See "An Introduction to Display Editing with Vi" for
Xmore details.
X
XSection 44.29: {tabstop}, {ts} default: ts=8
X
XThe editor expands tabs ^I to tabstop boundaries in the display.
X
XSection 44.30: {taglength}, {tl} default: tl=0
X
XTags are not significant beyond this many characters.
XA value of zero (the default) means that all characters are significant.
X
XSection 44.31: {tags} default: tags=tags /usr/lib/tags
X
XA path of files to be used as tag files for the tag command.  A requested tag
Xis searched for in the specified files, sequentially.  By default files called
Xtags are searched for in the current directory and in /usr/lib (a master file
Xfor the entire system).
X
X[Author's note: The author of this tutorial has never used this option, nor
Xseen it used.  I'm not even sure I know what they are talking about.]
X
XSection 44.32: {term} default: from environment variable TERM
X
XThe terminal type of the output device.
X
XSection 44.33: {terse} default: noterse
X
XShorter error diagnostics are produced for the experienced user.
X
XSection 44.34: {timeout} default: timeout
X
XCauses macros to time out after one second.  Turn it off and they will
Xwait forever.  This is useful if you want multi-character macros, but if
Xyour terminal sends escape sequences for arrow keys, it will be
Xnecessary to hit escape twice to get a beep.
X
X[Editor's note: Another paragraph which requires a cryptographer.]
X
XSection 44.35: ttytype
X
X[Editor's note: I have found no documentation for this option at all.]
X
XSection 44.36: {warn} default: warn
X
XWarn if there has been `[No write since last change]' before a `!' command
Xescape.
X
XSection 44.37: {window} default: window=speed dependent
X
XThe number of lines in a text window in the visual command.  The default is 8
Xat slow speeds (600 baud or less), 16 at medium speed (1200 baud), and the full
Xscreen (minus one line) at higher speeds.
X
XSection 44.38: {wrapscan}, {ws} default: ws
X
XSearches using the regular expressions in addressing will wrap around past the
Xend of the file.
X
XSection 44.39: {wrapmargin}, {wm} default: wm=0
X
XDefines a margin for automatic wrapover of text during input in open and visual
Xmodes.  The numeric value is the number of columns from the right edge of the
Xscreen around which vi looks for a convenient place to insert a new-line
Xcharacter (wm=0 is OFF).  This is very convenient for touch typists.
XWrapmargin behaves much like fill/nojustify mode does in nroff.
X
XSection 44.40: {writeany}, {wa} default: nowa
X
XInhibit the checks normally made before write commands, allowing a write to any
Xfile which the system protection mechanism will allow.
X
XSection 44.41: {w300}, {w1200}, {w9600} defaults: w300=8
X                                                 w1200=16
X                                                 w9600=full screen minus one
X
XThese are not true options but set the default size of the window for when the
Xspeed is slow (300), medium (1200), or high (9600), respectively.  They are
Xsuitable for an EXINIT and make it easy to change the 8/16/full screen rule.
X
XSection 45: Limitations
X
XHere are some editor limits that the user is likely to encounter:
X       1024   characters per line
X       256    characters per global command list
X       128    characters per file name
X       128    characters in the previous inserted and deleted text in open or 
X              visual
X       100    characters in a shell escape command
X       63     characters in a string valued option
X       30     characters in a tag name
X       250000 lines in the file (this is silently enforced).
X
XThe visual implementation limits the number of macros defined with map to 32,
Xand the total number of characters in macros to be less than 512.
X
X[Editor's note: these limits may not apply to versions after 4.1BSD.]
SHAR_EOF
echo shar: 3 control characters may be missing from "'vi.advanced'"
if test 70997 -ne "`wc -c < 'vi.advanced'`"
then
	echo shar: error transmitting "'vi.advanced'" '(should have been 70997 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'vi.beginner'" '(36328 characters)'
if test -f 'vi.beginner'
then
	echo shar: will not over-write existing file "'vi.beginner'"
else
sed 's/^X//' << \SHAR_EOF > 'vi.beginner'
XSection 1: {^F} {ZZ}
X
XTo get out of this tutorial, type: ZZ (two capital Z's).
X
XLearning a new computer system implies learning a new text editor.  These
Xtutorial lessons were created by Dain Samples to help you come to grips with
XUC Berkeley's screen oriented editor called vi (for VIsual). This tutorial
Xuses the vi editor itself as the means of presentation. 
X
XFor best use of this tutorial, read all of a screen before performing any of
Xthe indicated actions.  This tutorial (or, at least, the first half of it) has
Xbeen designed to systematically present the vi commands IF THE INSTRUCTIONS
XARE FOLLOWED!  If you are too adventuresome, you may find yourself lost.  If
Xyou ever find yourself stuck, remember the first line of this section.
X
XOK, now find the control key on your keyboard; it usually has CTL or CTRL
Xwritten on its upper surface.  Your first assignment is to hold the control
Xkey down while you press the 'F' key on your keyboard.  Please do so now.
X
X
X
XSection 2: {^F} {^B}
XMany of vi's commands use the control key and some other key in combination,
Xas with the control and the 'F' key above.  This is abbreviated CTL-F, or ^F.
X
XAs you have probably guessed by now, ^F (CTL-F) moves you forward a fixed
Xnumber of lines in the file.  Throughout the remainder of the tutorial when
Xyou are ready to advance to the next section of text, hit ^F.
X
XThe opposite command is ^B.  Just for fun, you might want to try a ^B to see
Xthe previous section again.  Be sure to do a ^F to return you here.
X
XDetermine what the cursor looks like on your screen.  Whatever it is (a box,
Xan underscore, blinking, flashing, inverse, etc.) it should now be positioned
Xin the upper left-hand corner of your screen under or on the S of Section.
XBecome familiar with your cursor: to use vi correctly it is important to
Xalways know where the cursor is.
X
XDid you notice that when you do a ^F the cursor is left at the top of the
Xscreen, and a ^B leaves the cursor near the bottom of the screen?  Try the two
Xcommands ^B^F again.  And now do another ^F to see the next section.
X
XSection 3: {^F} {^B}
XYou now have two basic commands for examining a file, both forwards (^F) and
Xbackwards (^B).
X
XNote that these are vi text editing commands: they are not commands for the
Xtutorial.  Indeed, this tutorial is nothing but a text file which you are now
Xediting.  Everything you do and learn in this tutorial will be applicable to
Xediting text files.
X
XTherefore, when you are editing a file and are ready to see more of the text,
Xentering ^F will get you to the next section of the file.  Entering ^B will
Xshow you the previous section.
X
XTime for you to do another ^F.
X
X
X
X
X
X
X
XSection 4: {^F} {^B} {^M} (return key)
XWe will adopt the notation of putting commands in curly braces so we can write
Xthem unambiguously.  For example, if you are to type the command sequence
X"control B control F" (as we asked you to do above) it would appear as {^B^F}.
XThis allows clear delineation of the command strings from the text. Remember
Xthat the curly braces are NOT part of the command string you are to type. Do
XNOT type the curly braces.  
X
XSometimes, the command string in the curly braces will be rather long, and may
Xbe such that the first couple of characters of the command will erase from
Xthe screen the string you are trying to read and type.  It is suggested that
Xyou write down the longer commands BEFORE you type them so you won't forget
Xthem once they disappear.
X
XNow locate the return key on your keyboard: it is usually marked 'RETURN',
Xindicate hitting the return key.  In fact, the control-M key sequence is
Xexactly the same as if you hit the return key, and vice versa.
X
XNow type {^F}.
X
X
XSection 5: {:q!} {ZZ} {^M} (return key)
XRecognize that this tutorial is nothing more than a text file that you
Xare editing.  This means that if you do something wrong, it is possible
Xfor you to destroy the information in this file.  Don't worry.  If this
Xhappens, type {ZZ} (two capital Z's) or {:q!^M} to leave the tutorial.
XRestart the tutorial.  Once in the tutorial, you can then page forward
Xwith {^F} until you are back to where you want to be.  (There are
Xeasier ways to do this, some of which will be discussed later, but this
Xis the most straightforward.)
X
XYou may want to write these commands down in a convenient place for quick
Xreference: {:q!^M} and {ZZ}
X
XWe will assume that you now know to do a {^F} to advance the file
X
X
X
X
X
X
X
XSection 6: {m} {G} {'} {z}
XNow that you know how to get around in the file via ^F and ^B let's look at
Xother ways of examining a text file.  Sometimes it is necessary, in the midst
Xof editing a file, to examine another part of the file.  You are then faced
Xwith the problem of remembering your place in the file, looking at the other
Xtext, and then getting back to your original location.  Vi has a 'mark'
Xcommand, m. Type {mp}.  You have just 'marked' your current location in the
Xfile and given it the name 'p'.  The command string below will do three
Xthings: position you at the beginning of the file (line 1), then return you to
Xthe location 'p' that you just marked with the 'm' command, and, since the
Xscreen will not look exactly the same as it does right now, the 'z' command
Xwill reposition the screen. (You may want to write the string down before
Xtyping it: once you type {1G} it will no longer be on the screen.)
X
XSo now type {1G'pz^M} - a one followed by a capital G, followed by the quote
Xmark, followed by a lower case 'p', then a lower case 'z', then a return
X(which is the same as a ^M).  The {1G} moves you to line 1, i.e. the beginning
Xof the file.  The {'p} moves you to the location you marked with {mp}.  The
X{z^M} command will repaint the screen putting the cursor at the top of the
Xscreen. (Now {^F}.)
X
XSection 7: {m} {G} {'} {z}
XLet's look at some variations on those commands.  If you wanted to look at
Xline 22 in the file and return to this location you could type {mp22G'p}.  Do
Xso now, observing that {22G} puts your cursor at the beginning of section 2 in
Xthe middle of the screen.
X
XAlso note that, without the {z^M} command, the line with 'Section 7' on it is
Xnow in the MIDDLE of the screen, and not at the top.  Our cursor is on the
Xcorrect line (where we did the {mp} command) but the line is not where we
Xmight like it to be on the screen.  That is the function of the {z^M} command.
X(Remember, ^M is the same as the 'return' key on your keyboard.)  Type {z^M}
Xnow and observe the effect.
X
XAs you can see, the 'Section 7' line is now at the top of the screen with the
Xcursor happily under the capital S.  If you would like the cursor line (i.e.
Xthe line which the cursor is on) in the middle of the screen again, you would
Xtype {z.}.  If you wanted the cursor line to be at the BOTTOM of the screen,
Xtype {z-}.  Try typing {z-z.z^M} and watch what happens.
X
X{^F}
X
XSection 8: {z} {m} {'}
X
XNote that the z command does not change the position of our cursor in the file
Xitself, it simply moves the cursor around on the screen by moving the contents
Xof the file around on the screen.  The cursor stays on the same line of the
Xfile when using the z command.
X
XThis brings up an important point.  There are two questions that the users of
Xvi continually need to know the answer to: "Where am I in the file?" and
X"Where am I on the screen?"  The cursor on your terminal shows the answer to
Xboth questions.  Some commands will move you around in the file, usually
Xchanging the location of the cursor on the screen as well.  Other commands
Xmove the cursor around on the screen without changing your location in the
Xfile.
X
XNow type {ma}.  Your location in the file has been given the name 'a'. If you
Xtype {'p'a} you will see the previous location we marked in section 7, and
Xthen will be returned to the current location.  (You will want to do a {z^M}
Xto repaint the screen afterwards.)  Try it.  
X{^F}
X
XSection 9: {m} {''}
XNow we can move about in our file pretty freely.  By using the {m} command we
Xcan give the current cursor position a lower-case-character name, like 'p',
X'a', 'e', 'm', or 'b'.  Using the {G} command preceded by a line number we can
Xlook at any line in the file we like.  Using the single quote command {'}
Xfollowed by a character used in an {m} command, we can return to any location
Xin the file we have marked.
X
XHowever, try {m3}, or {mM}.  You should hear a beep, or bell.  Only lower-case
Xletters are acceptable to the {m} and {'} commands: numbers, upper-case
Xletters, and special characters are not acceptable.
X
XIf you type the {'} command with a character that is lower-case alphabetic but
Xthat has not been used in an {m} command, or for which the 'marked' text has
Xbeen deleted, you will also get a beep.  Try {'i}.  You should get a beep
Xbecause the command {mi} has never been issued.  (Unless you've been
Xexperimenting.)
X
XThe command {''} attempts to return you to the location at which you last
Xmodified some part of your file.  However, my experience has been that it is
Xdifficult to predict exactly where you will end up.  
XSection 10: {^M} {-}
XNow do {ma}, marking your position at the top of the screen.  Now hit {^M} (or
Xreturn) until the cursor is right ... 
X* <- here, over/under the asterisk.  Now
Xtype {mb'a'b} and watch the cursor move from the asterisk to the top of the
Xscreen and back again.
X
XThe {^M} command moves the cursor to the beginning of the next line.  Now type
X{^M} until the cursor is right ...
X* <- here.  The command to move the cursor to the beginning of the
Xprevious line is {-}.  Practice moving the cursor around on the screen by using
X{^M} and {-}.  BE CAREFUL to not move the cursor OFF the screen just yet.  If
Xyou do, type {'az^M}.
X
XNow we can move to any line within the screen.  Practice moving around in the
Xfile using the {^F}, {^B}, {-}, {^M}, {z}, and {'} commands.  When you are
Xfairly confident that you can get to where you need to be in the file, and
Xposition the cursor on the screen where you want it type {'az^M^F} (which, of
Xcourse, moves you back to the beginning of this section, repositions the
Xcursor at the top of the screen, and advances you to the next section).
X
XSection 11: scrolling: {^M}
XThe cursor should now be on the S of 'Section 11', and this should be on the
Xfirst line of the screen.  If it is not, do {^M} or {-} as appropriate to put
Xthe cursor on the section line, and type {z^M}.
X
XType {mc} to mark your place.
X
XNow type {^M} until the cursor is on the last line of this screen.  Now do one
Xmore {^M} and observe the result.  This is called scrolling.  When you
Xattempted to move to a line not displayed on the screen, the line at the top of
Xthe screen was 'scrolled off', and a line at the bottom of the screen was
X'scrolled on'.  The top line with 'Section 11' should no longer be visible.
X
XNow type {'cz^M} to reset the screen and type {^F} for the next section.
X
X
X
X
X
X
X
XSection 12: {-} {z}
X
XThe {-} command moves the cursor to the previous line in the file.  Now type
X{-}, which attempts to move the cursor to the previous line in this file.
XHowever, that line is not on the screen.  The resulting action will depend on
Xyour terminal.  (Do a {^Mz^M} to reposition the file).  On intelligent
Xterminals (e.g. VT100s, Z19s, Concept 100s), a top line is 'scrolled on' and
Xthe bottom line is 'scrolled off'.  Other terminals, however, may not have
Xthis 'reverse scrolling' feature.  They will simply repaint the screen with
Xthe cursor line in the middle of the screen.  On such terminals it is
Xnecessary to type {z^M} to get the cursor line back to the top of the screen.
X
X
X
X
X
X
X
X
X
X
XSection 13:
XUp until this point, the tutorial has always tried to make sure that the first
Xline of each screen has on it the section number and a list of the commands
Xcovered in that section.  This will no longer be strictly maintained.  If you
Xwant the section line at the top of the screen, you now know enough commands to
Xdo it easily: do {^M} or {-} until the cursor is on the section line and
Xthen {z^M}.  Also, from this point on, it may not be the case that a {^F} will
Xput you at the beginning of the next section.  Therefore, be aware of where you
Xare in the file as we look at other commands.  You may have to find your way
Xback to a particular section without any help from the tutorial.  If you do not
Xfeel comfortable with this, then it is suggested that you practice moving from
Xsection 1 to section 13, back and forth, using {^M}, {-}, {^F}, and {^B}
Xcommands for a while.
X
XAlso make liberal use of the mark command {m}: if, for example, you make a
Xhabit of using {mz} to mark your current location in the file, then you will
Xalways be able to return to that location with {'z} if the editor does
Xsomething strange and you have no idea where you are or what happened.
X
XAnd finally, the proscription against experimentation is hereby lifted: play
Xwith the editor.  Feel free to try out variations on the commands and move
Xaround in the file.  By this time you should be able to recover from any gross
Xerrors.
X
XSection 14: {^E} {^Y} {^D} {^U}
XLet us now look at a few other commands for moving around in the file, and
Xmoving the file around on the screen.  Note that the commands we have already
Xlooked at are sufficient: you really don't need any more commands for looking
Xin a file.  The following commands are not absolutely necessary.  However,
Xthey can make editing more convenient, and you should take note of their
Xexistence.  But it would be perfectly valid to decide to ignore them on this
Xfirst pass: you can learn them later when you see a need for them, if you ever
Xdo.
X
XFirst, let's clear up some potentially confusing language.  In at least one
Xplace in the official document ('An Introduction to Display Editing with Vi'
Xby William Joy, and Mark Horton, September 1980), the expression "to scroll
Xdown text" means that the cursor is moved down in your file.  However, note
Xthat this may result in the text on the screen moving UP.  This use of the
Xword 'scroll' refers to the action of the cursor within the file.  However,
Xanother legitimate use of the word refers to the action of the text on the
Xscreen.  That is, if the lines on your screen move up toward the top of the
Xscreen, this would be 'scrolling the screen up'.  If the lines move down
Xtoward the bottom of the screen, this would be refered to as scrolling down.
X
XI have tried to maintain the following jargon: 'scrolling' refers to what the
Xtext does on the screen, not to what the cursor does within the file.  For the
Xlatter I will refer to the cursor 'moving', or to 'moving the cursor'.  I
Xrealize that this is not necessarily consistent with Joy and Horton, but they
Xwere wrong.
X
X{^E} scrolls the whole screen up one line, keeping the cursor on the same line,
Xif possible.  However, if the cursor line is the first line on the screen, then
Xthe cursor is moved to the next line in the file.  Try typing {^E}.
X
X{^Y} scrolls the screen down one line, keeping the cursor on the same line, if
Xpossible.  However, if the cursor line is the last line on the screen, then the
Xcursor is moved to the previous line in the file.  Try it.
X
X{^D} moves the cursor down into the file, scrolling the screen up.
X
X{^U} moves the cursor up into the file, also scrolling the screen if the
Xterminal you are on has the reverse scroll capability.  Otherwise the
Xscreen is repainted.
X
XNote that {^E} and {^Y} move the cursor on the screen while trying to keep the
Xcursor at the same place in the file (if possible: however, the cursor can
Xnever move off screen), while {^D} and {^U} keep the cursor at the same place
Xon the screen while moving the cursor within the file.
X
XSection 15: {/ .. /^M}
X
XAnother way to position yourself in the file is by giving the editor a string
Xto search for.  Type the following: {/Here 1/^M} and the cursor should end up
Xright ...........................here ^.  Now type {/Section 15:/^M} and the
Xcursor will end up over/on .....................here ^.  Now type {//^M} and
Xobserve that the cursor is now over the capital S five lines above this line.
XTyping {//^M} several more times will bounce the cursor back and forth between
Xthe two occurrences of the string.  In other words, when you type a string
Xbetween the two slashes, it is searched for.  Typing the slashes with nothing
Xbetween them acts as if you had typed the previous string again.
X
XObserve that the string you type between the two slashes is entered on the
Xbottom line of the screen.  Now type {/Search for x /^M} except replace the 'x'
Xin the string with some other character, say 'b'.  The message "Pattern not
Xfound" should appear on the bottom of the screen.  If you hadn't replaced the
X'x', then you would have found the string.  Try it.
X
XSection 16: {? .. ?^M} {n} (search strings: ^ $)
X
XWhen you surround the sought-for string with slashes as in {/Search/}, the
Xfile is searched beginning from your current position in the file.  If the
Xstring is not found by the end of the file, searching is restarted at the
Xbeginning of the file.  However, if you do want the search to find the
XPREVIOUS rather than the NEXT occurrence of the string, surround the string
Xwith question marks instead of slash marks.
X
XBelow are several occurrences of the same string.  
XHere 2            Here 2 Here 2
X Here 2             Here 2.
XObserve the effect of the following search commands (try them in the
Xsequence shown):
X{/Here 2/^M}  {//^M}  {??^M}
X{/^Here 2/^M}  {//^M}  {??^M}
X{/Here 2$/^M}  {//^M}  {??^M}
X
XThe first command looks for the next occurrence of the string 'Here 2'.
XHowever the second line of commands looks for an occurrence of 'Here 2' that
Xis at the beginning of the line.  When the up-arrow is the first character of
Xa search string it stands for the beginning of the line.  When the dollar-sign
Xis the last character of the search string it stands for the end of the line.
XTherefore, the third line of commands searches for the string only when it is
Xat the end of the line.  Since there is only one place the string begins a
Xline, and only one place the string ends the line, subsequent {//^M} and
X{??^M} will find those same strings over and over.
X
XThe {n} command will find the next occurrence of the / or ? search
Xstring.  Try {/Here 2/^M} followed by several {n} and observe the
Xeffect.  Then try {??^M} followed by several {n}.  The {n} command
Xremembers the direction of the last search.  It is just a way to save a
Xfew keystrokes.
X
XSection 17: \ and magic-characters in search strings
X
XNow type {/Here 3$/^M}.  You might expect the cursor to end up
Xright......^ here.  However, you will get "Pattern not found" at the bottom of
Xthe screen.  Remember that the dollar-sign stands for the end of the line.
XSomehow, you must tell vi that you do not want the end of the line, but a
Xdollar-sign.  In other words, you must take away the special meaning that the
Xdollar-sign has for the search mechanism.  You do this (for any special
Xcharacter, including the up-arrow ^) by putting a back-slash ('\', not '/') in
Xfront of the character.
X
XNow try {/Here 3\$/^M} and you should end up nine lines above this one.  Try
X{//^M} and note that it returns you to the same place, and not to the first
Xline of this paragraph: the back-slash character is not part of the search
Xstring and will not be found.  To find the string in the first line of this
Xparagraph, type {/Here 3\\\$/^M}.  There are three back-slashes: the first takes
Xaway the special meaning from the second, and the third takes away the special
Xmeaning from the dollar-sign.
X
XFollowing is a list of the characters that have special meanings in search
Xstrings.  If you wish to find a string containing one of these characters, you
Xwill have to be precede the character with a backslash.  These characters are
Xcalled magic characters because of the fun and games you can have with them
Xand they can have with you, if you aren't aware of what they do.  
X
X  ^ - (up-arrow)       beginning of a line
X  $ - (dollar-sign)    end of a line
X  . - (period)         matches any character
X  \ - (backslant)      the escape character itself
X  [ - (square bracket) for finding patterns (see section #SEARCH)
X  ] - (square bracket) ditto
X  * - (asterisk)       ditto
X
XWithout trying to explain it here, note that {:set nomagic^M} turns off the
Xspecial meanings of all but the ^ up-arrow, $ dollar-sign, and backslash
Xcharacters.
X
XSection 18: {: (colon commands)} {ZZ}
X
XIn this section we will discuss getting into and out of the editor in more
Xdetail.  If you are editing a file and wish to save the results the command
Xsequence {:w^M} writes the current contents of the file out to disk, using the
Xfile name you used when you invoked the editor.  That is, if you are at the
Xcommand level in Unix, and you invoke vi with {vi foo} where foo is the name
Xof the file you wish to edit, then foo is the name of the file used by the
X{:w^M} command.
X
XIf you are done, the write and quit commands can be combined into a single
Xcommand {:wq^M}.  An even simpler way is the command {ZZ} (two capital Z's).
X
XIf, for some reason, you wish to exit without saving any changes you have made,
X{:q!^M} does the trick.  If you have not made any changes, the exclamation
Xpoint is not necessary: {:q^M}.  Vi is pretty good about not letting you
Xget out without warning you that you haven't saved your file.
X
XWe have mentioned before that you are currently in the vi editor, editing a
Xfile.  If you wish to start the tutorial over from the very beginning, you
Xcould {ZZ}, and then type {vi.tut beginner} in response to the Unix prompt.
XThis will create a fresh copy of this file for you, which might be necessary 
Xif you accidentally destroyed the copy you were working with.  Just do a 
Xsearch for the last section you were in: e.g.  {/Section 18:/^Mz^M}.
X
XSection 19: {H} {M} {L}
X
XHere are a few more commands that will move you around on the screen.  Again,
Xthey are not absolutely necessary, but they can make screen positioning easier:
X
X{H} - puts the cursor at the top of the screen (the 'home' position)
X
X{M} - puts the cursor in the middle of the screen
X
X{L} - puts the cursor at the bottom of the screen.
X
XTry typing {HML} and watch the cursor.
X
XTry typing {5HM5L} and note that 5H puts you five lines from the top of the
Xscreen, and 5L puts you five lines from the bottom of the screen.
X
XSection 20: {w} {b} {0} {W} {B} {e} {E} {'} {`}
X
XUp to this point we have concentrated on positioning in the file, and
Xpositioning on the screen.  Now let's look at positioning in a line.  Put the
Xcursor at the beginning of the following line and type {z^M}:
X
XThis is a test line: your cursor should initially be at its beginning.
X
XThe test line should now be at the top of your screen. Type {w} several times.
XNote that it moves you forward to the beginning of the next word.  Now type
X{b} (back to the beginning of the word) several times till you are at the
Xbeginning of the line.  (If you accidentally type too many {b}, type {w} until
Xyou are on the beginning of the line again.) Type {wwwww} (five w's) and note
Xthat the cursor is now on the colon in the sentence.  The lower-case w command
Xmoves you forward one word, paying attention to certain characters such as
Xcolon and period as delimiters and counting them as words themselves.  Now
Xtype {0} (zero, not o 'oh'): this moves you to the beginning of the current
Xline.  Now type {5w} and notice that this has the effect of repeating {w} five
Xtimes and that you are now back on the colon.  Type {0} (zero) again.  To
Xignore the delimiters and to move to the beginning of the next word using only
Xblanks, tabs and carriage-returns (these are called white-space characters) to
Xdelimit the words, use the {W} command: upper-case W.  {B} takes you back a
Xword using white-space characters as word delimiters.
X
XNote that the commands {wbWB} do not stop at the beginning or end of a line:
Xthey will continue to the next word on the next line in the direction specified
X(a blank line counts as a word).
X
XIf you are interested in the END of the word, and not the BEGINNING, then use
Xthe {e} and {E} commands.  These commands only move forward and there are no
Xcorresponding 'reverse search' commands for the end of a word.
X
XAlso, we have been using the {'} command to move the cursor to a position that
Xwe have previously marked with the {m} command.  However, position the cursor
Xin the middle of a line (any line, just pick one) and type {mk}, marking that
Xposition with the letter k.  Now type a few returns {^M} and type {'k}.
XObserve that the cursor is now at the beginning of the line that you marked.
XNow try {`k}: note that this is the reverse apostrophe, or back-quote, or grave
Xaccent, or whatever you want to call it.  Also note that it moves you to the
Xcharacter that was marked, not just to the line that was marked.
X
XIn addition, the {``} command works just like the {''} command except that you
Xare taken to the exact character, not just to the line.  (I'm still not
Xsure which exact character, just as I'm still not sure which line.)
X
XSection 21: {l} {k} {j} {h}
X
XThere are several commands to move around on the screen on a character by
Xcharacter basis:
X
Xl - moves the cursor one character to the RIGHT
Xk - moves the cursor UP one line
Xj - moves the cursor DOWN one line
Xh - moves the cursor one character to the LEFT
X
XSection 22: {i} {a} {I} {A} {o} {O} ^[ (escape key)
X
XFor this and following sections you will need to use the ESCAPE key on your
Xterminal.  It is usually marked ESC.  Since the escape key is the same as
Xtyping {^[} we will use ^[ for the escape key.
X
XProbably the most often used command in an editor is the insert command.  Below
Xare two lines of text, the first correct, the second incorrect.  Position your
Xcursor at the beginning of Line 1 and type {z^M}.
X
XLine 1: This is an example of the insert command.
XLine 2: This is an of the insert command.
X
XTo make line 2 look like line 1, we are going to insert the characters
X'example ' before the word 'of'.  So, now move the cursor so that it is
Xpositioned on the 'o' of 'of'.  (You can do this by typing {^M} to move
Xto the beginning of line 2, followed by {6w} or {wwwwww} to position the cursor
Xon the word 'of'.)
X
XNow carefully type the following string and observe the effects:
X  {iexample ^[}  (remember: ^[ is the escape key)}
XThe {i} begins the insert mode, and 'example ' is inserted into the line: 
Xbe sure to notice the blank in 'example '.  The ^[ ends insertion mode, 
Xand the line is updated to include the new string.  Line 1 should look exactly 
Xlike Line 2.
X
XMove the cursor to the beginning of Line 3 below and type {z^M}:
X
XLine 3: These lines are examples for the 'a' command.
XLine 4: These line are examples for the '
X
XWe will change line four to look like line three by using the append command.
XWe need to append an 's' to the word 'line'.  Position the cursor on the 'e'
Xof 'line'.  You can do this in several ways, one way is the following:
XFirst, type {/line /^M}.  This puts us on the word 'line' in Line 4
X(the blank in the search string is important!).  Next, type {e}.  The 'e' puts
Xus at the end of the word.  Now, type {as^[  (^[ is the escape character)}.  
XThe 'a' puts us in insert mode, AFTER the current character.  We appended the 
X's', and the escape ^[ ended the insert mode.
X
XThe difference between {i} (insert) and {a} (append) is that {i} begins
Xinserting text BEFORE the cursor, and {a} begins inserting AFTER the cursor.
X
XNow type {Aa' command.^[}.  The cursor is moved to the end of the line and the
Xstring following {A} is inserted into the text.  Line 4 should now look like
Xline 3.
X
XJust as {A} moves you to the end of the line to begin inserting, {I} would
Xbegin inserting at the FRONT of the line.
X
XTo begin the insertion of a line after the cursor line, type {o}.  To insert a
Xline before the cursor line, type {O}.  In other words {o123^[} is equivalent
Xto {A^M123^[}, and {O123^[} is equivalent to {I123^M^[}.  The text after the
X{o} or {O} is ended with an escape ^[.
X
XThis paragraph contains information that is terminal dependent: you will just
Xhave to experiment to discover what your terminal does.  Once in the insert
Xmode, if you make a mistake in the typing, ^H will delete the previous
Xcharacter up to the beginning of the current insertion.  ^W will delete the
Xprevious word, and one of ^U, @, or ^X will delete the current line (up to the
Xbeginning of the current insertion).  You will need to experiment with ^U, @,
Xand ^X to determine which works for your terminal.
X
XSection 23: {f} {x} {X} {w} {l} {r} {R} {s} {S} {J}
X
XPosition the cursor at the beginning of line 5 and {z^M}:
X
XLine 5: The line as it should be.
XLine 6: The line as it shouldn't be.
X
XTo make Line 6 like Line 5, we have to delete the 'n', the apostrophe, and the
X't'.  There are several ways to position ourselves at the 'n'.  Choose
Xwhichever one suits your fancy:
X
X{/n't/^M}
X{^M7w6l}  or  {^M7w6 } (note the space)
X{^M3fn}  (finds the 3rd 'n' on the line)
X
XNow {xxx} will delete the three characters, as will {3x}.
X
XNote that {X} deletes the character just BEFORE the cursor, as opposed
Xto the character AT the cursor.
X
XPosition the cursor at line 7 and {z^M}:
X
XLine 7: The line as it would be.
XLine 8: The line as it could be.
X
XTo change line 8 into line 7 we need to change the 'c' in 'could' into a 'w'.
XThe 'r' (replace) command was designed for this.  Typing {rc} is the same as
Xtyping {xic^[} (i.e.  delete the 'bad' character and insert the correct
Xnew character).  Therefore, assuming that you have positioned the cursor on the
X'c' of 'could', the easiest way to change 'could' into 'would' is {rw}.
X
XIf you would like to now change the 'would' into 'should', use the substitute
Xcommand, 's': {ssh^[}.  The difference between 'r' and 's' is that 'r'
X(replace) replaces the current character with another character, while 's'
X(substitute) substitutes the current character with a string, ended with an
Xescape.
X
XThe capital letter version of replace {R} replaces each character by a
Xcharacter one at a time until you type an escape, ^[.  The 'S' command
Xsubstitutes the whole line.
X
XPosition your cursor at the beginning of line 9 and {z^M}.
X
XLine  9: Love is a many splendored thing.
XLine 10: Love is a most splendored thing.
X
XTo change line 10 into line 9, position the cursor at the beginning of 'most',
Xand type {Rmany^[}.
X
XYou may have noticed that, when inserting text, a new line is formed by typing
X{^M}.  When changing, replacing, or substituting text you can make a new line
Xby typing {^M}.  However, neither {x} nor {X} will remove ^M to make two lines 
Xinto one line.  To do this, position the cursor on the first of the two lines 
Xyou wish to make into a single line and type {J} (uppercase J for 'Join').
X
XSection 24: {u} {U}
X
XFinally, before we review, let's look at the undo command.  Position
Xyour cursor on line 11 below and {z^M}.
X
XLine 11: The quick brown fox jumped over the lazy hound dog.
XLine 12: the qwick black dog dumped over the laxy poune fox.
X
XType the following set of commands, and observe carefully the effect of each 
Xof the commands:
X
X{/^Line 12:/^M} {ft} {rT} {fw} {ru} {w} {Rbrown fox^[} {w} {rj} 
X{fx} {rz} {w} {Rhound dog^[}
X
XLine 12 now matches line 11.  Now type {U} - capital 'U'.  And line 12 now
Xlooks like it did before you typed in the command strings.  Now type:
X
X{ft} {rT} {fw} {ru} {^M} {^M}
X
Xand then type {u}:  the cursor jumps back to the line containing the second
Xchange you made and 'undoes' it.  That is, {U} 'undoes' all the changes on the
Xline, and {u} 'undoes' only the last change.  Type {u} several times and
Xobserve what happens: {u} can undo a previous {u}!
X
XCaveat: {U} only works as long as the cursor is still on the line.  Move the
Xcursor off the line and {U} will have no effect, except to possibly beep at
Xyou.  However, {u} will undo the last change, no matter where it occurred.
X
XSection 25: review
X
XAt this point, you have all the commands you need in order to make use of vi.
XThe remainder of this tutorial will discuss variations on these commands as
Xwell as introduce new commands that make the job of editing more efficient.
XHere is a brief review of the basic commands we have covered.  They are listed
Xin the order of increasing complexity and/or decreasing necessity (to say that
Xa command is less necessary is not to say that it is less useful!).  These
Xcommands allow you to comfortably edit any text file.  There are other
Xcommands that will make life easier but will require extra time to learn,
Xobviously.  You may want to consider setting this tutorial aside for several
Xweeks and returning to it later after gaining experience with vi and getting
Xcomfortable with it.  The convenience of some of the more exotic commands may
Xthen be apparent and worth the extra investment of time and effort
Xrequired to master them.
X
Xto get into the editor from Unix:           {vi filename}
Xto exit the editor
X      saving all changes                    {ZZ} or {:wq^M}
X      throwing away all changes             {:q!^M}
X      when no changes have been made        {:q^M}
Xsave a file without exiting the editor      {:w^M}
Xwrite the file into another file            {:w filename^M}
Xinsert text 
X      before the cursor                     {i ...text... ^[}
X      at the beginning of the line          {I ...text... ^[}
X      after the cursor (append)             {a ...text... ^[}
X      at the end of the line                {A ...text... ^[}
X      after the current line                {o ...text... ^[}
X      before the current line               {O ...text... ^[}
Xdelete the character  ...
X      under the cursor                      {x}
X      to the left of the cursor             {X}
Xdelete n characters                         {nx} or {nX}  (for n a number)
Xmake two lines into one line (Join)         {J}
Xfind a string in the file ...
X      searching forward                     {/ ...string... /^M}
X      searching backwards                   {? ...string... ?^M}
Xrepeat the last search command              {n}
Xrepeat the last search command in the
X  opposite direction                        {N}
Xfind the character c on this line ...
X      searching forward                     {fc}
X      searching backward                    {Fc}
Xrepeat the last 'find character' command    {;}
Xreplace a character with character x        {rx}
Xsubstitute a single character with text     {s ...text... ^[}
Xsubstitute n characters with text           {ns ...text... ^[}
Xreplace characters one-by-one with text     {R ...text... ^[}
Xundo all changes to the current line        {U}
Xundo the last single change                 {u}
Xmove forward in the file a "screenful"      {^F}
Xmove back in the file a "screenful"         {^B}
Xmove forward in the file one line           {^M} or {+}
Xmove backward in the file one line          {-}
Xmove to the beginning of the line           {0}
Xmove to the end of the line                 {$}
Xmove forward one word                       {w}
Xmove forward one word, ignoring punctuation {W}
Xmove forward to the end of the next word    {e}
Xto the end of the word, ignoring punctuation{E}
Xmove backward one word                      {b}
Xmove back one word, ignoring punctuation    {B}
Xreturn to the last line modified            {''}
Xscroll a line onto the top of the screen    {^Y}
Xscroll a line onto the bottom of the screen {^E}
Xmove "up" in the file a half-screen         {^U}
Xmove "down" in the file a half-screen       {^D}
Xmove the cursor to the top screen line      {H}
Xmove the cursor to the bottom screen line   {L}
Xmove the cursor to the middle line          {M}
Xmove LEFT one character position            {h} or {^H}
Xmove RIGHT one character position           {l} or { }
Xmove UP in the same column                  {k} or {^P}
Xmove DOWN in the same column                {j} or {^N}
Xmark the current position, name it x        {mx}
Xmove to the line marked/named x             {'x}
Xmove to the character position named x      {`x}
Xmove to the beginning of the file           {1G}
Xmove to the end of the file                 {G}
Xmove to line 23 in the file                 {23G}
Xrepaint the screen with the cursor line
X       at the top of the screen             {z^M}
X       in the middle of the screen          {z.}
X       at the bottom of the screen          {z-}
X
XMore information on vi can be found in the file vi.advanced, which you can
Xperuse at your leisure.  From UNIX, type {vi.tut advanced^M}.  
SHAR_EOF
if test 36328 -ne "`wc -c < 'vi.beginner'`"
then
	echo shar: error transmitting "'vi.beginner'" '(should have been 36328 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0

