6/12/72 ED (I) NAME ed -- editor SYNOPSIS ed [ name ] DESCRIPTION ed is the standard text editor. If the optional argument is given, ed simulates an e command on the named file; that is to say, the file is read into ed's buffer so that it can be edited. ed operates on a copy of any file it is editing; changes made in the copy have no effect on the file until an explicit write (w) command is given. The copy of the text being edited resides in a temporary file called the buffer. There is only one buffer. Commands to ed have a simple and regular struc- ture: zero or more addresses followed by a single character command, possibly followed by parame- ters to the command. These addresses specify one or more lines in the buffer. Every command which requires addresses has default addresses, so that the addresses can often be omitted. In general only one command may appear on a line. Certain commands allow the input of text. This text is placed in the appropriate place in the buffer. While ed is accepting text, it is said to be in input mode. In this mode, no commands are recognized; all input is merely collected. Input mode is left by typing a period (.) alone at the beginning of a line. ed supports a limited form of regular expression notation. A regular expression is an expression which specifies a set of strings of characters. A member of this set of strings is said to be matched by the regular expression. The regular expressions allowed by ed are constructed as fol- lows: 1. An ordinary character (not one of those discussed below) is a regular expression and matches that character. 2. A circumflex (^) at the beginning of a reg- ular expression matches the null character at the beginning of a line. 3. A currency symbol ($) at the end of a regu- lar expression matches the null character at the end of a line. 4. A period (.) matches any character but a new-line character. 5. A regular expression followed by an aster- isk (*) matches any number of adjacent oc- currences (including zero) of the regular expression it follows. 6. A string of characters enclosed in square brackets ([]) matches any character in the string but no others. If, however, the first character of the string is a circum- flex (^) the regular expression matches any character but new-line and the characters in the string. 7. The concatenation of regular expressions is a regular expression which matches the con- catenation of the strings matched by the components of the regular expression. 8. The null regular expression standing alone is equivalent to the last regular expres- sion encountered. Regular expressions are used in addresses to specify lines and in one command (s, see below) to specify a portion of a line which is to be re- placed. If it is desired to use one of the regular ex- pression metacharacters as an ordinary character, that character may be preceded by "\". This also applies to the character bounding the regular ex- pression (often "/") and to "\" itself. Addresses are constructed as follows. To under- stand addressing in ed it is necessary to know that at any time there is a current line. Gener- ally speaking, the current line is the last line affected by a command; however, the exact effect on the current line by each command is discussed under the description of the command. 1. The character "." addresses the current line. 2. The character "^" addresses the line imme- diately before the current line. 3. The character "$" addresses the last line of the buffer. 4. A decimal number n addresses the nth line of the buffer. 6. A regular expression enclosed in slashes "/" addresses the first line found by searching toward the end of the buffer and stopping at the first line containing a string matching the regular expression. If necessary the search wraps around to the beginning of the buffer. 5. A regular expression enclosed in queries "?" addresses the first line found by searching toward the beginning of the buffer and stopping at the first line found containing a string matching the regular expression. If necessary the search wraps around to the end of the buffer. 7. An address followed by a plus sign "+" or a minus sign "-" followed by a decimal number specifies that address plus (resp. minus) the indicated number of lines. The plus sign may be omitted. 8. "'x" addresses the line associated (marked) with the mark name character "x" which must be a printable character. Lines may be marked with the "k" command described be- low. Commands may require zero, one, or two addresses. Commands which require no addresses regard the presence of an address as an error. Commands which accept one or two addresses assume default addresses when insufficient are given. If more addresses are given than such a command requires, the last one or two (depending on what is ac- cepted) are used. Addresses are separated from each other typically by a comma (,). They may also be separated by a semicolon (;). In this case the current line "." is set to the the previous address before the next address is interpreted. This feature can be used to determine the starting line for forward and backward searches ("/", "?"). The second ad- dress of any two-address sequence must correspond to a line following the line corresponding to the first address. In the following list of ed commands, the default addresses are shown in parentheses. The paren- theses are not part of the address, but are used to show that the given addresses are the default. As mentioned, it is generally illegal for more than one command to appear on a line. However, any command may be suffixed by "p" (for "print"). In that case, the current line is printed after the command is complete. (.)a <text> . The append command reads the given text and appends it after the addressed line. "." is left on the last line input, if there were any, otherwise at the addressed line. Address "0" is legal for this command; text is placed at the beginning of the buffer. (.,.)c <text> . The change command deletes the addressed lines, then accepts input text which re- places these lines. "." is left at the last line input; if there were none, it is left at the first line not changed. (.,.)d The delete command deletes the addressed lines from the buffer. The line originally after the last line deleted becomes the current line; if the lines deleted were originally at the end, the new last line becomes the current line. e filename The edit command causes the entire contents of the buffer to be deleted, and then the named file to be read in. "." is set to the last line of the buffer. The number of characters read is typed. "filename" is remembered for possible use as a default file name in a subsequent r or w command. f filename The filename command prints the currently remembered file name. If "filename" is given, the currently remembered file name is changed to "filename". (1,$)g/regular expression/command list In the global command, the first step is to mark every line which matches the given regular expression. Then for every such line, the given command list is executed with "." initially set to that line. A single command or the first of multiple commands appears on the same line with the global command. All lines of a multi-line list except the last line must be ended with "\". a, i, and c commands and associ- ated input are permitted; the "." terminat- ing input mode may be omitted if it would be on the last line of the command list. The (global) commands, g and v, are not permitted in the command list. (.)i <text> . This command inserts the given text before the addressed line. "." is left at the last line input; if there were none, at the addressed line. This command differs from the a command only in the placement of the text. (.)kx The mark command associates or marks the addressed line with the single character mark name "x". The ten most recent mark names are remembered. The current mark names may be printed with the n command. (.,.)l The list command prints the addressed lines in an unambiguous way. Non-printing char- acters are over-struck as follows: char prints bs\tab>ret<SIISOOAll character preceded by a prefix (ESC) character are printed over-struck with ^ without the prefix. Long lines are folded with the sequence \newline. (.,.)mA The move command will reposition the ad- dressed lines after the line addressed by "A". The line originally after the last line moved becomes the current line; if the lines moved were originally at the end, the new last line becomes the current line. n The marknames command will print the cur- rent mark names. (.,.)p The print command prints the addressed lines. "." is left at the last line printed. The p command may be placed on the same line after any command. q The quit command causes ed to exit. No au- tomatic write of a file is done. ($)r filename The read command reads in the given file after the addressed line. If no file name is given, the remembered file name, if any, is used (see e and f commands). The remem- bered file name is not changed unless "filename" is the very first file name men- tioned. Address "0" is legal for r and causes the file to be read at the beginning of the buffer. If the read is successful, the number of characters read is typed. "." is left at the last line read in from the file. (.,.)s/regular expression/replacement/ or, (.,.)s/regular expression/replacement/g The substitute command searches each ad- dressed line for an occurrence of the spec- ified regular expression. On each line in which a match is found, all matched strings are replaced by the replacement specified, if the global replacement indicator "g" ap- pears after the command. If the global in- dicator does not appear, only the first oc- currence of the matched string is replaced. It is an error for the substitution to fail on all addressed lines. Any character oth- er than space or new-line may be used in- stead of "/" to delimit the regular expres- sion and the replacement. "." is left at the last line substituted. The ampersand "&" appearing in the replace- ment is replaced by the regular expression that was matched. The special meaning of "&" in this context may be suppressed by preceding it by "\". (1,$)v/regular expression/command list This command is the same as the global com- mand except that the command list is exe- cuted with "." initially set to every line except those matching the regular expres- sion (1,$)w filename The write command writes the addressed lines onto the given file. If the file does not exist, it is created mode 17 (readable and writeable by everyone). The remembered file name is not changed unless "filename" is the very first file name men- tioned. If no file name is given, the re- membered file name, if any, is used (see e and f commands). "." is unchanged. If the command is successful, the number of char- acters written is typed. ($)= The line number of the addressed line is typed. "." is unchanged by this command. !UNIX command The remainder of the line after the "!" is sent to UNIX to be interpreted as a com- mand. "." is unchanged. (.+1)<newline> An address alone on a line causes that line to be printed. A blank line alone is equivalent to ".+1p"; it is useful for stepping through text. If an interrupt signal (ASCII DEL) is sent, ed will print a "?" and return to its command level. If invoked with the command name '-', (see init) ed will sign on with the message "Editing system" and print "*" as the command level prompt charac- ter. Ed has size limitations on the maximum number of lines that can be edited, and on the maximum num- ber of characters in a line, in a global's com- mand list, and in a remembered file name. These limitations vary with the physical core size of the PDP11 computer on which ed is being used. The range of limiting sizes for the above men- tioned items is; 1300 - 4000 lines per file, 256 - 512 characters per line, 63 - 256 charac- ters per global command list, and 64 characters per file name. FILES /tmp/etm? temporary /etc/msh to implement the "!" command. SEE ALSO -- DIAGNOSTICS "?" for any error BUGS -- OWNER ken, dmr, jfo