Ken Thompson built Unix's core text editor in just one week
In 1969, Ken Thompson sat down to write a text editor for the fledgeling Unix operating system. Borrowing ideas from the earlier QED editor, he created 'ed' in less than a week. Designed for slow teletype terminals that printed on physical rolls of paper, ed kept output to an absolute minimum—often responding to syntax errors with nothing more than a cryptic question mark.
The Mechanical Constraints of Paper Terminals
In the late 1960s, interacting with a computer was not an experience mediated by glowing cathode-ray screens or fluid cursor navigation. Programmers interacted with systems through electromechanical teleprinters, most notably machines like the Teletype Model 33. These devices functioned like automated typewriters, physically striking inked ribbons against continuous rolls of paper to record input and output. Data transfer rates over serial connections were excruciatingly slow, frequently limited to 110 baud—roughly ten characters per second. Every keystroke, error message, and printed result was permanently stamped into paper at a mechanical crawl.
In such an operating environment, the modern concept of a full-screen text editor was impossible. There was no video memory to refresh, no cursor to reposition across a two-dimensional grid of text, and no backspace key that could erase ink already pressed into paper. If an editor were to dump an entire file to display a change, it would consume physical paper and keep the user waiting while the teleprinter chattered away. Interactive software had to treat output as a scarce resource. Programmers required tools that operated with extreme minimalism, altering text held invisibly in memory while generating the absolute minimum amount of printing.
From Multics and QED to Unix
Before creating Unix, Ken Thompson worked on the Multics project, an ambitious time-sharing operating system developed collaboratively by MIT, General Electric, and Bell Labs. While working on Multics and its predecessor CTSS, Thompson encountered QED, an interactive line editor originally designed by Butler Lampson and Peter Deutsch for the SDS 940 system. Thompson took an interest in QED and reimplemented it, adding pattern-matching capabilities based on regular expressions—translating theoretical mathematical concepts from logician Stephen Kleene into practical text-processing routines.
When Bell Labs withdrew from the Multics effort in 1969, Thompson, Dennis Ritchie, and other researchers found themselves without a modern computing environment. They acquired a surplus Digital Equipment Corporation PDP-7 minicomputer to build their own operating system, which would evolve into Unix. The fledgling platform needed a core tool to write and modify source code and system files. In less than a week, Thompson wrote ed. He drew heavily upon the design of QED, ruthlessly pruning its syntax and feature set so that it could run within the modest memory of the PDP-7 and operate efficiently over slow teleprinters.
The Mechanics of Line Editing
At the core of ed is a strict separation between persistent storage on disk and active text manipulation in memory. When invoked on a file, ed reads the file's contents into an internal memory workspace called the buffer. The underlying file remains unchanged until the user explicitly issues a command to write the buffer back to disk. Within the buffer, text is managed as an ordered sequence of discrete lines. The editor tracks an internal pointer known as the current line or "dot" (represented in commands by a period), which serves as the implicit target for operations when no explicit line number is provided.
The interface relies on modal editing, separating command input from text entry. In command mode, ed interprets single-letter directives followed by a carriage return. These commands can be prefixed by line numbers, ranges, or search patterns. Typing d deletes lines, p displays text on the terminal, and s performs string substitutions. To insert new content, the user enters an input mode using commands like a for append or i for insert. The editor then stops evaluating commands and absorbs every keystroke into the buffer until the user enters a single period on a line by itself, which returns the session to command mode.
The Eloquent Question Mark
Perhaps the most famous design trait of ed was its uncompromising terseness when handling mistakes. In modern environments, applications provide verbose messages explaining what went wrong and how to fix it. In ed, when a user entered an unrecognized command, supplied an invalid line address, or wrote a malformed pattern, the editor responded with a single question mark: ?. The teleprinter would advance the paper, print the character, and return to an empty line, leaving the user to deduce what had failed.
This silence was an intentional design decision driven by hardware realities rather than user hostility. Detailed error descriptions took seconds to print over a 110-baud connection, wasting paper and ink while interrupting the programmer's workflow. An experienced operator usually knew why a command failed the moment it was rejected. Later iterations of Unix introduced concessionary features: the h command, which printed an explanation of the most recent error, and the H command, which toggled an automatic explanation mode. Even so, the default behavior remained the silent ?.
Regular Expressions and the Birth of grep
Thompson's decision to embed regular expressions into ed transformed text processing across the entire Unix ecosystem. Users could search and transform lines based on patterns rather than fixed strings. Within ed, global operations across the entire buffer followed the syntax g/regular_expression/command. A user wishing to find and display every line matching a pattern would enter g/re/p—directing the editor to globally search for the regular expression and print matching lines to the terminal.
This particular sequence was so widely used to inspect files that Thompson extracted the regular expression matching engine from ed and packaged it as a standalone command-line tool. He named the program grep, directly adopting the letters of the ed idiom. The extraction of grep helped establish the foundational Unix philosophy: small, single-purpose tools that do one thing well and can be chained together. A similar path led Lee E. McMahon to develop sed (the stream editor), which repurposed ed's editing syntax into a non-interactive tool designed to process continuous streams of data in pipelines.
The Enduring Lineage of ed
While modern developers rarely use ed for writing software, nearly all ubiquitous Unix text editors descend directly from its lineage. In the 1970s, George Coulouris developed em ("editor for mortals") at Queen Mary College to make ed more accessible on visual displays. Bill Joy at the University of California, Berkeley, built upon em to create ex (the extended editor), which introduced a full-screen visual mode invoked by typing vi. Modern tools like Vim retain the same command syntax, substitution rules, and regular expression patterns that Thompson laid down in ed.
Beyond its descendants, ed itself remains an active standard. The POSIX specification requires ed to be present on any compliant operating system. Because it does not rely on cursor-addressable terminals, terminfo databases, or complex terminal emulations, ed functions reliably in stripped-down recovery environments where full-screen editors fail. When a system crash, broken terminal configuration, or damaged filesystem leaves an administrator with only a basic shell prompt, the compact editor written in a week remains capable of modifying critical system files.
Key takeaways
•Ken Thompson created ed in 1969 for the early Unix operating system on a PDP-7, adapting concepts and regular expressions from the earlier QED editor in less than a week.
•The editor's famous terseness—such as printing only a '?' on errors—was an intentional optimization for slow, 110-baud paper teleprinters where output wasted time and physical materials.
•The ed command syntax 'g/re/p' (global regular expression print) was directly extracted to create the standalone Unix utility grep, while its command grammar formed the basis for sed and vi.
•Because it does not depend on terminal capabilities or display libraries, ed is mandated by POSIX standards and remains a crucial fallback tool for system repair.