BSD 3 development
[unix-history] / usr / doc / edtut / e5
CommitLineData
8340f87c
BJ
1.SH
2Change and Insert \- ``c'' and ``i''
3.PP
4This section discusses the
5.ul
6change
7command
8.P1
9c
10.P2
11which is used to change
12or replace a group of one or more lines,
13and the
14.ul
15insert
16command
17.P1
18i
19.P2
20which is used for inserting a group of one or more lines.
21.PP
22``Change'', written as
23.P1
24c
25.P2
26is used to replace a number of lines with different lines, which
27are typed in at the terminal.
28For example,
29to change lines
30.UL .+1
31through
32.UL $
33to something else, type
34.P1
35\&.+1,$c
36\&. . . \fItype the lines of text you want here\fP . . .
37\*.
38.P2
39The lines you type between the
40.UL c
41command and
42the
43.UL .
44will take the place of the original lines between
45start line and end line.
46This is most useful in replacing a line
47or several lines which have errors in them.
48.PP
49If only one line is specified in the
50.UL c
51command, then just
52that line is replaced.
53(You can type in as many replacement lines as you like.)
54Notice
55the use of
56.UL .
57to end the
58input \- this works just like the
59.UL .
60in the append command
61and must appear by itself on a new line.
62If no line number is given, line dot is replaced.
63The value of dot is set to the last line you typed in.
64.PP
65``Insert'' is similar to append \- for instance
66.P1
67/string/i
68\&. . . \fItype the lines to be inserted here\fP . . .
69\*.
70.P2
71will insert the given text
72.ul
73before
74the next line that contains ``string''.
75The text between
76.UL i
77and
78.UL .
79is
80.ul
81inserted before
82the specified line.
83If no line number is specified dot is used.
84Dot is set to the last line inserted.
85.SH
86Exercise 7:
87.PP
88``Change'' is rather like a combination of
89delete followed by insert.
90Experiment to verify that
91.P1
92\fIstart, end\fP d
93i
94.ul
95\&. . . text . . .
96\*.
97.P2
98is almost the same as
99.P1
100\fIstart, end\fP c
101.ul
102\&. . . text . . .
103\*.
104.P2
105These are not
106.ul
107precisely
108the same
109if line
110.UL $
111gets deleted.
112Check this out.
113What is dot?
114.PP
115Experiment with
116.UL a
117and
118.UL i ,
119to see that they are
120similar, but not the same.
121You will observe that
122.P1
123\fIline\(hynumber\fP a
124\&. . . \fItext\fP . . .
125\*.
126.P2
127appends
128.ul
129after
130the given line, while
131.P1
132\fIline\(hynumber\fP i
133\&. . . \fItext\fP . . .
134\*.
135.P2
136inserts
137.ul
138before
139it.
140Observe that if no line number is given,
141.UL i
142inserts before line dot, while
143.UL a
144appends
145after line dot.
146.SH
147Moving text around: the ``m'' command
148.PP
149The move command
150.UL m
151is used for cutting and pasting \-
152it lets you move a group of lines
153from one place to another in the buffer.
154Suppose you want to put the first three lines of the buffer at the end instead.
155You could do it by saying:
156.P1
1571,3w temp
158$r temp
1591,3d
160.P2
161(Do you see why?)
162but you can do it a lot easier with the
163.UL m
164command:
165.P1
1661,3m$
167.P2
168The general case is
169.P1
170\fIstart line, end line\fP m \fIafter this line\fP
171.P2
172Notice that there is a third line to be specified \-
173the place where the moved stuff gets put.
174Of course the lines to be moved can be specified
175by context searches;
176if you had
177.P1
178First paragraph
179\&. . .
180end of first paragraph.
181Second paragraph
182\&. . .
183end of second paragraph.
184.P2
185you could reverse the two paragraphs like this:
186.P1
187/Second/,/end of second/m/First/\-1
188.P2
189Notice the
190.UL \-1 :
191the moved text goes
192.ul
193after
194the line mentioned.
195Dot gets set to the last line moved.
196.SH
197The global commands ``g'' and ``v''
198.PP
199The
200.ul
201global
202command
203.UL g
204is used to execute one or more
205.ul
206ed
207commands on all those lines in the buffer
208that match some specified string.
209For example
210.P1
211g/peling/p
212.P2
213prints all lines that contain
214.UL peling .
215More usefully,
216.P1
217g/peling/s//pelling/gp
218.P2
219makes the substitution everywhere on the line,
220then prints each corrected line.
221Compare this to
222.P1
2231,$s/peling/pelling/gp
224.P2
225which only prints the last line substituted.
226Another subtle difference is that
227the
228.UL g
229command
230does not give a
231.UL ?
232if
233.UL peling
234is not found
235where the
236.UL s
237command will.
238.PP
239There may be several commands
240(including
241.UL a ,
242.UL c ,
243.UL i ,
244.UL r ,
245.UL w ,
246but not
247.UL g );
248in that case,
249every line except the last must end with a backslash
250.UL \e :
251.P1
252g/xxx/\*.-1s/abc/def/\\
253\&\*.+2s/ghi/jkl/\\
254\&\*.-2,\*.p
255.P2
256makes changes in the lines before and after each line
257that contains
258.UL xxx ,
259then prints all three lines.
260.PP
261The
262.UL v
263command is the same as
264.UL g ,
265except that the commands are executed on every line
266that does
267.ul
268not
269match the string following
270.UL v :
271.P1
272v/ /d
273.P2
274deletes every line that does not contain a blank.