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