Of all the editors that exist today, ed is probably one of the worst on paper. When you first load ed you may think it's broken, it doesn't give you any prompt and doing anything will likely cause ed to print a question mark at you. With that said, ed is one of the most useful pieces of software, if you know how to use it.
What is ed
ed is a line based text editor. Before I was alive it was not uncommon for people to do computing tasks with no monitor, just a piece of paper and a typewriter. Using a typewriter, you can't really use vim or vi as those are TUIs which require an interface that always updates so ed was born.
ed takes commands in the form of singular letters, to save on ink. All commands try to output as minimal output as necessary by default. As such, ed does not print the file. For the most part, output occurs only when you are moving to another line (x, +x, -x), you use the "n" or "p" command to print out information, or you mess up a command resulting in an "error message" in the form of a question mark.
How to use ed
Firstly, install ed! Unfortunately, despite being the "Standard Unix Editor", a lot of distros choose to no longer include it by default. Install it with your package manager, usually the package is just called ed. Once installed, you'll want to alias ed purely for your own convinence later.
alias ed='ed -v -p"* " ' # for GNU ed alias ed='ed -p"* " ' # for POSIX edNon GNU users should put the H option in as ed is starting up. The -p option lets users specify a prompt which ed can use. The -v option gives verbose error messages which are useful for figuring out what is broken in your scripts. POSIX can achieve the same by using the H command.
For learning the commands, I recommend looking up ed cheatsheet on google or reading the 1p manual for ed, as that will provide the best documentation. Looking up examples is also quite helpful. That said, if you just need to edit files the basics are as follows:
n - print the line you are on and the line number ,n - print all lines in the file with line numbers on each of them <number> - teleports you to the number <+/-number> - relative to where you are, go forward/backward in the document. Example: if you are on line 70, +5 will bring you to 75, -5 will bring you to 65 i - insert text above the line you are on a - insert text below the line you are on c - replace the current line you are on For all editing commands, a singular dot on its own line will signal to stop inserting text. w - write the changes q - quit (but prompt if you have unsaved changes) Q - quit without saving /re/ - search for the expression "re" in the document, interpreted as a basic regular expression. ?re - same as above, but search backwards s/a/b/ - replace a with b on the line you are on.
Why Should I Use ed
I would be shocked if thus far you are convinced that ed is anything special, especially compared to the vi(m) family of editors. Until around 2-3 days ago I was strictly in that boat, but, there is one thing which makes ed awesome, ed scripts.
ed relies entirely on stdin to get input which allows for common inputs to be stored in a file for future use. Consider, for example, you need to edit a bunch of files all to change really 1 or 2 lines. While it's possible to use sed or a similar program, it can be clunky especially if you need to call sed multiple times or use multiple sed commands, involving the use of semicolons. If, however, you write out the changes in ed, you can then execute them simply by feeding the edscript through standard input and you could, of course, reuse that ed script on several files. This was actually historically how diff worked, you would get an ed script and use that to patch the files before unified diffs and the patch program came around.
"Doesn't vim have this feature"
Reading the man page for vim may lead you to believe that the -w and -s flags would yield a similar but superior result but you would be mistaken. The unfortunate reality is that -s and/or -w are broken, they will garbale a file if they are used as the man page suggests. As such, ed is the only option I know of which supports this feature (ex may support this feature better but I have only ever used ed for this. also emacs probably has a plugin for it, lol).
ed Script Examples
My new page Other Stuff (or /etc) contains a section on ed scripting. It features several real world scripts which I used to create the /etc page on my site. You can also view the scripts directly here.