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

  1. .TL
  2. A Tutorial Introduction to the \s-2UNIX\s+2 Text Editor
  3. .sp
  4. .AU
  5. B. W. Kernighan
  6. .sp
  7. .AI
  8. Bell Laboratories, Murray Hill, N. J.
  9. .nr PS 9
  10. .nr VS 11
  11. .if t .2C
  12. .H1
  13. Introduction
  14. .H2
  15. .PG
  16. .ul
  17. Ed
  18. is a ``text editor'', that is, an interactive program
  19. for creating and modifying ``text'',
  20. using directions provided by a user at
  21. a terminal.
  22. The text is often a document
  23. like this one,
  24. or a program
  25. or perhaps data for a program.
  26. .PG
  27. This introduction is meant to simplify learning
  28. .ul
  29. ed.
  30. The recommended way to learn
  31. .ul
  32. ed
  33. is to read this document,
  34. simultaneously using
  35. .ul
  36. ed
  37. to follow the examples,
  38. then to read the description in section I of the
  39. .S1
  40. UNIX
  41. .S2
  42. manual, all the while
  43. experimenting with
  44. .ul
  45. ed.
  46. (Solicitation of advice from experienced users is also useful.)
  47. .PG
  48. Do the exercises!
  49. They cover material not completely discussed
  50. in the actual text.
  51. An appendix summarizes the commands.
  52. .H1
  53. Disclaimer
  54. .H2
  55. .PG
  56. This is an introduction and a tutorial.
  57. For this reason, no attempt is made to
  58. cover more than a part of the facilities that
  59. .ul
  60. ed
  61. offers
  62. (although this fraction includes the most useful and frequently used
  63. parts).
  64. Also,
  65. there is not enough space to explain basic
  66. .S1
  67. UNIX
  68. .S2
  69. procedures.
  70. We will assume that you know how to log on to
  71. .S1
  72. UNIX,
  73. .S2
  74. and that you have at least a vague understanding
  75. of what a file is.
  76. .PG
  77. You must also know what character to type as the end-of-line
  78. on your particular terminal.
  79. This is a ``newline'' on Model 37 Teletypes,
  80. and ``return'' on most others.
  81. Throughout, we will refer to this character,
  82. whatever it is,
  83. as ``newline''.
  84. .H1
  85. Getting Started
  86. .H2
  87. .PG
  88. We'll assume that you have logged in to
  89. .S1
  90. UNIX
  91. .S2
  92. and it has just said ``%''.
  93. The
  94. easiest way to get
  95. .ul
  96. ed
  97. is to type
  98. .X1
  99. ed    (followed by a newline)
  100. .X2
  101. You are now ready to go \(mi
  102. .ul
  103. ed
  104. is waiting for you to tell it what to do.
  105. .H1
  106. Creating Text \(mi the Append command ``a''
  107. .H2
  108. .PG
  109. As our first problem, suppose we want to create some text
  110. starting from scratch.
  111. Perhaps we are typing the very first
  112. draft of a paper; clearly it will have to start
  113. somewhere, and undergo modifications later.
  114. This section will show how to get some text in, just to
  115. get started.
  116. Later we'll talk about how to change it.
  117. .PG
  118. When
  119. .ul
  120. ed
  121. is first started, it is rather like working
  122. with a blank piece of paper \(mi there is no text
  123. or information present.
  124. This must be supplied by the person using
  125. .ul
  126. ed;
  127. it is usually done
  128. by typing in the text, or by reading it into
  129. .ul
  130. ed
  131. from a
  132. file.
  133. We will start by typing in some text, and return shortly to how to
  134. read files.
  135. .PG
  136. First a bit of terminology.
  137. In
  138. .ul
  139. ed
  140. jargon, the text being
  141. worked on is said to be ``kept in a buffer.''
  142. Think of the
  143. buffer as a work space, if you like, or simply as the information
  144. that you are going to be editing.
  145. In effect the buffer is like the
  146. piece of paper, on which we will write things, then change some
  147. of them, and finally file the whole thing away for another day.
  148. .PG
  149. The user tells
  150. .ul
  151. ed
  152. what to do to his text
  153. by typing instructions called ``commands.''
  154. Most
  155. commands consist of a single letter,
  156. which must be typed in lower case.
  157. Each command is typed
  158. on a separate line.
  159. (Sometimes the command is preceded by information
  160. about what line or lines of text are to be affected \(mi
  161. we will discuss these shortly.)
  162. .ul
  163. Ed
  164. makes no response
  165. to most commands \(mi there is no prompting
  166. or typing of messages like ``ready''.
  167. (This silence is preferred
  168. by experienced users, but sometimes a hangup for beginners.)
  169. .PG
  170. The first command is
  171. .ul
  172. append,
  173. written as the letter
  174. .X1
  175. a
  176. .X2
  177. all
  178. by itself.
  179. It means ``append (or add) text lines to the buffer,
  180. as I type them in.''
  181. Appending is rather like
  182. writing fresh material on a piece of paper.
  183. .PG
  184. So to enter lines of text into the buffer,
  185. we just type an ``a'' followed by a
  186. newline, followed by the lines of text we want, like this:
  187. .X1
  188. a
  189. Now is the time
  190. for all good men
  191. to come to the aid of their party.
  192. .li
  193. \fB.\fR
  194. .X2
  195. .PG
  196. The only way to stop appending is to type a
  197. line that contains only a period.
  198. The ``\*.'' is used
  199. to tell
  200. .ul
  201. ed
  202. that we have finished appending.
  203. (Even experienced users forget that terminating ``\*.''
  204. sometimes.
  205. If
  206. .ul
  207. ed
  208. seems to be ignoring you,
  209. type an extra line with just ``\*.'' on it.
  210. You may then find you've added some garbage lines
  211. to your text, which you'll have to take out later.)
  212. .PG
  213. After the append command has been done, the buffer will
  214. contain the three lines
  215. .X1
  216. Now is the time
  217. for all good men
  218. to come to the aid of their party.
  219. .X2
  220. The ``a'' and ``\*.'' aren't there, because they are
  221. not text.
  222. .PG
  223. To add more text to what we already have,
  224. just issue another ``a'' command, and continue typing.
  225. .H1
  226. Error Messages \(mi ``?''
  227. .H2
  228. .PG
  229. If at any time you make an error in the commands you type to
  230. .ul
  231. ed,
  232. it will tell you by typing
  233. .X1
  234. ?
  235. .X2
  236. This is about as cryptic as it can be,
  237. but with practice, you can usually
  238. figure out how you goofed.
  239.