181 lines
6 KiB
Text
181 lines
6 KiB
Text
|
Viper tutorial #4: Insertion Techniques
|
||
|
|
||
|
This lesson lasts 5-10 minutes. This tutorial assumes full knowledge
|
||
|
of tutorial #1, and familiarity with tutorial #2. Lines which begin
|
||
|
with >>> mark exercises you should try. When you want to exit this
|
||
|
tutorial type 'Z''Z' .
|
||
|
|
||
|
|
||
|
SIMPLE INSERTION
|
||
|
----------------
|
||
|
You spend most of your time in vi inserting text. As you might expect,
|
||
|
there are several commands to begin insertion.
|
||
|
|
||
|
'o' OPEN a line below the cursor
|
||
|
'O' OPEN a line above the cursor
|
||
|
|
||
|
'i' INSERT starting before the cursor
|
||
|
'I' INSERT at the beginning of the line
|
||
|
|
||
|
'a' APPEND starting after the cursor
|
||
|
'A' APPEND at the end of the line
|
||
|
|
||
|
Remember to type ESC to leave insert mode. If you don't have an ESC key
|
||
|
type C-[ (control [ ).
|
||
|
|
||
|
ESC ESCAPE from insert mode
|
||
|
|
||
|
>>> Move the cursor to this line. Type 'O' , enter your name. Press ESC.
|
||
|
>>> Next type 'o' , enter the date. Press ESC.
|
||
|
|
||
|
Note that 'O' opens the line above and puts you in insert mode,
|
||
|
while 'o' opens the line below and also puts you in insert mode.
|
||
|
|
||
|
>>> Type 'a' on any line above, enter your name. Press ESC. Do the
|
||
|
>>> same for 'A'.
|
||
|
|
||
|
>>> Read the following. Your goal is to take the sentence fragment below:
|
||
|
|
||
|
BROWN FOX OVER THE SEVEN LAZY
|
||
|
|
||
|
>>> and convert it to
|
||
|
|
||
|
THE QUICK BROWN FOX JUMPED OVER THE SEVEN LAZY DOGS.
|
||
|
|
||
|
>>> To do this type:
|
||
|
>>> 'I' to insert THE QUICK (then press ESC)
|
||
|
>>> move the cursor to after the X in FOX
|
||
|
>>> 'a' to insert JUMPED (then press ESC)
|
||
|
>>> 'A' to insert DOGS. (then press ESC)
|
||
|
>>> Now move to the sentence fragment and make the changes outlined above.
|
||
|
|
||
|
|
||
|
JOINING LINES
|
||
|
-------------
|
||
|
Often it is convenient to join two short lines into one line. There
|
||
|
are several ways to do this. The easiest is the J command. Other
|
||
|
methods will be explored in tutorial #5.
|
||
|
|
||
|
'J' JOIN two lines
|
||
|
|
||
|
>>> Go to the first line in the block below. Type J. Type J again.
|
||
|
|
||
|
Example: NOW IS THE TIME
|
||
|
the walrus said
|
||
|
TO THINK OF MANY THINGS
|
||
|
|
||
|
In the event that joining lines creates a line which exceeds the width
|
||
|
of the screen, you can break the line by typing i and pressing RETURN.
|
||
|
|
||
|
|
||
|
SUBSTITUTING TEXT
|
||
|
-----------------
|
||
|
Substituting combines the delete command and the insert command into a
|
||
|
single step.
|
||
|
|
||
|
#'s' SUBSTITUTE for # characters
|
||
|
#'S' SUBSTITUTE for # whole lines
|
||
|
|
||
|
|
||
|
In order to substitute text you have to know how much text you want to
|
||
|
delete. Consider the following examples:
|
||
|
|
||
|
'3''s' SUBSTITUTE the next 3 characters for what will be typed
|
||
|
'7''s' SUBSTITUTE the next 7 characters for what will be typed
|
||
|
|
||
|
>>> Change the SAMPLE DEFINITION below. To do this:
|
||
|
>>> move the cursor to the T in TWO
|
||
|
>>> type '3's
|
||
|
>>> type FOUR then press ESC
|
||
|
|
||
|
SAMPLE DEFINITION: A string quartet is defined to be
|
||
|
a group of TWO musicians.
|
||
|
|
||
|
|
||
|
REPLACING TEXT
|
||
|
--------------
|
||
|
The 'r' and 'R' commands allow you to directly type over existing text.
|
||
|
|
||
|
'r' REPLACE character (NO need to press ESC)
|
||
|
'R' enter over-type mode
|
||
|
|
||
|
>>> Correct each of the TYPOs on the sample line below. To do this:
|
||
|
>>> move the cursor to the misspelled character
|
||
|
>>> type 'r'
|
||
|
>>> type the correct character
|
||
|
|
||
|
SAMPLE: maintanence conveniance complience applience dilagent
|
||
|
|
||
|
>>> Use the over-type command, 'R' , on the sample line above.
|
||
|
>>> Type 'R' then type the name of a local restaurant. Press ESC.
|
||
|
|
||
|
|
||
|
CHANGING TEXT
|
||
|
-------------
|
||
|
The change command combines insertion, deletion, and the movement
|
||
|
commands. (Recall that the movement commands were taught in tutorial
|
||
|
#2.) Change is probably more useful than replace or substitute. The
|
||
|
general form of the change command is:
|
||
|
|
||
|
'c'movement CHANGE to where the movement command specifies
|
||
|
|
||
|
Consider the following examples:
|
||
|
|
||
|
'c''w' CHANGE to the beginning of the next WORD
|
||
|
'c''$' CHANGE to the end of the line
|
||
|
'c'')' CHANGE to the beginning of the next sentence
|
||
|
'c''t'e CHANGE 'TIL the next e
|
||
|
'c''3''w' CHANGE the next 3 WORDS
|
||
|
'c''c' CHANGE a line (cc is a special case of the c command)
|
||
|
'c''}' CHANGE to the end of the paragraph
|
||
|
|
||
|
>>> Follow these steps:
|
||
|
>>> 1. move to the desired location in the practice paragraph below
|
||
|
>>> 2. type 'c''w' (change to the beginning of the next WORD)
|
||
|
>>> 3. type your name
|
||
|
>>> 4. press ESC
|
||
|
|
||
|
PRACTICE here. Now is the time for all good users to learn the
|
||
|
editor. The quick red fox jumped over the seven lazy fish. Now
|
||
|
is the time for all good users to learn the editor. The quick
|
||
|
brown computer jumped over the seven lazy users. END PRACTICE
|
||
|
|
||
|
>>> Experiment by using a variety of options for step #2. Try
|
||
|
>>> out 'c''$' 'c'')' 'c''t'e 'c''3''w' 'c''c' 'c''}' on the practice paragraph above.
|
||
|
|
||
|
Note that the change command follows the same pattern as the delete
|
||
|
and yank commands which were explored in tutorial #3.
|
||
|
|
||
|
|
||
|
SUMMARY
|
||
|
-------
|
||
|
|
||
|
'o' OPEN a line below the cursor
|
||
|
'O' OPEN a line above the cursor
|
||
|
|
||
|
'i' INSERT starting before the cursor
|
||
|
'I' INSERT at the beginning of the line
|
||
|
|
||
|
'a' APPEND starting after the cursor
|
||
|
'A' APPEND at the end of the line
|
||
|
|
||
|
ESC ESCAPE from insert mode
|
||
|
|
||
|
'J' JOIN two lines
|
||
|
|
||
|
#'s' SUBSTITUTE for # characters
|
||
|
#'S' SUBSTITUTE for # whole lines
|
||
|
|
||
|
'r' REPLACE character (NO need to press ESC)
|
||
|
'R' enter over-type mode
|
||
|
|
||
|
'c'movement CHANGE to where the movement commands specifies
|
||
|
(e.g. 'c''3''w' 'c''$' 'c''c' )
|
||
|
|
||
|
|
||
|
These commands should improve your ability to insert text efficiently.
|
||
|
The next tutorials deal with advanced commands and tricks which can
|
||
|
further speed up your editing.
|
||
|
|
||
|
Copyright (c) 1992 Jill Kliger and Wesley Craig. All Rights Reserved.
|