Jump to content

Ed (text editor)

From Wikipedia, the free encyclopedia

Template:Short description Template:Lowercase title {{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }} Template:Tt (pronounced as distinct letters, Template:IPAc-en)[1] is a line editor. It was one of the first features of the Unix operating system.[2] Although not commonly used today, it remains part of the POSIX and Open Group standards,[3] alongside the full-screen editor vi.

History

The ed text editor was one of the first three key elements of the Unix operating system—assembler, editor, and shell—developed by Ken Thompson in August 1969 on a PDP-7 at AT&T Bell Labs.[2] Many of its features came from the qed text editor developed at Thompson's alma mater University of California, Berkeley.[4][5]Thompson was very familiar with qed, and had reimplemented it on the CTSS and Multics systems. Thompson's versions of qed were notable as the first to implement regular expressions. Regular expressions are also implemented in ed, though their implementation is considerably less general than that in qed.

Dennis M. Ritchie produced what Doug McIlroy later described as the "definitive" ed,[6] and aspects of ed went on to influence ex, and later vi. The non-interactive Unix command grep was inspired by a common special use of qed and later ed, where the command g/re/p performs a global regular expression search and prints the lines containing matches. The Unix stream editor, sed, implemented many of the scripting features of qed that were not supported by ed on Unix.[7]

The ed commands are often imitated in other line-based editors. For example, CP/M's ED, EDLIN in early MS-DOS versions and 32-bit versions of Windows NT has a somewhat similar syntax, and text editors in many MUDs (LPMud and descendants, for example) use ed-like syntax. These editors, however, are typically more limited in function.

In current practice, ed is rarely used interactively, yet is sometimes used in shell scripts. For interactive use, ed was subsumed by the sam, vi and Emacs editors in the 1980s. ed can be found on virtually every version of Unix and Linux available, and as such is useful for people who have to work with multiple versions of Unix. On Unix-based operating systems, some utilities like SQL*Plus run ed as the editor if the EDITOR and VISUAL environment variables are not defined.[8] If something goes wrong, ed is sometimes the only editor available. This is often the only time when it is used interactively.

Features

File:Man page for Ed text editor screenshot.webp
The man page for GNU ed

Features of ed include:

The GNU version includes options intended to enhance feedback. Using <syntaxhighlight lang="text" class="" style="" inline="1">ed -v -p:</syntaxhighlight> provides a simple prompt and enables more useful feedback messages.[9] The <syntaxhighlight lang="text" class="" style="" inline="1">-p</syntaxhighlight> switch is defined in POSIX since XPG2 (1987).[3]

User experience

Known for its terseness, ed gives almost no feedback,[10] and has been called (by Peter H. Salus) "the most user-hostile editor ever created", even when compared to the contemporary (and notoriously complex) TECO.Template:R For example, the message that ed produces in case of error and when it wants to confirm exit without saving, is merely "?". It does not report the current filename or line number, or even display the results of a change to the text, unless requested. Older versions (c. 1981) did not even ask for confirmation when a quit command was issued when there were unsaved changes.[10] This terseness was appropriate in early versions of Unix, when a console was a teletypeTemplate:Efn, modems were slow, and memory was limited. As computer technology improved and these constraints loosened, editors with more feedback became the norm.

The glibc documentation notes an error code called <syntaxhighlight lang="text" class="" style="" inline="1">ED</syntaxhighlight> with its description (errorstr) merely a single question mark, noting "the experienced user will know what is wrong."[11]

Example

Here is an example transcript of an ed session. For clarity, commands and text typed by the user are in <syntaxhighlight lang="text" class="" style="" inline="1">normal color</syntaxhighlight>, and output from ed is <syntaxhighlight lang="output" class="" style="" inline="1">gray color</syntaxhighlight>.

a
Template:As written
This is line number two.
.
2i
. ,l Template:Codett Template:Codett Template:Codett w text.txt Template:Codett Template:Codett ,l Template:Codett Template:Codett Template:Codett w text.txt Template:Codett q

The end result is a simple text file Template:Mono containing the following text:

ed is the standard Unix text editor.
This is line number three.

Started with an empty file, the Template:Kbd command appends text (all ed commands are single letters). The command puts ed in insert mode, inserting the characters that follow and is terminated by a single dot on a line. The two lines that are entered before the dot end up in the file buffer. The Template:Kbd command also goes into insert mode, and will insert the entered text (a single empty line in our case) before line two. All commands may be prefixed by a line number to operate on that line.

In the line Template:Kbd, the lowercase L stands for the list command. The command is prefixed by a range, in this case Template:Kbd which is a shortcut for Template:Kbd. A range is two line numbers separated by a comma (Template:Kbd means the last line). In return, ed lists all lines, from first to last. These lines are ended with dollar signs, so that white space at the end of lines is clearly visible.

Once the empty line is inserted in line 2, the line which reads "This is line number two." is now actually the third line. This error is corrected with <syntaxhighlight lang="sed" class="" style="background-color:#ffffcc" inline="1">3s/two/three/</syntaxhighlight>, a substitution command. The Template:Kbd will apply it to the correct line; following the command is the text to be replaced, and then the replacement. Listing all lines with Template:Kbd the line is shown now to be correct.

Template:Kbd writes the buffer to the file Template:Mono making ed respond with Template:Codett, the number of characters written to the file. Template:Kbd will end an ed session.

See also

Notes

Template:Notes

References

Template:Reflist

Template:Sister project

Template:Unix commands Template:Plan 9 commands Template:Ken Thompson navbox

  1. ↑ Template:CitationTemplate:Cbignore
  2. ↑ 2.0 2.1 Template:Cite book
  3. ↑ 3.0 3.1 Template:Man
  4. ↑ D. M. Ritchie and K. L. Thompson, "QED Text Editor", MM-70-1373-3 (June 1970), reprinted as "QED Text Editor Reference Manual", MHCC-004, Murray Hill Computing, Bell Laboratories (October 1972).
  5. ↑ Template:Citation.
  6. ↑ Template:Cite tech report
  7. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  8. ↑ Administering SQL*Plus Template:Webarchive. Accessed 7/23/2016.
  9. ↑ Template:Man
  10. ↑ 10.0 10.1 Template:Cite journal
  11. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}