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