The ed text editor

Short tutorial on the ubiquitous and arcane editor, ed.

by spitemim, 2021-10-01

If you thought exiting Vim was hard, try exiting the ed text editor. Better yet, try doing anything within the ed text editor that doesn’t result in an unhelpful “?” error message. If you are one of the many people in the world who don’t know how to use ed, that’s understandable. However, most of the original Unix source code was written within ed, and knowing how to use it might be useful just in case you find yourself having to write code on a PDP-11 anytime soon.

The ed manpage can be found here, but here’s a summary of the useful stuff.

ed basics

The first thing to remember is that like vim, ed is a modal text editor. It has two modes: command mode and input mode. When first invoked, ed is in command mode and eagerly awaits your commands. One more thing to keep in mind is that ed operates on one line at a time. Most commands only affect the currently selected line. A list of commands is as follows:

Hopefully this is enough for some basic ed usage. If you want to become an ed poweruser, the manpage linked above is a good place to start. Additionally, the documentation for ed may be accessible on your system in the form of a Texinfo manpage. Running info ed may give you access to the ed documentation locallly.

Also, even though it’s linked above, I think it’s worth mentioning again: click here for a really cool in-browser PDP-11 emulator, or click here for my cloned version with dark mode added. The FAQ is really helpful, and the emulator even supports writing your own programs in C or Fortran. It’s really useful for passing the time in boring classes.