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

  1. .th ED I 1/15/73
  2. .if t .ds q \(aa
  3. .if n .ds q '
  4. .sh NAME
  5. ed \*- text editor
  6. .sh SYNOPSIS
  7. .bd ed
  8. [
  9. .bd \*-
  10. ] [ name ]
  11. .sh DESCRIPTION
  12. .it Ed
  13. is the standard text editor.
  14. .s3
  15. If a
  16. .it name
  17. argument is given,
  18. .it ed
  19. simulates an
  20. .it e
  21. command (see below)\| on the named file; that is to say,
  22. the file is read into
  23. .it ed's
  24. buffer so that it can be edited.
  25. The optional
  26. .bd \*-
  27. suppresses the printing
  28. of character counts by
  29. .it e,
  30. .it r,
  31. and
  32. .it w
  33. commands.
  34. .s3
  35. .it Ed
  36. operates on a copy of any file it is editing; changes made
  37. in the copy have no effect on the file until a \fIw\fR (write)\|
  38. command is given.
  39. The copy of the text being edited resides
  40. in a temporary file called the 
  41. .it buffer.
  42. There is only
  43. one buffer.
  44. .s3
  45. Commands to
  46. .it ed
  47. have a simple and regular structure: zero or
  48. more
  49. .it addresses
  50. followed by a single character
  51. .it command,
  52. possibly
  53. followed by parameters to the command.
  54. These addresses specify one or more lines in the buffer.
  55. Every command which requires addresses has default addresses,
  56. so that the addresses can often be omitted.
  57. .s3
  58. In general, only one command may appear on a line.
  59. Certain commands allow the input of text.
  60. This text is placed in the appropriate place in the buffer.
  61. While
  62. .it ed
  63. is accepting text, it is said
  64. to be in
  65. \fIinput mode.\fR
  66. In this mode, no commands are recognized;
  67. all input is merely collected.
  68. Input mode is left by typing a period `\fB.\fR' alone at the
  69. beginning of a line.
  70. .s3
  71. .it Ed
  72. supports a limited form of
  73. .it "regular expression"
  74. notation.
  75. A regular expression specifies
  76. a set of strings of characters.
  77. A member of this set of strings is said to be
  78. .it matched
  79. by the regular expression.
  80. The regular expressions allowed by
  81. .it ed
  82. are constructed as follows:
  83. .s3
  84. .lp +3 3
  85. 1.    An ordinary character (not one of those discussed below)\|
  86. is a regular expression and matches that character.
  87. .s3
  88. .lp +3 3
  89. 2.    A circumflex `^' at the beginning of a regular expression
  90. matches the empty string at the beginning of a line.
  91. .s3
  92. .lp +3 3
  93. 3.    A currency symbol `$' at the end of a regular expression
  94. matches the null character at the end of a line.
  95. .s3
  96. .lp +3 3
  97. 4.    A period `\fB.\fR' matches any character except a new-line character.
  98. .s3
  99. .lp +3 3
  100. 5.    A regular expression followed by an asterisk `*'
  101. matches any number of adjacent occurrences (including zero)\|
  102. of the regular expression it follows.
  103. .s3
  104. .lp +3 3
  105. 6.    A string of characters enclosed in square brackets
  106. `[ ]' matches any character in the string but no others.
  107. If, however, the first character of the string is a circumflex
  108. `^' the regular expression matches any character except new-line
  109. and the characters in the string.
  110. .s3
  111. .lp +3 3
  112. 7.    The concatenation of regular expressions is a regular
  113. expression which matches the concatenation of the strings
  114. matched by the components of the regular expression.
  115. .s3
  116. .lp +3 3
  117. 8.    A regular expression enclosed between
  118. the sequences
  119. `\\(' and `\\)'is identical to the
  120. unadorned expression; the construction has side effects discussed
  121. under the
  122. .it s
  123. command.
  124. .s3
  125. .lp +3 3
  126. 9.    The null regular expression standing alone
  127. is equivalent to the last regular expression encountered.
  128. .s3
  129. .i0
  130. Regular expressions are used in addresses to specify
  131. lines and in one command
  132. (see
  133. .it s
  134. below)\|
  135. to specify a portion of a line which is to be replaced.
  136. If it is desired to use one of
  137. the regular expression metacharacters as an ordinary
  138. character, that character may be preceded by `\\'.
  139. This also applies to the character bounding the regular
  140. expression (often `/')\| and to `\\' itself.
  141. .s3
  142. To understand addressing in
  143. .it ed
  144. it is necessary to know that at any time there is a
  145. \fIcurrent line.\fR
  146. Generally speaking, the current line is
  147. the last line affected by a command; however,
  148. the exact effect on the current line
  149. is discussed under the description of
  150. the command.
  151. Addresses are constructed as follows.
  152. .s3
  153. .lp +6 3
  154. 1.    The character `\fB.\fR' addresses the current line.
  155. .s3
  156. .lp +6 3
  157. 2.    The character `$' addresses the last line of the buffer.
  158. .s3
  159. .lp +6 3
  160. 3.    A decimal number
  161. .it n
  162. addresses the
  163. \fIn\fR-th
  164. line of the buffer.
  165. .s3
  166. .lp +6 3
  167. 4.    `\*q\fIx\fR' addresses the line marked with the
  168. mark name character \fIx\fR,
  169. which must be a lower-case letter.
  170. Lines are marked with the
  171. .it k
  172. command described below.
  173. .s3
  174. .lp +6 3
  175. 5.    A regular expression enclosed in slashes `/' addresses
  176. the first line found by searching toward the end of the
  177. buffer and stopping at the first line containing a
  178. string matching the regular expression.
  179. If necessary the search wraps around to the beginning of the
  180. buffer.
  181. .s3
  182. .lp +6 3
  183. 6.    A regular expression enclosed in queries `?' addresses
  184. the first line found by searching toward the beginning of
  185. the buffer and stopping at the first line containing
  186. a string matching the regular expression.
  187. If necessary
  188. the search wraps around to the end of the buffer.
  189. .s3
  190. .lp +6 3
  191. 7.    An address followed by a plus sign `+'
  192. or a minus sign `\*-' followed by a decimal number specifies that address plus
  193. (resp. minus)\| the indicated number of lines.
  194. The plus sign may be omitted.
  195. .s3
  196. .lp +6 3
  197. 8.    If an address begins with `+' or `\-'
  198. the addition or subtraction is taken with respect to the current line;
  199. e.g. `\-5' is understood to mean `\fB.\fR\-5'.
  200. .s3
  201. .lp +6 3
  202. 9.    If an address ends with `+' or `\-',
  203. then 1 is added (resp. subtracted).
  204. As a consequence of this rule and rule 8,
  205. the address `\-' refers to the line before the current line.
  206. Moreover,
  207. trailing
  208. `+' and `\-' characters
  209. have cumulative effect, so `\-\-' refers to the current
  210. line less 2.
  211. .s3
  212. .lp +6 3
  213. 10.    To maintain compatibility with earlier version of the editor,
  214. the character `^' in addresses is entirely
  215. equivalent to `\-'.
  216. .s3
  217. .i0
  218. Commands may require zero, one, or two addresses.
  219. Commands which require no addresses regard the presence
  220. of an address as an error.
  221. Commands which accept one or two addresses
  222. assume default addresses when insufficient are given.
  223. If more addresses are given than such a command requires,
  224. the last one or two (depending on what is accepted)\| are used.
  225. .s3
  226. Addresses are separated from each other typically by a comma
  227. `\fB,\fR'.
  228. They may also be separated by a semicolon
  229. `\fB;\fR'.
  230. In this case the current line `\fB.\fR' is set to
  231. the previous address before the next address is interpreted.
  232. This feature can be used to determine the starting
  233. line for forward and backward searches (`/', `?')\|.
  234. The second address of any two-address sequence
  235. must correspond to a line following the line corresponding to the first address.
  236. .s3
  237. In the following list of
  238. .it ed
  239. commands, the default addresses
  240. are shown in parentheses.
  241. The parentheses are not part of
  242. the address, but are used to show that the given addresses are
  243. the default.
  244. .s3
  245. As mentioned, it is generally illegal for more than one
  246. command to appear on a line.
  247. However, any command may be suffixed by `p'
  248. or by `l', in which case
  249. the current line is either
  250. printed or listed respectively
  251. in the way discussed below.
  252. .s3
  253. .lp +5 5
  254. ( \fB. \fR)\|a
  255. .lp +5 5
  256. <text>
  257. .lp +5 5
  258. .li
  259. \fB.\fR
  260. .lp +5 5
  261.     The append command reads the given text
  262. and appends it after the addressed line.
  263. `\fB.\fR' is left
  264. on the last line input, if there
  265. were any, otherwise at the addressed line.
  266. Address `0' is legal for this command; text is placed
  267. at the beginning of the buffer.
  268. .s3
  269. .lp +5 5
  270. ( \fB. \fR, \fB. \fR)\|c
  271. .lp +5 5
  272. <text>
  273. .lp +5 5
  274. .li
  275. \fB.\fR
  276. .lp +5 5
  277.     The change
  278. command deletes the addressed lines, then accepts input
  279. text which replaces these lines.
  280. `\fB.\fR' is left at the last line input; if there were none,
  281. it is left at the first line not deleted.
  282. .s3
  283. .lp +5 5
  284. ( \fB. \fR, \fB. \fR)\| d
  285. .br
  286. The delete command deletes the addressed lines from the buffer.
  287. The line originally after the last line deleted becomes the current line;
  288. if the lines deleted were originally at the end,
  289. the new last line becomes the current line.
  290. .s3
  291. .lp +5 5
  292. e filename
  293. .br
  294. The edit
  295. command causes the entire contents of the buffer to be deleted,
  296. and then the named file to be read in.
  297. `\fB.\fR' is set to the last line of the buffer.
  298. The number of characters read is typed.
  299. `filename' is remembered for possible use as a default file name
  300. in a subsequent
  301. .it r
  302. or
  303. .it w
  304. command.
  305. .s3
  306. .lp +5 5
  307. f filename
  308. .br
  309. The filename command prints the currently remembered file name.
  310. If `filename' is given,
  311. the currently remembered file name is changed to `filename'.
  312. .s3
  313. .lp +5 5
  314. (1,$)\|g/regular expression/command list
  315. .br
  316. In the global
  317. command, the first step is to mark every line which matches
  318. the given regular expression.
  319. Then for every such line, the
  320. given command list is executed with `\fB.\fR' initially set to that line.
  321. A single command or the first of multiple commands
  322. appears on the same line with the global command.
  323. All lines of a multi-line list except the last line must be ended with `\\'.
  324. .it A,
  325. .it i,
  326. and
  327. .it c
  328. commands and associated input are permitted;
  329. the `\fB.\fR' terminating input mode may be omitted if it would be on the
  330. last line of the command list.
  331. The (global)\| commands,
  332. .it g,
  333. and
  334. .it v,
  335. are not permitted in the command list.
  336. .s3
  337. .lp +5 5
  338. ( \fB. \fR)\|i
  339. .lp +5 5
  340. <text>
  341. .lp +5 5
  342. .li
  343. \fB.\fR
  344. .br
  345. This command inserts the given text before the addressed line.
  346. `\fB.\fR' is left at the last line input; if there were none,
  347. at the addressed line.
  348. This command differs from the
  349. .it a
  350. command only in the placement of the
  351. text.
  352. .s3
  353. .lp +5 5
  354. ( \fB. \fR)\|k\fIx\fR
  355. .br
  356. The mark command marks the addressed line with
  357. name
  358. .it x,
  359. which must be a lower-case letter.
  360. The address form `\*q\fIx\fR' then addresses this line.
  361. .s3
  362. .lp +5 5
  363. ( \fB. \fR, \fB. \fR)\|l
  364. .br
  365. The list command
  366. prints the addressed lines in an unambiguous way:
  367. non-graphic characters are
  368. printed in octal,
  369. and long lines are folded.
  370. An
  371. .it l
  372. command may follow any other on the same line.
  373. .s3
  374. .lp +5 5
  375. ( \fB. \fR, \fB. \fR)\|m\fIa\fR
  376. .br
  377. The move command repositions the addressed lines after the line
  378. addressed by
  379. .it a.
  380. The last of the moved lines becomes the current line.
  381. .s3
  382. .lp +5 5
  383. ( \fB. \fR, \fB. \fR)\|p
  384. .br
  385. The print command prints the addressed lines.
  386. `\fB.\fR'
  387. is left at the last line printed.
  388. The
  389. .it p
  390. command
  391. may
  392. be placed on the same line after any command.
  393. .s3
  394. .lp +5 5
  395. q
  396. .br
  397. The quit command causes
  398. .it ed
  399. to exit.
  400. No automatic write
  401. of a file is done.
  402. .s3
  403. .lp +5 5
  404. ($)\|r filename
  405. .br
  406. The read command
  407. reads in the given file after the addressed line.
  408. If no file name is given,
  409. the remembered file name, if any, is used
  410. (see
  411. .it e
  412. and
  413. .it f
  414. commands)\|.
  415. The remembered file name is not changed unless
  416. `filename' is the very first file name
  417. mentioned.
  418. Address `0' is legal for
  419. .it r
  420. and causes the
  421. file to be read at the beginning of the buffer.
  422. If the read is successful, the number of characters
  423. read is typed.
  424. `\fB.\fR' is left at the last line read in from the file.
  425. .s3
  426. .lp +5 5
  427. ( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/         or,
  428. .lp +5 5
  429. ( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/g
  430. .br
  431. The substitute command searches each addressed
  432. line for an occurrence of the specified regular expression.
  433. On each line in which a match is found,
  434. all matched strings are replaced by the replacement specified,
  435. if the global replacement indicator `g' appears after the command.
  436. If the global indicator does not appear, only the first occurrence
  437. of the matched string is replaced.
  438. It is an error for the substitution to fail on all addressed lines.
  439. Any character other than space or new-line
  440. may be used instead of `/' to delimit the regular expression
  441. and the replacement.
  442. `\fB.\fR' is left at the last line substituted.
  443. .s2
  444. An ampersand `&' appearing in the replacement
  445. is replaced by the string matching the regular expression.
  446. The special meaning of `&' in this context may be
  447. suppressed by preceding it by `\\'.
  448. As a more general feature,
  449. the characters
  450. `\\\fIn\fR',
  451. where
  452. .it n
  453. is a digit,
  454. are replaced by the text matched by the
  455. \fIn\fR-th
  456. regular subexpression
  457. enclosed between `\\(' and `\\)'.
  458. When
  459. nested, parenthesized subexpressions
  460. are present,
  461. .it n
  462. is determined by counting occurrences of `\\(' starting from the left.
  463. .s2
  464. Lines may be split by substituting new-line characters into them.
  465. The new-line in the
  466. replacement string
  467. must be escaped by preceding it by `\\'.
  468. .s3
  469. .lp +5 5
  470. ( \fB.\fR , \fB.\fR ) t \fIa\fR
  471. .br
  472. This command acts just like the
  473. .it m
  474. command, except that a copy of the addressed lines is placed
  475. after address
  476. .it a
  477. (which may be 0).
  478. `\fB.\fR' is left on the last line of the copy.
  479. .s3
  480. .lp +5 5
  481. (1,$)\|v/regular expression/command list
  482. .br
  483. This command is the same as the global command
  484. except that the command list is executed
  485. with `\fB.\fR' initially set to every line
  486. .it except
  487. those
  488. matching the regular expression.
  489. .s3
  490. .lp +5 5
  491. (1,$)\|w filename
  492. .br
  493. The write command writes the addressed lines onto
  494. the given file.
  495. If the file does not exist,
  496. it is created mode 666 (readable and writeable by everyone)\|.
  497. The remembered file name is
  498. .it not
  499. changed unless
  500. `filename' is the very first file name mentioned.
  501. If no file name is given,
  502. the remembered file name, if any, is used
  503. (see
  504. .it e
  505. and
  506. .it f
  507. commands)\|.
  508. `\fB.\fR' is unchanged.
  509. If the command is successful, the number of characters written is
  510. typed.
  511. .s3
  512. .lp +5 5
  513. ($)\|=
  514. .br
  515. The line number of the addressed line is typed.
  516. `\fB.\fR' is unchanged by this command.
  517. .s3
  518. .lp +5 5
  519. !UNIX command
  520. .br
  521. The remainder of the line after the `!' is sent
  522. to UNIX to be interpreted as a command.
  523. `\fB.\fR' is unchanged.
  524. .s3
  525. .lp +5 5
  526. ( \fB.\fR+1 )\|<newline>
  527. .br
  528. An address alone on a line causes the addressed line to be printed.
  529. A blank line alone is equivalent to `.+1p'; it is useful
  530. for stepping through text.
  531. .s3
  532. .i0
  533. If an interrupt signal (ASCII DEL)\| is sent,
  534. .it ed
  535. prints a `?' and returns to its command level.
  536. .s3
  537. Some size limitations:
  538. 512 characters per line,
  539. 256 characters per global command list,
  540. 64 characters per file name,
  541. and 128K characters in the temporary file.
  542. The limit on the number of lines depends on the amount of core:
  543. each line takes 1 word.
  544. .sh FILES
  545. /tmp/#, temporary;
  546. `#' is the process number (in octal).
  547. .sh DIAGNOSTICS
  548. `?' for
  549. errors in commands;
  550. `TMP' for temporary file overflow.
  551. .sh "SEE ALSO"
  552. A Tutorial Introduction to the ED Text Editor
  553. (B. W. Kernighan)
  554. .sh BUGS
  555. The
  556. .it s
  557. command causes all marks
  558. to be lost on lines changed.
  559.