I have been using Ed text editor daily since spring of 2020. Back then I introduced it to my tool belt out of necessity but ever since it has been my goto tool for quick edits and it's going to stay.
For most Ed is a relic of the past. Almost like programming using punch cards. There is just no more need and use for it. It was never convenient and we all are happy that those days are gone. It was the same for me. I don't even remember how I found out about Ed but after quick look into how it works and trying few commands I concluded that there is no way for such text editor to be useful nowadays. Gods like to laugh at such thoughts. So they made an evil plan to prove me wrong. Now I'm a slave to this software.
EDITOR
env var to ed
to use it daily.
rlwrap
to have readline capabilities.
shell-mode
.
Back in 2020 I had an small cheep Virtual Private Serve (VPS). I used it for hosting my website, hosting private and public git server, experimenting with live streams and first projects in C programming language. What I quickly realised was that VPS didn't cost me much money but a lot of time an patience. It was too damn slow.
How slow it was? Imagine Terminal User Interface (TUI) software lagging so much that live feedback they give is no longer ... live. Basically all TUI programs like less and htop where useless. And yes, even the mighty vi has fallen. I was ok with it tho. Most things I did on VPS didn't required actual text editor. I was doing just fine using programs like: grep, echo, sed, head, tail, awk and other similar standard tools that combined with redirection from standard input (STDIN) and to standard output (STDOUT) proved to be very capable. But there comes a time in life of Linux server administrator where toys are not longer enough. I needed a real thing. A text editor used by old grand masters. An elegant weapon for a more civilized age.
That is when I started using ed. Having experienced with vi that even quitting an obscure editor might be difficult I decided to first look into documentation. What I had on VPS was a GNU version of Ed. In practice it means that man page for ed is mostly useless. I had to look into Info page for Ed. For the most part the main Info page section was just a one page with list of commands. And it was short.
I must admit that I did not understood all commands at first. Regardless, with my new knowledge I began to use Ed for my small edits on VPS. And this is how it started.
First impression that Ed gives leaves the feelings of compassion for programmers that had to use it. It must have been so difficult and painful for them. But my experience of using Ed was surprisingly pleasant and it quickly replaced echo, sed, head, tail and awk.
Because it's such small and simple software you can master all commands in 2 hours. I mean - all of them. This is not possible in Vim, Emacs or any other text editor. The initial difficulty comes from our expectations of how text edition should look like. It's yet another case where you first have to empty your cup because it's already full with no space for different concepts.
Having this positive experience I started looking around the web for some Ed articles. This is when I found an demonstration video Ed text editor. My jaw was on the floor. I was blind to wast landscape of opportunities that Ed gives when used with external scripts. It was clear to me now that there are hidden cleaver techniques. A secret knowledge.
I used Ed daily for about 2 months for almost everything trying to reach full potential of editing powers. I migrated my workflows for most things using helper shell scripts that I was invoking from Ed. I even used it secretly at work delivering real Web Dev tasks to production. Life was great.
But it was not meant to last. In the end the complexity of modern data structures and code was a bit too much. Ed is great for line editing but fails short when you have logical structure that starts in the middle of one line and ends in the middle of another few lines later.
There are also many different implementations of Ed. Commands are not always consistent and being a simple software it likes to have constrains. Some implementations do not play well with UTF8, other have line length or file size limits. My overall experience was that Gnu Ed will handle all files but the source code is not easy to edit.
Yes I went as far as building Ed from source code. Adding my own commands and editing existing commands to my liking. In the end, even with custom code, when I had to do serious coding at work I ended up using Emacs again. Few months later I shutdown my VPS. That was the end of Ed for me. Or was it?
Strangely enough, I kept thinking of Ed when using Vim or Emacs.
Many of the text edits I did outside of Ed seemed to me inefficient
and difficult to execute and even slow at times. I had a reflex of
typing zn
or g/TODO/n
. I was a changed man.
I kept going back to Ed to apply global substitution changes even tho
you have exactly the same commands and syntax in Vim. But Ed was
faster.
And then I fond a perfect symbiosis. You see I was using Emacs for
most of my work. And in Emacs you have few terminal emulators,
eshell and shell-mode. The terminal emulators are ok
but for me those break the flow of using Emacs. The Eshell is a
different beast on its own. What I use is the shell-mode. I
love it for a reasons that I will discuss some another time. But the
important thing is that it does not support TUI programs. And I use
programs like Git and Pass.
Both will sometimes ask you to edit a text file. This workflow does
not work great in Emacs Shell as both programs will try to run text
editor defined by EDITOR
environment variable. This is
usually Vim or Nano and both are TUI programs.
Then I had this revelation. I can use Ed as my default value for
EDITOR
environment variable and all those Unix tools will
now succumb to Ed
cult. So I did. And it has been my default editor ever since.
Every git commit, git interactive rebase, pass edit, crontab edits and
more I do in Ed for almost 4 years now. Mostly in Emacs Shell but not
only.
Using Ed in Emacs Shell gives few extra advantages like ease of
navigation, line edition and repeating past commands. In regular Ed
in terminal you can't do that but when used in fusion with
rlwrap ed
program you can unlock Super Saiyan form of Ed.
The rlwrap gives readline capabilities to regular STDIN prompt
in any program. So you can edit line using Emacs or Vim keybinding
according to your readline configuration. It also persist history of
commands in given program between sessions.
With those two things, the default EDITOR
value and
rlwrap, I keep using Ed daily. Whenever I login to ssh session
or I'm on new fresh Unix based system I like to use Ed. Even if there
is an Emacs or equivalent replacement like mg.
BTW to all haters that says Emacs is great OS but lacks an good text editor. Use Ed inside Emacs Shell.
I found out that there are surprisingly many Ed users. This usually comes from the fact that Ed is very simple and can be used for scripting as all commands can be passed to it from STDIN. For example this post Batch editing files with ed by Julia Evans. To which I replied with a small tip and got this response:
From: Julia Evans Date: Sun, 26 Apr 2020 08:25:36 -0400 Subject: Re: About "Batch editing files with ed" To: irek thank you! On Sun, Apr 26, 2020 at 8:25 AM irek wrote: > Hi I just found your article about "ed": > https://jvns.ca/blog/2018/05/11/batch-editing-files-with-ed/ > > I want to point out that comments actually do exists in ed. > They have to be in separate lines. > Taking your script as an example: > > # search for `baz` > /baz > # copy that line and paste it on the next line > .t. > # on the second, pasted, line replace `baz` with `elephants` > s/baz/elephants > # save > w > # quit > q > > Thanks for the article and have a nice day. Bye :) > -- > irek
So one of good use case is to replace crazy sed scripts with Ed scripts. Ed commands are much easier to write and understand than Sed IMHO. I also see some users on tildeverse. Makes sense as sites hosted on Gemini and Gopher protocols are easy to edit with Ed on ssh session.
It feels like Ed will never go away as long as there will be a need or desire for simple tools. Especially those that works in standard CMD fashion taking STDIN and printing STDOUT. Also to me Ed feels more like an idea than one specific software as there are many different implementations. In such small program every small difference feels significant to the user.
I encourage you to give it a go. If you are a Vim/Emacs user then consider that proposing usage of Ed to you feels like when you propose an daily usage of Vim/Emacs to regular Visual Studio Code developer. Maybe you will find a different use case for yourself. Don't hesitate sharing your Ed experience with me sending message to irek (at) gabr (dot) pl if you have any. OFC you should write email message in Ed.
Blog post written NOT using Ed ( ._.)
Last update: April 2024