NAME
     ed - line editor

SYNOPSIS
     ed [file]

DESCRIPTION
     Ed edits text a line at a time.  It descends from Ken Thompson's editor
     of 1969, the oldest program on this deck by lineage, and it works the way
     it did then: you type a command, it does the thing, it says nothing.  No
     screen is drawn and no cursor moves, which makes it the one editor that
     is usable over a link too slow or too lossy for se(1) or vi(1), and the
     one that will not fight with a slow e-paper panel.

     If file is given it is read into the buffer and the byte count is
     printed.  The buffer is a numbered list of lines; most commands take an
     address or a range of addresses saying which lines they apply to.  The
     current line, written ., is where the last command left off, and is the
     default address for most commands.

     Errors print as ?  followed by a word or two.  This is the whole of ed's
     diagnostic vocabulary.  Typing h prints a summary of everything below.

ADDRESSES
     .    The current line.

     $    The last line.

     n    Line n, counting from 1.

     +n

     -n   n lines after or before the current line.  The number may be
          omitted, in which case it is 1.

     addr1,addr2
          The range from addr1 to addr2.  An omitted left address is the
          current line; an omitted right address is the last line.

     addr1;addr2
          The same, but the current line is set to addr1 before addr2 is
          worked out.

     There are no /pattern/ addresses; search is not implemented.  Use sam(1)
     if you need to address lines by their contents.

COMMANDS
     An address by itself moves to that line and prints it.  An empty command
     line prints the next line, so pressing return repeatedly walks the file.

     a    Append text after the addressed line.

     i    Insert text before the addressed line.

     c    Change: delete the addressed lines, then insert in their place.

     All three read lines from the terminal until a line containing only .  is
     typed.

     d    Delete the addressed lines.

     p    Print the addressed lines.

     n    Print them with line numbers.

     =    Print the line number of the last addressed line.

     s/pattern/replacement/[g]
          Replace pattern with replacement on each addressed line.  Without g
          only the first occurrence on a line is replaced.  Any character may
          serve as the delimiter in place of /; a backslash takes the next
          character literally.  Pattern is plain text, not a regular
          expression: it is matched as a substring.

     w file
          Write the buffer to file, or to the file being edited if none is
          named, and print the byte count.  The first filename used is
          remembered.

     r file
          Read file in after the addressed line and print the byte count.

     e file
          Discard the buffer and edit file.

     q    Quit.  If the buffer has unsaved changes this prints a warning and
          does nothing; typing q again quits.

     Q    Quit without the warning.

     h    Print the summary.

EXAMPLES
     Write a short file from nothing:

          ed
          a
          the crystal is patient
          the network is not
          w /n/local/note
          q

     Fix a line in place:

          ed /n/local/rc/profile
          3p
          3s/8080/70/
          w
          q

     Print the whole buffer with numbers, then delete a range:

          1,$n
          4,7d
          w

INPUT
     While typing a command or a line of text, backspace rubs out a character,
     ctrl-u rubs out the line, and ctrl-d on an empty line ends input.

SEE ALSO
     sam(1), se(1), vi(1), sed(1)

NOTES
     The buffer holds at most 256 lines of at most 256 characters.  These are
     small numbers on purpose; the deck has other uses for its memory.

     Ed talks to /dev/cons directly and takes no part in the shell's
     redirections.

BUGS
     A file longer than 256 lines is read in silently truncated.  Check with
     $= after reading anything you did not write yourself.

     A line that would grow past 256 characters under s is left alone and ?
     line too long is printed.

FRST Computer                                                            ED(1)
