home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / ed / e5 < prev    next >
Encoding:
Text File  |  1975-06-26  |  4.4 KB  |  235 lines

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