1 Viper tutorial #4: Insertion Techniques
3 This lesson lasts 5-10 minutes. This tutorial assumes full knowledge
4 of tutorial #1, and familiarity with tutorial #2. Lines which begin
5 with >>> mark exercises you should try. When you want to exit this
11 You spend most of your time in vi inserting text. As you might expect,
12 there are several commands to begin insertion.
14 'o' OPEN a line below the cursor
15 'O' OPEN a line above the cursor
17 'i' INSERT starting before the cursor
18 'I' INSERT at the beginning of the line
20 'a' APPEND starting after the cursor
21 'A' APPEND at the end of the line
23 Remember to type ESC to leave insert mode. If you don't have an ESC key
24 type C-[ (control [ ).
26 ESC ESCAPE from insert mode
28 >>> Move the cursor to this line. Type 'O' , enter your name. Press ESC.
29 >>> Next type 'o' , enter the date. Press ESC.
31 Note that 'O' opens the line above and puts you in insert mode,
32 while 'o' opens the line below and also puts you in insert mode.
34 >>> Type 'a' on any line above, enter your name. Press ESC. Do the
37 >>> Read the following. Your goal is to take the sentence fragment below:
39 BROWN FOX OVER THE SEVEN LAZY
43 THE QUICK BROWN FOX JUMPED OVER THE SEVEN LAZY DOGS.
46 >>> 'I' to insert THE QUICK (then press ESC)
47 >>> move the cursor to after the X in FOX
48 >>> 'a' to insert JUMPED (then press ESC)
49 >>> 'A' to insert DOGS. (then press ESC)
50 >>> Now move to the sentence fragment and make the changes outlined above.
55 Often it is convenient to join two short lines into one line. There
56 are several ways to do this. The easiest is the J command. Other
57 methods will be explored in tutorial #5.
61 >>> Go to the first line in the block below. Type J. Type J again.
63 Example: NOW IS THE TIME
65 TO THINK OF MANY THINGS
67 In the event that joining lines creates a line which exceeds the width
68 of the screen, you can break the line by typing i and pressing RETURN.
73 Substituting combines the delete command and the insert command into a
76 #'s' SUBSTITUTE for # characters
77 #'S' SUBSTITUTE for # whole lines
80 In order to substitute text you have to know how much text you want to
81 delete. Consider the following examples:
83 '3''s' SUBSTITUTE the next 3 characters for what will be typed
84 '7''s' SUBSTITUTE the next 7 characters for what will be typed
86 >>> Change the SAMPLE DEFINITION below. To do this:
87 >>> move the cursor to the T in TWO
89 >>> type FOUR then press ESC
91 SAMPLE DEFINITION: A string quartet is defined to be
92 a group of TWO musicians.
97 The 'r' and 'R' commands allow you to directly type over existing text.
99 'r' REPLACE character (NO need to press ESC)
100 'R' enter over-type mode
102 >>> Correct each of the TYPOs on the sample line below. To do this:
103 >>> move the cursor to the misspelled character
105 >>> type the correct character
107 SAMPLE: maintanence conveniance complience applience dilagent
109 >>> Use the over-type command, 'R' , on the sample line above.
110 >>> Type 'R' then type the name of a local restaurant. Press ESC.
115 The change command combines insertion, deletion, and the movement
116 commands. (Recall that the movement commands were taught in tutorial
117 #2.) Change is probably more useful than replace or substitute. The
118 general form of the change command is:
120 'c'movement CHANGE to where the movement command specifies
122 Consider the following examples:
124 'c''w' CHANGE to the beginning of the next WORD
125 'c''$' CHANGE to the end of the line
126 'c'')' CHANGE to the beginning of the next sentence
127 'c''t'e CHANGE 'TIL the next e
128 'c''3''w' CHANGE the next 3 WORDS
129 'c''c' CHANGE a line (cc is a special case of the c command)
130 'c''}' CHANGE to the end of the paragraph
132 >>> Follow these steps:
133 >>> 1. move to the desired location in the practice paragraph below
134 >>> 2. type 'c''w' (change to the beginning of the next WORD)
135 >>> 3. type your name
138 PRACTICE here. Now is the time for all good users to learn the
139 editor. The quick red fox jumped over the seven lazy fish. Now
140 is the time for all good users to learn the editor. The quick
141 brown computer jumped over the seven lazy users. END PRACTICE
143 >>> Experiment by using a variety of options for step #2. Try
144 >>> out 'c''$' 'c'')' 'c''t'e 'c''3''w' 'c''c' 'c''}' on the practice paragraph above.
146 Note that the change command follows the same pattern as the delete
147 and yank commands which were explored in tutorial #3.
153 'o' OPEN a line below the cursor
154 'O' OPEN a line above the cursor
156 'i' INSERT starting before the cursor
157 'I' INSERT at the beginning of the line
159 'a' APPEND starting after the cursor
160 'A' APPEND at the end of the line
162 ESC ESCAPE from insert mode
166 #'s' SUBSTITUTE for # characters
167 #'S' SUBSTITUTE for # whole lines
169 'r' REPLACE character (NO need to press ESC)
170 'R' enter over-type mode
172 'c'movement CHANGE to where the movement commands specifies
173 (e.g. 'c''3''w' 'c''$' 'c''c' )
176 These commands should improve your ability to insert text efficiently.
177 The next tutorials deal with advanced commands and tricks which can
178 further speed up your editing.
180 Copyright (c) 1992 Jill Kliger and Wesley Craig. All Rights Reserved.