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