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