xref: /original-bsd/bin/ed/USD.doc/tutorial/e5 (revision e79a6a26)
%sccs.include.proprietary.roff%

@(#)e5 8.1 (Berkeley) 06/08/93

Change and Insert - ``c'' and ``i''

This section discusses the .ul change command

1 c

2 which is used to change or replace a group of one or more lines, and the .ul insert command

1 i

2 which is used for inserting a group of one or more lines.

``Change'', written as

1 c

2 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

1 .+1,$c . . . type the lines of text you want here . . . \*.

2 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.

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 - 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.

``Insert'' is similar to append - for instance

1 /string/i . . . type the lines to be inserted here . . . \*.

2 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.

Exercise 7:

``Change'' is rather like a combination of delete followed by insert. Experiment to verify that

1 start, end d i .ul . . . text . . . \*.

2 is almost the same as

1 start, end c .ul . . . text . . . \*.

2 These are not .ul precisely the same if line $ gets deleted. Check this out. What is dot?

Experiment with a and i , to see that they are similar, but not the same. You will observe that

1 line\(hynumber a . . . text . . . \*.

2 appends .ul after the given line, while

1 line\(hynumber i . . . text . . . \*.

2 inserts .ul before it. Observe that if no line number is given, i inserts before line dot, while a appends after line dot.

Moving text around: the ``m'' command

The move command m is used for cutting and pasting - it lets you move a group of lines from one place to another in the buffer. Suppose you want to put the first three lines of the buffer at the end instead. You could do it by saying:

1 1,3w temp $r temp 1,3d

2 (Do you see why?) but you can do it a lot easier with the m command:

1 1,3m$

2 The general case is

1 start line, end line m after this line

2 Notice that there is a third line to be specified - the place where the moved stuff gets put. Of course the lines to be moved can be specified by context searches; if you had

1 First paragraph . . . end of first paragraph. Second paragraph . . . end of second paragraph.

2 you could reverse the two paragraphs like this:

1 /Second/,/end of second/m/First/-1

2 Notice the -1 : the moved text goes .ul after the line mentioned. Dot gets set to the last line moved.

The global commands ``g'' and ``v''

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

1 g/peling/p

2 prints all lines that contain peling . More usefully,

1 g/peling/s//pelling/gp

2 makes the substitution everywhere on the line, then prints each corrected line. Compare this to

1 1,$s/peling/pelling/gp

2 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.

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 \e :

1 g/xxx/\*.-1s/abc/def/\e \*.+2s/ghi/jkl/\e \*.-2,\*.p

2 makes changes in the lines before and after each line that contains xxx , then prints all three lines.

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 :

1 v/ /d

2 deletes every line that does not contain a blank.