summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/etc/viper-tut/4inserting
blob: ab2c6a5e2f9cb4d0f6d0d0f957b476b23253d775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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.