annotate ed.1 @ 0:1493bea5ac22

Initial version of the standalone heirloom-ed
author markus schnalke <meillo@marmaro.de>
date Mon, 05 Sep 2011 16:31:35 +0200
children a09d0630f05b
rev   line source
meillo@0 1 '\" t
meillo@0 2 .\" Sccsid @(#)ed.1 1.48 (gritter) 6/22/05
meillo@0 3 .\" Parts taken from ed(1), Unix 7th edition:
meillo@0 4 .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
meillo@0 5 .\"
meillo@0 6 .\" Redistribution and use in source and binary forms, with or without
meillo@0 7 .\" modification, are permitted provided that the following conditions
meillo@0 8 .\" are met:
meillo@0 9 .\" Redistributions of source code and documentation must retain the
meillo@0 10 .\" above copyright notice, this list of conditions and the following
meillo@0 11 .\" disclaimer.
meillo@0 12 .\" Redistributions in binary form must reproduce the above copyright
meillo@0 13 .\" notice, this list of conditions and the following disclaimer in the
meillo@0 14 .\" documentation and/or other materials provided with the distribution.
meillo@0 15 .\" All advertising materials mentioning features or use of this software
meillo@0 16 .\" must display the following acknowledgement:
meillo@0 17 .\" This product includes software developed or owned by Caldera
meillo@0 18 .\" International, Inc.
meillo@0 19 .\" Neither the name of Caldera International, Inc. nor the names of
meillo@0 20 .\" other contributors may be used to endorse or promote products
meillo@0 21 .\" derived from this software without specific prior written permission.
meillo@0 22 .\"
meillo@0 35 .TH ED 1 "6/22/05" "Heirloom Toolchest" "User Commands"
meillo@0 36 .if t .ds q \(aa
meillo@0 37 .if n .ds q '
meillo@0 38 .SH NAME
meillo@0 39 ed \- text editor
meillo@0 40 .SH SYNOPSIS
meillo@0 41 \fBed\fR [\fB\-\fR\ |\ \fB\-s\fR] [\fB\-p\fI\ prompt\fR] [\fIname\fR]
meillo@0 42 .SH DESCRIPTION
meillo@0 43 .I Ed
meillo@0 44 is the standard text editor.
meillo@0 45 .PP
meillo@0 46 If a
meillo@0 47 .I name
meillo@0 48 argument is given,
meillo@0 49 .I ed
meillo@0 50 simulates an
meillo@0 51 .I e
meillo@0 52 command (see below)\| on the named file; that is to say,
meillo@0 53 the file is read into
meillo@0 54 .IR ed 's
meillo@0 55 buffer so that it can be edited.
meillo@0 56 The optional
meillo@0 57 .B \-
meillo@0 58 or
meillo@0 59 .B \-s
meillo@0 60 suppresses the printing
meillo@0 61 of character counts by
meillo@0 62 .IR e ,
meillo@0 63 .IR r ,
meillo@0 64 and
meillo@0 65 .I w
meillo@0 66 commands,
meillo@0 67 and of the `!' after completion of a shell command.
meillo@0 68 .PP
meillo@0 69 With the
meillo@0 70 .B \-p
meillo@0 71 option,
meillo@0 72 the given
meillo@0 73 .I prompt
meillo@0 74 string is printed before each command is read.
meillo@0 75 .PP
meillo@0 76 .I Ed
meillo@0 77 operates on a copy of any file it is editing; changes made
meillo@0 78 in the copy have no effect on the file until a
meillo@0 79 .IR w ""
meillo@0 80 (write)\|
meillo@0 81 command is given.
meillo@0 82 The copy of the text being edited resides
meillo@0 83 in a temporary file called the
meillo@0 84 .IR buffer .
meillo@0 85 .PP
meillo@0 86 The editor supports format specifications as defined in
meillo@0 87 .IR fspec (5).
meillo@0 88 If the terminal is configured to expand tabulators
meillo@0 89 (as enabled with
meillo@0 90 .I stty tab3
meillo@0 91 or
meillo@0 92 .IR "stty \-tabs"),
meillo@0 93 and the first line of the file being edited
meillo@0 94 contains a format specification,
meillo@0 95 the
meillo@0 96 .I t
meillo@0 97 and
meillo@0 98 .I s
meillo@0 99 are interpreted,
meillo@0 100 that is, tabulators are expanded and lines are truncated
meillo@0 101 when printing to the terminal. For example,
meillo@0 102 .RS
meillo@0 103 <:t\-f s72:>
meillo@0 104 .sp
meillo@0 105 .RE
meillo@0 106 selects FORTRAN format and truncates lines at 72 characters.
meillo@0 107 No expansion or truncation is performed by
meillo@0 108 .I ed
meillo@0 109 when input is typed to the terminal.
meillo@0 110 .PP
meillo@0 111 Commands to
meillo@0 112 .I ed
meillo@0 113 have a simple and regular structure: zero or
meillo@0 114 more
meillo@0 115 .I addresses
meillo@0 116 followed by a single character
meillo@0 117 .I command,
meillo@0 118 possibly
meillo@0 119 followed by parameters to the command.
meillo@0 120 These addresses specify one or more lines in the buffer.
meillo@0 121 Missing addresses are supplied by default.
meillo@0 122 .PP
meillo@0 123 In general, only one command may appear on a line.
meillo@0 124 Certain commands allow the
meillo@0 125 addition of text to the buffer.
meillo@0 126 While
meillo@0 127 .I ed
meillo@0 128 is accepting text, it is said
meillo@0 129 to be in
meillo@0 130 .I "input mode."
meillo@0 131 In this mode, no commands are recognized;
meillo@0 132 all input is merely collected.
meillo@0 133 Input mode is left by typing a period `\fB.\fR' alone at the
meillo@0 134 beginning of a line.
meillo@0 135 .PP
meillo@0 136 .I Ed
meillo@0 137 supports a limited form of
meillo@0 138 .I "regular expression"
meillo@0 139 notation.
meillo@0 140 A regular expression specifies
meillo@0 141 a set of strings of characters.
meillo@0 142 A member of this set of strings is said to be
meillo@0 143 .I matched
meillo@0 144 by the regular expression.
meillo@0 145 In the following specification for regular expressions
meillo@0 146 the word `character' means any character but newline.
meillo@0 147 .B ed
meillo@0 148 uses simple regular expressions.
meillo@0 149 .SS "Simple Regular Expressions"
meillo@0 150 .IP 1.
meillo@0 151 Any character except a special character
meillo@0 152 matches itself.
meillo@0 153 Special characters are
meillo@0 154 the regular expression delimiter plus
meillo@0 155 .RB \e\|[\| .
meillo@0 156 and sometimes ^\|*\|$.
meillo@0 157 .IP 2.
meillo@0 158 A
meillo@0 159 .B .\&
meillo@0 160 matches any character.
meillo@0 161 .IP 3.
meillo@0 162 A \fB\e\fR followed by any character except a digit
meillo@0 163 or (\|) {\|} <\|> matches that character.
meillo@0 164 .IP 4.
meillo@0 165 A nonempty string
meillo@0 166 .I s
meillo@0 167 bracketed
meillo@0 168 \fB[\fI\|s\|\fB]\fR
meillo@0 169 (or
meillo@0 170 \fB[^\fIs\|\fB]\fR)
meillo@0 171 forms a \fIbracket expression\fR that
meillo@0 172 matches any character in (or not in)
meillo@0 173 .I s.
meillo@0 174 In
meillo@0 175 .I s,
meillo@0 176 \e has no special meaning, and ] may only appear as
meillo@0 177 the first letter.
meillo@0 178 A substring
meillo@0 179 \fIa\fB\-\fIb\fR,
meillo@0 180 with
meillo@0 181 .I a
meillo@0 182 and
meillo@0 183 .I b
meillo@0 184 in ascending ASCII order, stands for the inclusive
meillo@0 185 range of ASCII characters.
meillo@0 186 .IP 5.
meillo@0 187 A regular expression of form 1-4 followed by \fB*\fR matches a sequence of
meillo@0 188 0 or more matches of the regular expression.
meillo@0 189 .IP 6.
meillo@0 190 A regular expression of form 1-4
meillo@0 191 followed by \fB\e{\fIm\fB,\fIn\fB\e}\fR
meillo@0 192 forms an \fIinterval expression\fR that
meillo@0 193 matches a sequence of \fIm\fR through \fIn\fR matches, inclusive,
meillo@0 194 of the regular expression.
meillo@0 195 The values of \fIm\fR and \fIn\fR must be non-negative
meillo@0 196 and smaller than 256.
meillo@0 197 The form \fB\e{\fIm\fB\e}\fR matches exactly \fIm\fR occurrences,
meillo@0 198 \fB\e{\fIm\fB,\e}\fR matches at least \fIm\fR occurrences.
meillo@0 199 .IP 7.
meillo@0 200 The sequence \fB\e<\fR forces the match
meillo@0 201 to occur only at the beginning of a ``variable'' or ``word'';
meillo@0 202 that is, either at the beginning of a line,
meillo@0 203 or just before a letter, digit or underline
meillo@0 204 and after a character not one of these.
meillo@0 205 .IP 8.
meillo@0 206 The sequence \fB\e>\fR matches the end
meillo@0 207 of a ``variable'' or ``word'',
meillo@0 208 i.\|e. either the end of the line
meillo@0 209 or before character which is neither a letter,
meillo@0 210 nor a digit, nor the underline character.
meillo@0 211 .IP 9.
meillo@0 212 A regular expression,
meillo@0 213 .I x,
meillo@0 214 of form 1-11, parenthesized
meillo@0 215 \fB\e(\fI\|x\|\fB\e)\fR
meillo@0 216 is called a \fIsubexpression\fR and
meillo@0 217 matches what
meillo@0 218 .I x
meillo@0 219 matches.
meillo@0 220 .IP 10.
meillo@0 221 A \fB\e\fR followed by a digit
meillo@0 222 .I n
meillo@0 223 forms a \fIbackreference\fR and
meillo@0 224 matches a copy of the string that the
meillo@0 225 parenthesized regular expression beginning with the
meillo@0 226 .IR n th
meillo@0 227 \e( matched.
meillo@0 228 .IP 11.
meillo@0 229 A regular expression of form 1-11,
meillo@0 230 .I x,
meillo@0 231 followed by a regular expression of form 1-10,
meillo@0 232 .I y
meillo@0 233 matches a match for
meillo@0 234 .I x
meillo@0 235 followed by a match for
meillo@0 236 .I y,
meillo@0 237 with the
meillo@0 238 .I x
meillo@0 239 match being as long as possible while still permitting a
meillo@0 240 .I y
meillo@0 241 match.
meillo@0 242 .IP 12.
meillo@0 243 A regular expression of form 1-11 preceded by \fB^\fR
meillo@0 244 (or followed by \fB$\fR), is constrained to matches that
meillo@0 245 begin at the left (or end at the right) end of a line
meillo@0 246 (\fIanchoring\fR).
meillo@0 247 .IP 13.
meillo@0 248 A regular expression of form 1-12 picks out the
meillo@0 249 longest among the leftmost matches in a line.
meillo@0 250 .IP 14.
meillo@0 251 An empty regular expression stands for a copy of the
meillo@0 252 last regular expression encountered.
meillo@0 253 .PP
meillo@0 254 Regular expressions are used in addresses to specify
meillo@0 255 lines and in one command
meillo@0 256 (see
meillo@0 257 .I s
meillo@0 258 below)\|
meillo@0 259 to specify a portion of a line which is to be replaced.
meillo@0 260 If it is desired to use one of
meillo@0 261 the regular expression metacharacters as an ordinary
meillo@0 262 character, that character may be preceded by `\e'.
meillo@0 263 This also applies to the character bounding the regular
meillo@0 264 expression (often `/')\| and to `\e' itself.
meillo@0 265 .PP
meillo@0 266 To understand addressing in
meillo@0 267 .I ed
meillo@0 268 it is necessary to know that at any time there is a
meillo@0 269 .I "current line."
meillo@0 270 Generally speaking, the current line is
meillo@0 271 the last line affected by a command; however,
meillo@0 272 the exact effect on the current line
meillo@0 273 is discussed under the description of
meillo@0 274 the command.
meillo@0 275 Addresses are constructed as follows.
meillo@0 276 .TP
meillo@0 277 1.
meillo@0 278 The character `\fB.\fR' addresses the current line.
meillo@0 279 .TP
meillo@0 280 2.
meillo@0 281 The character `\fB$\fR' addresses the last line of the buffer.
meillo@0 282 .TP
meillo@0 283 3.
meillo@0 284 A decimal number
meillo@0 285 .I n
meillo@0 286 addresses the
meillo@0 287 .IR n -th
meillo@0 288 line of the buffer.
meillo@0 289 .TP
meillo@0 290 4.
meillo@0 291 `\fB\(fm\fIx\fR' addresses the line marked with the name
meillo@0 292 .IR x ,
meillo@0 293 which must be a lower-case letter.
meillo@0 294 Lines are marked with the
meillo@0 295 .I k
meillo@0 296 command described below.
meillo@0 297 .TP
meillo@0 298 5.
meillo@0 299 A regular expression enclosed in slashes `\fB/\fR' addresses
meillo@0 300 the line found by searching forward from the current line
meillo@0 301 and stopping at the first line containing a
meillo@0 302 string that matches the regular expression.
meillo@0 303 If necessary the search wraps around to the beginning of the
meillo@0 304 buffer.
meillo@0 305 .TP
meillo@0 306 6.
meillo@0 307 A regular expression enclosed in queries `\fB?\fR' addresses
meillo@0 308 the line found by searching backward from the current line
meillo@0 309 and stopping at the first line containing
meillo@0 310 a string that matches the regular expression.
meillo@0 311 If necessary
meillo@0 312 the search wraps around to the end of the buffer.
meillo@0 313 .TP
meillo@0 314 7.
meillo@0 315 An address followed by a plus sign `\fB+\fR'
meillo@0 316 or a minus sign `\fB\-\fR' followed by a decimal number
meillo@0 317 specifies that address plus
meillo@0 318 (resp. minus)\| the indicated number of lines.
meillo@0 319 The plus sign may be omitted.
meillo@0 320 .TP
meillo@0 321 8.
meillo@0 322 If an address begins with `\fB+\fR' or `\fB\-\fR'
meillo@0 323 the addition or subtraction is taken with respect to the current line;
meillo@0 324 e.g. `\-5' is understood to mean `\fB.\fR\-5'.
meillo@0 325 .TP
meillo@0 326 9.
meillo@0 327 If an address ends with `\fB+\fR' or `\fB\-\fR',
meillo@0 328 then 1 is added (resp. subtracted).
meillo@0 329 As a consequence of this rule and rule 8,
meillo@0 330 the address `\-' refers to the line before the current line.
meillo@0 331 Moreover,
meillo@0 332 trailing
meillo@0 333 `+' and `\-' characters
meillo@0 334 have cumulative effect, so `\-\-' refers to the current
meillo@0 335 line less 2.
meillo@0 336 .TP
meillo@0 337 10.
meillo@0 338 To maintain compatibility with earlier versions of the editor,
meillo@0 339 the character `\fB^\fR' in addresses is
meillo@0 340 equivalent to `\-'.
meillo@0 341 .PP
meillo@0 342 Commands may require zero, one, or two addresses.
meillo@0 343 Commands which require no addresses regard the presence
meillo@0 344 of an address as an error.
meillo@0 345 Commands which accept one or two addresses
meillo@0 346 assume default addresses when insufficient are given.
meillo@0 347 If more addresses are given than such a command requires,
meillo@0 348 the last one or two (depending on what is accepted)\| are used.
meillo@0 349 .PP
meillo@0 350 Addresses are separated from each other typically by a comma
meillo@0 351 `\fB,\fR'.
meillo@0 352 They may also be separated by a semicolon
meillo@0 353 `\fB;\fR'.
meillo@0 354 In this case the current line `\fB.\fR' is set to
meillo@0 355 the previous address before the next address is interpreted.
meillo@0 356 This feature can be used to determine the starting
meillo@0 357 line for forward and backward searches (`/', `?')\|.
meillo@0 358 The second address of any two-address sequence
meillo@0 359 must correspond to a line following the line corresponding to the first address.
meillo@0 360 .PP
meillo@0 361 Omission of the first address causes
meillo@0 362 the first line to be used with `,',
meillo@0 363 or the current line with `;', respectively;
meillo@0 364 if the second address is also omitted,
meillo@0 365 the last line of the buffer is used.
meillo@0 366 Thus a single `,' specifies the entire contents of the buffer,
meillo@0 367 and a single `;' specifies the contents
meillo@0 368 ranging from the current line to the last one.
meillo@0 369 .PP
meillo@0 370 In the following list of
meillo@0 371 .I ed
meillo@0 372 commands, the default addresses
meillo@0 373 are shown in parentheses.
meillo@0 374 The parentheses are not part of
meillo@0 375 the address, but are used to show that the given addresses are
meillo@0 376 the default.
meillo@0 377 .PP
meillo@0 378 As mentioned, it is generally illegal for more than one
meillo@0 379 command to appear on a line.
meillo@0 380 However, most commands may be suffixed by `p', `l', or `n',
meillo@0 381 in which case
meillo@0 382 the current line is either
meillo@0 383 printed, listed, or numbered respectively
meillo@0 384 in the way discussed below.
meillo@0 385 .TP 5
meillo@0 386 \fR(\|\fI.\|\fR)\fB\|a\fR
meillo@0 387 .br
meillo@0 388 .ns
meillo@0 389 .TP 5
meillo@0 390 <text>
meillo@0 391 .br
meillo@0 392 .ns
meillo@0 393 .TP 5
meillo@0 394 .B .
meillo@0 395 .br
meillo@0 396 The append command reads the given text
meillo@0 397 and appends it after the addressed line.
meillo@0 398 `\fB.\fR' is left
meillo@0 399 on the last line input, if there
meillo@0 400 were any, otherwise at the addressed line.
meillo@0 401 Address `0' is legal for this command; text is placed
meillo@0 402 at the beginning of the buffer.
meillo@0 403 .TP 5
meillo@0 404 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBc\fR
meillo@0 405 .br
meillo@0 406 .ns
meillo@0 407 .TP 5
meillo@0 408 <text>
meillo@0 409 .br
meillo@0 410 .ns
meillo@0 411 .TP 5
meillo@0 412 .B .
meillo@0 413 .br
meillo@0 414 The change
meillo@0 415 command deletes the addressed lines, then accepts input
meillo@0 416 text which replaces these lines.
meillo@0 417 `\fB.\fR' is left at the last line input; if there were none,
meillo@0 418 it is left at the line preceding the deleted lines.
meillo@0 419 .TP 5
meillo@0 420 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBd\fR
meillo@0 421 The delete command deletes the addressed lines from the buffer.
meillo@0 422 The line originally after the last line deleted becomes the current line;
meillo@0 423 if the lines deleted were originally at the end,
meillo@0 424 the new last line becomes the current line.
meillo@0 425 .TP 5
meillo@0 426 \fBe\ \fIfilename\fR
meillo@0 427 The edit
meillo@0 428 command causes the entire contents of the buffer to be deleted,
meillo@0 429 and then the named file to be read in.
meillo@0 430 `\fB.\fR' is set to the last line of the buffer.
meillo@0 431 The number of characters read is typed.
meillo@0 432 `\fIfilename\fR' is remembered for possible use as a default file name
meillo@0 433 in a subsequent
meillo@0 434 .I r
meillo@0 435 or
meillo@0 436 .I w
meillo@0 437 command.
meillo@0 438 If `\fIfilename\fR' is missing, the remembered name is used.
meillo@0 439 A `\fIfilename\fR' starting with a `\fB!\fR'
meillo@0 440 causes the output of the shell command following this character
meillo@0 441 to be read in.
meillo@0 442 .TP 5
meillo@0 443 \fBE\ \fIfilename\fR
meillo@0 444 This command is the same as
meillo@0 445 .IR e ,
meillo@0 446 except that no diagnostic results when no
meillo@0 447 .I w
meillo@0 448 has been given since the last buffer alteration.
meillo@0 449 .TP 5
meillo@0 450 \fBf\ \fIfilename\fR
meillo@0 451 The filename command prints the currently remembered file name.
meillo@0 452 If `\fIfilename\fR' is given,
meillo@0 453 the currently remembered file name is changed to `\fIfilename\fR'.
meillo@0 454 .TP 5
meillo@0 455 \fR(\fI1\fB,\fI$\fR)\|\fBg/\fIregular expression\fB/\fIcommand list\fR
meillo@0 456 In the global
meillo@0 457 command, the first step is to mark every line which matches
meillo@0 458 the given \fIregular expression\fR.
meillo@0 459 Then for every such line, the
meillo@0 460 given \fIcommand list\fR is executed
meillo@0 461 with `\fB.\fR' initially set to that line.
meillo@0 462 A single command or the first of multiple commands
meillo@0 463 appears on the same line with the global command.
meillo@0 464 All lines of a multi-line list except the last line must be ended with `\e'.
meillo@0 465 .I A,
meillo@0 466 .I i,
meillo@0 467 and
meillo@0 468 .I c
meillo@0 469 commands and associated input are permitted;
meillo@0 470 the `\fB.\fR' terminating input mode may be omitted if it would be on the
meillo@0 471 last line of the command list.
meillo@0 472 The commands
meillo@0 473 .I g
meillo@0 474 and
meillo@0 475 .I v
meillo@0 476 are not permitted in the command list.
meillo@0 477 .TP 5
meillo@0 478 \fR(\fI1\fB,\fI$\fR)\|\fBG/\fIregular expression\fB/\fR
meillo@0 479 The interactive global command
meillo@0 480 first marks every line matching the given \fIregular expression\fR.
meillo@0 481 Then each line is printed
meillo@0 482 and a command is read and executed for this line.
meillo@0 483 A single newline character causes the line to remain unchanged,
meillo@0 484 an isolated `\fB&\fR' repeats the command given for the previous line.
meillo@0 485 The command can be terminated by an interrupt signal.
meillo@0 486 .TP 5
meillo@0 487 .B h
meillo@0 488 This command prints a verbose description for the
meillo@0 489 last error encountered.
meillo@0 490 .TP
meillo@0 491 .B H
meillo@0 492 This command acts like the
meillo@0 493 .I h
meillo@0 494 command,
meillo@0 495 but also causes verbose descriptions to be printed
meillo@0 496 on all following error conditions.
meillo@0 497 Another
meillo@0 498 .I H
meillo@0 499 turns verbose mode off.
meillo@0 500 .TP 5
meillo@0 501 \fR(\|\fI.\|\fR)\|\fBi\fR
meillo@0 502 .br
meillo@0 503 .ns
meillo@0 504 .TP 5
meillo@0 505 <text>
meillo@0 506 .br
meillo@0 507 .ns
meillo@0 508 .TP 5
meillo@0 509 .B .
meillo@0 510 .br
meillo@0 511 This command inserts the given text before the addressed line.
meillo@0 512 `\fB.\fR' is left at the last line input, or, if there were none,
meillo@0 513 at the line before the addressed line.
meillo@0 514 This command differs from the
meillo@0 515 .I a
meillo@0 516 command only in the placement of the
meillo@0 517 text.
meillo@0 518 .TP 5
meillo@0 519 \fR(\|\fI.\|\fB,\|\fI.+1\fR)\|\fBj\fR
meillo@0 520 This command joins the addressed lines into a single line;
meillo@0 521 intermediate newlines simply disappear.
meillo@0 522 `\fB.\fR' is left at the resulting line.
meillo@0 523 .TP 5
meillo@0 524 \fR(\fI.\fR)\|\fBk\fIx\fR
meillo@0 525 The mark command marks the addressed line with
meillo@0 526 name
meillo@0 527 .IR x ,
meillo@0 528 which must be a lower-case letter.
meillo@0 529 The address form `\(fm\fIx\fR' then addresses this line.
meillo@0 530 .ne 2.5
meillo@0 531 .TP 5
meillo@0 532 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBl\fR
meillo@0 533 The list command
meillo@0 534 prints the addressed lines in an unambiguous way:
meillo@0 535 non-graphic control characters are printed in three-digit octal;
meillo@0 536 Long lines are folded.
meillo@0 537 The
meillo@0 538 .I l
meillo@0 539 command may be placed on the same line after any non-i/o
meillo@0 540 command.
meillo@0 541 .TP 5
meillo@0 542 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBm\fIa\fR
meillo@0 543 The move command repositions the addressed lines after the line
meillo@0 544 addressed by
meillo@0 545 .IR a .
meillo@0 546 The last of the moved lines becomes the current line.
meillo@0 547 .TP 5
meillo@0 548 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBn\fR
meillo@0 549 This command prints lines preceded by their line numbers.
meillo@0 550 It otherwise acts like the
meillo@0 551 .I p
meillo@0 552 command described below.
meillo@0 553 .TP 5
meillo@0 554 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBp\fR
meillo@0 555 The print command prints the addressed lines.
meillo@0 556 `\fB.\fR'
meillo@0 557 is left at the last line printed.
meillo@0 558 The
meillo@0 559 .I p
meillo@0 560 command
meillo@0 561 may
meillo@0 562 be placed on the same line after any non-i/o command.
meillo@0 563 .TP
meillo@0 564 .B P
meillo@0 565 This command causes a prompt to be printed
meillo@0 566 before following commands are read.
meillo@0 567 The default prompt is a `*' character,
meillo@0 568 but can be set with the
meillo@0 569 .I \-p
meillo@0 570 command line option (which also enables the prompt).
meillo@0 571 Another
meillo@0 572 .I P
meillo@0 573 disables the prompt.
meillo@0 574 .TP 5
meillo@0 575 .B q
meillo@0 576 The quit command causes
meillo@0 577 .I ed
meillo@0 578 to exit.
meillo@0 579 No automatic write
meillo@0 580 of a file is done.
meillo@0 581 .TP 5
meillo@0 582 .B Q
meillo@0 583 This command is the same as
meillo@0 584 .I q,
meillo@0 585 except that no diagnostic results when no
meillo@0 586 .I w
meillo@0 587 has been given since the last buffer alteration.
meillo@0 588 .TP 5
meillo@0 589 \fR(\fI$\fR)\|\fBr\ \fIfilename\fR
meillo@0 590 The read command
meillo@0 591 reads in the given file after the addressed line.
meillo@0 592 If no file name is given,
meillo@0 593 the remembered file name, if any, is used
meillo@0 594 (see
meillo@0 595 .I e
meillo@0 596 and
meillo@0 597 .I f
meillo@0 598 commands)\|.
meillo@0 599 The file name is remembered if there was no
meillo@0 600 remembered file name already.
meillo@0 601 Address `0' is legal for
meillo@0 602 .I r
meillo@0 603 and causes the
meillo@0 604 file to be read at the beginning of the buffer.
meillo@0 605 If the read is successful, the number of characters
meillo@0 606 read is typed.
meillo@0 607 `\fB.\fR' is left at the last line read in from the file.
meillo@0 608 A `filename' starting with a `\fB!\fR'
meillo@0 609 causes the output of the shell command following this character
meillo@0 610 to be read in.
meillo@0 611 .TP 5
meillo@0 612 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fR or,
meillo@0 613 .br
meillo@0 614 .ns
meillo@0 615 .TP 5
meillo@0 616 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/g\fR or,
meillo@0 617 .br
meillo@0 618 .ns
meillo@0 619 .TP 5
meillo@0 620 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fInumber\fR
meillo@0 621 The substitute command searches each addressed
meillo@0 622 line for an occurrence of the specified regular expression.
meillo@0 623 On each line in which a match is found,
meillo@0 624 all matched strings are replaced by the replacement specified,
meillo@0 625 if the global replacement indicator
meillo@0 626 .RB ` g '
meillo@0 627 appears after the command.
meillo@0 628 If the global indicator does not appear, only the first occurrence
meillo@0 629 of the matched string is replaced;
meillo@0 630 if the \fInumber\fR indicator is given,
meillo@0 631 the numbered occurrence is replaced.
meillo@0 632 It is an error for the substitution to fail on all addressed lines.
meillo@0 633 Any character other than space or new-line
meillo@0 634 may be used instead of `/' to delimit the regular expression
meillo@0 635 and the replacement.
meillo@0 636 `\fB.\fR' is left at the last line substituted.
meillo@0 637 .IP
meillo@0 638 An ampersand
meillo@0 639 .RB ` & '
meillo@0 640 appearing in the replacement
meillo@0 641 is replaced by the string matching the regular expression.
meillo@0 642 The special meaning of `&' in this context may be
meillo@0 643 suppressed by preceding it by
meillo@0 644 .RB ` \e '.
meillo@0 645 The characters `\|\fB\e\fIn\fR'
meillo@0 646 where
meillo@0 647 .I n
meillo@0 648 is a digit,
meillo@0 649 are replaced by the text matched by the
meillo@0 650 .IR n -th
meillo@0 651 regular subexpression
meillo@0 652 enclosed between `\e(' and `\e)'.
meillo@0 653 When
meillo@0 654 nested, parenthesized subexpressions
meillo@0 655 are present,
meillo@0 656 .I n
meillo@0 657 is determined by counting occurrences of `\e(' starting from the left.
meillo@0 658 .IP
meillo@0 659 A substitution string consisting of a single
meillo@0 660 .RB ` % '
meillo@0 661 causes the string given on the previous substitution to be re-used.
meillo@0 662 .IP
meillo@0 663 Lines may be split by substituting new-line characters into them.
meillo@0 664 The new-line in the
meillo@0 665 replacement string
meillo@0 666 must be escaped by preceding it by
meillo@0 667 .RB ` \e '.
meillo@0 668 .TP 5
meillo@0 669 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBt\|\fIa\fR
meillo@0 670 This command acts just like the
meillo@0 671 .I m
meillo@0 672 command, except that a copy of the addressed lines is placed
meillo@0 673 after address
meillo@0 674 .I a
meillo@0 675 (which may be 0).
meillo@0 676 `\fB.\fR' is left on the last line of the copy.
meillo@0 677 .TP 5
meillo@0 678 .B u
meillo@0 679 The undo command restores
meillo@0 680 the contents of the buffer
meillo@0 681 before the last command was executed.
meillo@0 682 If the undo command is given twice,
meillo@0 683 the current state is restored.
meillo@0 684 .TP 5
meillo@0 685 \fR(\fI1\fB,\fI$\fR)\|\fBv/\fIregular expression\fB/\fIcommand list\fR
meillo@0 686 This command is the same as the global command
meillo@0 687 .I g
meillo@0 688 except that the command list is executed
meillo@0 689 .I g
meillo@0 690 with `\fB.\fR' initially set to every line
meillo@0 691 .I except
meillo@0 692 those
meillo@0 693 matching the regular expression.
meillo@0 694 .TP 5
meillo@0 695 \fR(\fI1\fB,\fI$\fR)\|\fBV/\fIregular expression\fB/\fR
meillo@0 696 This command is the same as the interactive global command
meillo@0 697 .I G
meillo@0 698 except that the commands are read
meillo@0 699 .I g
meillo@0 700 with `\fB.\fR' initially set to every line
meillo@0 701 .I except
meillo@0 702 those
meillo@0 703 matching the regular expression.
meillo@0 704 .TP 5
meillo@0 705 \fR(\fI1\fB,\fI$\fR)\|\fBw\ \fIfilename\fR
meillo@0 706 .br
meillo@0 707 The write command writes the addressed lines onto
meillo@0 708 the given file.
meillo@0 709 If the file does not exist,
meillo@0 710 it is created mode 666 (readable and writable by everyone)\|.
meillo@0 711 The file name is remembered if there was no
meillo@0 712 remembered file name already.
meillo@0 713 If no file name is given,
meillo@0 714 the remembered file name, if any, is used
meillo@0 715 (see
meillo@0 716 .I e
meillo@0 717 and
meillo@0 718 .I f
meillo@0 719 commands)\|.
meillo@0 720 `\fB.\fR' is unchanged.
meillo@0 721 If the command is successful, the number of characters written is
meillo@0 722 printed.
meillo@0 723 A `filename' starting with a `\fB!\fR'
meillo@0 724 causes the string following this character
meillo@0 725 to be executed as a shell command
meillo@0 726 with the addressed lines as standard input.
meillo@0 727 .TP
meillo@0 728 \fR(\fI1\fB,\fI$\fR)\fBW\ \fIfilename\fR
meillo@0 729 This command is the same as
meillo@0 730 .I w,
meillo@0 731 except that the addressed lines are appended to the file.
meillo@0 732 .TP 5
meillo@0 733 \fR(\fI$\fR)\|\fB=\fR
meillo@0 734 The line number of the addressed line is typed.
meillo@0 735 `\fB.\fR' is unchanged by this command.
meillo@0 736 .TP 5
meillo@0 737 \fB!\fR<shell command>
meillo@0 738 The remainder of the line after the `!' is sent
meillo@0 739 to
meillo@0 740 .IR sh (1)
meillo@0 741 to be interpreted as a command.
meillo@0 742 .RB ` . '
meillo@0 743 is unchanged.
meillo@0 744 If the command starts with a
meillo@0 745 .RB ` ! ',
meillo@0 746 the previous command is inserted.
meillo@0 747 A
meillo@0 748 .RB ` % '
meillo@0 749 causes the current file name to be inserted.
meillo@0 750 .TP 5
meillo@0 751 \fR(\|\fI.+1\fR)\|<newline>
meillo@0 752 An address alone on a line causes the addressed line to be printed.
meillo@0 753 A blank line alone is equivalent to `.+1p'; it is useful
meillo@0 754 for stepping through text.
meillo@0 755 .PP
meillo@0 756 The following commands are extensions:
meillo@0 757 .TP 5
meillo@0 758 \fR(\|\fI.\|\fR)\fB\|b\fR[\fIcount\fR]
meillo@0 759 Prints a screenful of lines,
meillo@0 760 starting at the addressed one,
meillo@0 761 and browses forward in the buffer by this amount.
meillo@0 762 With the optional
meillo@0 763 .I count
meillo@0 764 argument, the screen size for this and following
meillo@0 765 .I b
meillo@0 766 commands is set to the given number of lines.
meillo@0 767 .TP 5
meillo@0 768 .B help
meillo@0 769 Causes a summary of
meillo@0 770 .I ed
meillo@0 771 commands along with short descriptions
meillo@0 772 to be printed on the terminal.
meillo@0 773 .TP 5
meillo@0 774 .B N
meillo@0 775 Makes the
meillo@0 776 .I p
meillo@0 777 command behave like the
meillo@0 778 .I n
meillo@0 779 command and vice-versa.
meillo@0 780 If given a second time,
meillo@0 781 the original semantics are restored.
meillo@0 782 .TP 5
meillo@0 783 \fR(\|\fI.\|\fR)\fB\|o\fR[\fIcount\fR]
meillo@0 784 Prints a screenful of lines centered around the addressed one.
meillo@0 785 The current line is not changed.
meillo@0 786 With the optional
meillo@0 787 .I count
meillo@0 788 argument, the amount of lines printed above and below
meillo@0 789 for this and following
meillo@0 790 .I o
meillo@0 791 commands is set to the given number.
meillo@0 792 .TP 5
meillo@0 793 .B z
meillo@0 794 Performs the same actions as a
meillo@0 795 .I w
meillo@0 796 command followed by a
meillo@0 797 .I q
meillo@0 798 command.
meillo@0 799 .PP
meillo@0 800 If an interrupt signal is sent,
meillo@0 801 .I ed
meillo@0 802 prints a `?' and returns to its command level.
meillo@0 803 .PP
meillo@0 804 An input line that consists exactly of the two characters `\e.'
meillo@0 805 causes a period `.' to be inserted with the
meillo@0 806 .IR a ,
meillo@0 807 .IR c ,
meillo@0 808 and
meillo@0 809 .IR i
meillo@0 810 commands.
meillo@0 811 .PP
meillo@0 812 Some size limitations:
meillo@0 813 The maximum number of bytes in the buffer
meillo@0 814 corresponds to the address size;
meillo@0 815 on machines with 32-bit addressing,
meillo@0 816 it is 2\ G bytes,
meillo@0 817 with 64-bit addressing,
meillo@0 818 it is 9\ E bytes.
meillo@0 819 The limit on the number of lines depends on the amount of core:
meillo@0 820 each line takes 2 words.
meillo@0 821 .PP
meillo@0 822 If a line contains a NUL character,
meillo@0 823 regular expressions cannot match beyond this character.
meillo@0 824 A substitute command deletes a NUL
meillo@0 825 and all following characters on the line.
meillo@0 826 NUL characters in command input are discarded.
meillo@0 827 If an input file does not end with a newline,
meillo@0 828 .I ed
meillo@0 829 prints a message and appends one.
meillo@0 830 .PP
meillo@0 831 Omission of the `/' character
meillo@0 832 following the regular expression or the replacement string
meillo@0 833 to the global and substitute commands
meillo@0 834 causes the affected lines to be printed.
meillo@0 835 Thus the following commands have the same effect:
meillo@0 836 .RS
meillo@0 837 g/pattern g/pattern/p
meillo@0 838 .br
meillo@0 839 s/pattern/repl s/pattern/repl/p
meillo@0 840 .br
meillo@0 841 s/pattern/ s/pattern//p
meillo@0 842 .RE
meillo@0 844 .TP
meillo@0 845 .BR LANG ", " LC_ALL
meillo@0 846 See
meillo@0 847 .IR locale (7).
meillo@0 848 .TP
meillo@0 849 .B LC_CTYPE
meillo@0 850 Determines the mapping of bytes to characters
meillo@0 851 and the set of printable characters for the
meillo@0 852 .I l
meillo@0 853 command.
meillo@0 854 .TP
meillo@0 855 .B TMPDIR
meillo@0 856 Determines the location of the temporary file
meillo@0 857 if it contains the name of an accessible directory.
meillo@0 858 .SH FILES
meillo@0 859 /var/tmp/e*
meillo@0 860 .br
meillo@0 861 /tmp/e*
meillo@0 862 .br
meillo@0 863 ed.hup: work is saved here if terminal hangs up
meillo@0 864 .SH "SEE ALSO"
meillo@0 865 B. W. Kernighan,
meillo@0 866 .I
meillo@0 867 A Tutorial Introduction to the ED Text Editor
meillo@0 868 .br
meillo@0 869 B. W. Kernighan,
meillo@0 870 .I Advanced editing on UNIX
meillo@0 871 .br
meillo@0 872 bfs(1),
meillo@0 873 grep(1),
meillo@0 874 sed(1),
meillo@0 875 sh(1)
meillo@0 876 .SH DIAGNOSTICS
meillo@0 877 `?name' for inaccessible file;
meillo@0 878 `?' for
meillo@0 879 errors in commands,
meillo@0 880 possibly followed by a verbose description
meillo@0 881 (see the description for the
meillo@0 882 .I h
meillo@0 883 and
meillo@0 884 .I H
meillo@0 885 commands above).
meillo@0 886 .PP
meillo@0 887 To protect against throwing away valuable work,
meillo@0 888 a
meillo@0 889 .I q
meillo@0 890 or
meillo@0 891 .I e
meillo@0 892 command is considered to be in error, unless a
meillo@0 893 .I w
meillo@0 894 has occurred since the last buffer change.
meillo@0 895 A second
meillo@0 896 .I q
meillo@0 897 or
meillo@0 898 .I e
meillo@0 899 will be obeyed regardless.
meillo@0 900 .SH NOTES
meillo@0 901 A
meillo@0 902 .I !\&
meillo@0 903 command cannot be subject to a
meillo@0 904 .I g
meillo@0 905 command.
meillo@0 906 .PP
meillo@0 907 The LC_COLLATE variable has currently no effect.
meillo@0 908 Ranges in bracket expressions are ordered
meillo@0 909 as byte values in single-byte locales
meillo@0 910 and as wide character values in multibyte locales.
meillo@0 911 .PP
meillo@0 912 For portable programs, restrict textual data
meillo@0 913 to the US-ASCII character set and
meillo@0 914 set the LC_CTYPE and LC_COLLATE variables to `C' or `POSIX'.