.H1 Change and Insert \(mi ``c'' and ``i'' .H2 .PG This section discusses the .ul change command .X1 c .X2 which is used to change or replace a group of one or more lines, and the .ul insert command .X1 i .X2 which is used for inserting a group of one or more lines. .PG ``Change'', written as .X1 c .X2 is used to replace a number of lines with different lines, which are typed in at the terminal. For example, to change lines ``\*.+1'' through ``$'' to something else, type .X1 .+1,$c . . . \fItype the lines of text you want here\fP . . . \fB.\fR .X2 The lines you type between the ``c'' command and the ``\*.'' will take the place of the original lines between start line and end line. This is most useful in replacing a line or several lines which have errors in them. .PG If only one line is specified in the ``c'' command, then just that line is replaced. (You can type in as many replacement lines as you like.) Notice the use of ``\*.'' to end the input \(mi this works just like the ``\*.'' in the append command and must appear by itself on a new line. If no line number is given, line dot is replaced. The value of dot is set to the last line you typed in. .PG ``Insert'' is similar to append \(mi for instance .X1 /string/i .li . . . \fItype the lines to be inserted here\fP . . . .li \fB.\fR .X2 will insert the given text .ul before the next line that contains ``string''. The text between ``i'' and ``\*.'' is .ul inserted before the specified line. If no line number is specified dot is used. Dot is set to the last line inserted. .H1 Exercise 7: .H2 .PG ``Change'' is rather like a combination of delete followed by insert. Experiment to verify that .X1 \fIstart, end\fP d i .ul . . . text . . . .li \fB.\fR .X2 is almost the same as .X1 \fIstart, end\fP c .ul . . . text . . . .li \fB.\fR .X2 These are not .ul precisely the same if line ``$'' gets deleted. Check this out. What is dot? .PG Experiment with ``a'' and ``i'', to see that they are similar, but not the same. You will observe that .X1 \fIline-number\fP a .li . . . \fItext\fP . . . .li \fB.\fR .X2 appends .ul after the given line, while .X1 \fIline-number\fP i .li . . . \fItext\fP . . . .li \fB.\fR .X2 inserts .ul before it. Observe that if no line number is given, ``i'' inserts before line dot, while ``a'' appends after line dot. .H1 Moving text around: the ``m'' command .H2 .PG The move command ``m'' is used for cutting and pasting \(mi it lets you move a group of lines from one place to another in the buffer. Suppose we want to put the first three lines of the buffer at the end instead. We could do it by saying: .X1 1,3w temp $r temp 1,3d .X2 (Do you see why?) but we can do it a lot easier with the ``m'' command: .X1 1,3m$ .X2 The general case is .X1 \fIstart line, end line\fP m \fIafter this line\fP .X2 Notice that there is a third line to be specified \(mi the place where the moved stuff gets put. Of course the lines to be moved can be specified by context searches; if we had .X1 First paragraph .li . . . end of first paragraph. Second paragraph .li . . . end of second paragraph. .X2 we could reverse the two paragraphs like this: .X1 /Second/,/second/m/First/\(mi1 .X2 Notice the ``\(mi1'' \(mi the moved text goes .ul after the line mentioned. Dot gets set to the last line moved. .H1 The global commands ``g'' and ``v'' .H2 .PG The .ul global command ``g'' is used to execute one or more .ul ed commands on all those lines in the buffer that match some specified string. For example .X1 g/peling/p .X2 prints all lines that contain ``peling''. More usefully, .X1 g/peling/s//pelling/gp .X2 makes the substitution everywhere on the line, then prints each corrected line. Compare this to .X1 1,$s/peling/pelling/gp .X2 which only prints the last line substituted. Another subtle difference is that the ``g'' command does not give a ``?'' if ``peling'' is not found where the ``s'' command will. .PG There may be several commands (including ``a'', ``c'' ``i'' ``r'', ``w'', but not ``g''); in that case, every line except the last must end with a backslash ``\\'': .X1 g/xxx/\*.-1s/abc/def/\\ .li \fB.\fR+2s/ghi/jkl/\\ .li \fB.\fR-2,\fB.\fRp .X2 makes changes in the lines before and after each line that contains ``xxx'', then prints all three lines. .PG The ``v'' command is the same as ``g'', except that the commands are executed on every line that does .ul not match the string following ``v'': .X1 v/ /d .X2 deletes every line that does not contain a blank.