
Actually using ed (2012) - cyborgx7
https://sanctum.geek.nz/arabesque/actually-using-ed/
======
mojoe
Ed is the standard text editor.

[https://www.gnu.org/fun/jokes/ed-
msg.en.html](https://www.gnu.org/fun/jokes/ed-msg.en.html)

------
noobermin
1) Install rlwrap, which wraps readline around any stdin stream.

2) Save this as something (I call it `rled`)somewhere in your path:

    
    
       #!/usr/bin/env bash
       [ !  -n "$(which rlwrap)" ]  && echo "rled: no rlwrap found"  >&2  && exit -1
       rlwrap ed $@
    

Now you can use ed with readline which allows line navigation, insertion and
history.

------
ezequiel-garzon
Hey everyone! I actually use ed almost daily, and at some point I'd like to
put up a website devoted to ed oddities. I found in some book that ed was used
in the 80's as way to test how fast college students could learn a new
technology, under the safe assumption that those students hadn't used ed
before. I'm now much more careful when it comes to bookmarking these things,
since ed and Google really don't get along, but I lost track of that book or
publication. Does anybody know about the study I'm referring to? Any other
oddities would be welcome. Thanks in advance.

~~~
noobermin
ed is a god send. Often times, I want to edit a file but don't want to have an
editor overwrite the whole screen because I need what was previously printed
to edit. When streams aren't enough, ed does the job.

Another psychological thing, it's like exiting a room and forgetting what you
were supposed to remember in that room. When an editor takes over the whole
screen, I feel a little mental context switch that I have to sort of fight
(like having to go back into your memory once you leave a room)while ed seems
like less of a break in context since it doesn't wipe the screen. That's my
feeling at least.

~~~
ezequiel-garzon
I agree. Ken Thompson put it like this:

> I don't want to see the state of the file when I'm editing.

In my case at least this is mainly the case for quick edit, though he probably
felt this way in general.

A full account by George Coulouris about em, a visual enhancement of ed, is
more enlightening:

> By the way, 'em' stands for 'editor for mortals' \- I christened it that
> after Ken Thompson visited our lab at QMC while I was developing it and said
> something like: "yeah, I've seen editors like that, but I don't feel a need
> for them, I don't want to see the state of the file when I'm editing".

[1]
[http://web.archive.org/web/20080103071208/http://www.dcs.qmu...](http://web.archive.org/web/20080103071208/http://www.dcs.qmul.ac.uk/~george/history/)

------
dgacmu
I once became surprisingly good at using ed because it was the editor
available in a MUD environment (LPMud). I think that was in '92.

Shockingly, the MUD (3kingdoms) is still around, though I suspect they've
moved on from ed.

~~~
shabble
likewise, although it rapidly got the boot when I realised there was ftp
support and I could just do things locally.

Still found occasional use in tiny little fixes, but never super comfortable
using it.

------
kalleboo
> If you’re using any Unix at all, then ed really will always be there, no
> matter how old or limited the system.
    
    
        kalleboo@Synology:~$ ed
        -sh: ed: command not found
        kalleboo@Synology:~$ vi
        ~       VIM - Vi IMproved
    

ah

Snark aside, it's a very well-written tutorial! I'm sure I'll end up referring
to it at some point in the future.

~~~
HCIdivision17
> Well, unless you’re using Arch Linux.

I would love to know if you're using Arch Linux? There's got to be a good
story about why it's not there, if not. Might be fun to hunt down if so (I
like historical stories about that sort of decision making).

~~~
bananaoomarang
Going purely off memory here, but I think the discussion on the mailing list
went something like:

Why do we include multiple text editors by default?

Good point let’s just pick one for the base install.

Obvious choice is Vi not Ed because more people are familiar with the former.

~~~
abecedarius
ed has seen use in scripts -- for example, in Kernighan & Pike's _The UNIX
Programming Environment_. `diff` can output an ed script to perform a patch,
and that's what people used before `patch` was invented to make patching more
robust. I'm surprised you can't rely on ed being present.

~~~
david-given
I'm working on a codebase right now which uses ed a lot in scripts. I probably
wouldn't write new code which used it --- I like awk --- but it actually does
the job pretty well.

Admittedly, the code does date back to 1984 in places.

------
tylerneylon
I re-wrote ed in C once for fun:

[https://github.com/tylerneylon/ed2](https://github.com/tylerneylon/ed2)

It uses the regex and readline libraries, as well as some container data types
(array/map) called cstructs. The main C files sum to around 1,000 lines. It
was an interesting exercise in learning some of the pieces of building a text
editor.

~~~
mcguire
The code for a simple ed-alike is one of the chapters of _Software Tools_ by
Kernighan and Plaugher. For entertainment value, here's a version in Haskell
(using Parsec to parse regular expressions (!)):
[https://www.crsr.net/Programming_Languages/SoftwareTools/ch6...](https://www.crsr.net/Programming_Languages/SoftwareTools/ch6.html)

~~~
codygman
I'm confused at why the Haskell version is implied to only have entertainment
value.

~~~
mcguire
No one is using it, nor has anyone ever done so. I learned about Haskell, but
I have rarely used that, either.

------
simonh
ed was the first Unix editor I ever learned, back in 1991. The first terminal
I was given in my first job didn't support screen control commands so I could
only use line oriented commands such as ed. I got so used to it I still use it
occasionally to this day just from habit, though I do now mainly use vi. I
occasionally use it in scripts using 'here' documents.

~~~
kps
Similar here — the system didn't initially support uncooked input. I don't
still use it, but my vim idiolect is still heavy on regular expressions.

------
Annatar
ed is perfect in shell scripts:

    
    
      % cat <<- _EOF_ | ed -s filename
          ed commands...
      _EOF_
    

works on all UNIX-like operating systems and it means that temporary files are
no longer necessary. (GNU sed -i is an architectural violation of the idea of
a _stream editor_ , and it isn't available everywhere.)

~~~
kovek
It is unclear what this tries to achieve. Could you please explain why this
removes the need for temporary files?

~~~
Annatar
If you want to perform an in-place edit, and you want to do it in a portable
manner (not using GNU sed -i), you'd have to use sed with at least one
temporary file:

    
    
      % sed -e 's/something/other/' somefile > /tmp/temp.$$ && mv /tmp/temp.$$ somefile
    

now, using ed (or AWK) and the heredoc with ed commands above, you can mmap(2)
the entire file into memory, perform desired editting, and write it all out in
one go. No more temporary files!

------
tyingq
MS-DOS had the similarly frustrating line-at-a-time edlin:
[https://en.wikipedia.org/wiki/Edlin](https://en.wikipedia.org/wiki/Edlin)

~~~
sevensor
Edlin was my first text editor! I used it to write BASIC programs for my
parents' 286\. Fond memories.

------
mbrock
I like ed for simple editing tasks like deleting a range of lines,
substituting words, etc.

For a while I maintained an HTML blog only with ed, as an experiment... It
really forced me to get used to regexps ranges, thinking before I do stuff,
etc...

------
qwertyuiop924
I've used ed. To write Lisp. Yes, really.

It's by no means my favorite editor (You couldn't convince me to use vi - even
the original vi, with its excellent support for Lisp: do you really think I'll
drop emacs for ed?), but it's usable, and it works.

------
dazmax
Is ed where the slash for regex matching originated or does it go back
farther?

~~~
kps
Close; it was one of the Bell Labs versions of QED — [https://www.bell-
labs.com/usr/dmr/www/qed.html](https://www.bell-labs.com/usr/dmr/www/qed.html)
— I suspect but am not sure that Ken Thompson's CTSS version, that introduced
regular expression text editing, used slash. The original Deutsch/Lampson QED
used colons or square brackets for searches (fixed strings, not regular
expressions) but did use slashes as the substitution delimiter, which may have
inspired Thompson to use the same character for both search and replace.

~~~
cylinder714
Does QED source code exist anywhere? A senior developer at SCO gave me a copy
of the manual years ago but I've never had an opportunity to try it.

~~~
kps
I'm not aware of any.

------
michaelsbradley
Since bash doesn't provide a prepend operator, I define a shell function for
that purpose, making use of ed, without need for a temp/intermediate file:

    
    
       file_prepend () {
           local ed_cmd="1i"
           if [ ! -f "$2" ]; then
               touch "$2"
               ed_cmd="a"
           fi
           printf '%s\n' H "$ed_cmd" "$1" . w | ed -s "$2"
       }

------
dwhabcdefg
IIRC the TRS-80 Model III had a similar single-line editor. Once my little
fingers knew all the commands, it was pretty efficient.

------
blablabla123
It's not installed on my Android :(

------
Gruselbauer
I love OPs tutorials. If you're reading this, you taught me a _lot_ , thank
you.

------
yiyus
ed is nice, sam is better:
[http://man.cat-v.org/plan_9/1/sam](http://man.cat-v.org/plan_9/1/sam)

~~~
deadpixi
A version of Sam for X with scalable font support no Plan 9 dependencies:
[http://GitHub.com/deadpixi/sam](http://GitHub.com/deadpixi/sam)

------
avhon1
The first advice (using "h" or "H") doesn't work on Arch's version of ed. It
does work on red, which actually a script that calls sed.

------
tscs37
I might actually do that, mostly because I really only do quick edits on the
console 99% of the time.

------
fnj
> unless you’re using Arch Linux

pacman -S ed

~~~
sevensor
I think the article was trying to say that you're not absolutely guaranteed to
have ed on Arch. Although pulling it in as a dependency is almost unavoidable
if you're actually trying to do anything, so you have a fair point.

~~~
lucb1e
My Debian also doesn't have it, though I can't guarantee not having manually
uninstalled it (I also uninstalled nano for example).

I think vi is a perfectly sensible choice as the always-there editor.

~~~
OskarS
Why did you/would you uninstall ed or nano? It's not like they're taking up a
lot of disk space. I mean, I don't ever use them either, but they're not
getting in my way or anything.

~~~
kbp
ed is used somewhat commonly by other programs too, so uninstalling it can
break things.

~~~
koenigdavidmj
If they do then they should have a package manager dependency, or that's a bug
with the distribution.

~~~
kbp
If you get 100% of your software through the package manager, sure. If not,
then manually uninstalling things that have been standard on Unix since
version 1 isn't very smart.

------
selektah
I like jed.

------
cyborgx7
To whoever edited the title: I appreciate the addition of the year, forgot to
do it when I submitted the story. But I do think the "Actually" is an
important part of the title and should be put back in.

~~~
sctb
As someone who actually uses ed, I sympathize. We've put it back.

~~~
cyborgx7
Just to avoid a possible misunderstanding, I didn't write this article, I just
found it wanting to learn ed. Thanks for putting it back.

------
jlebrech
now if there was a siri for ed we wouldn't need vim, you could just ask it
"how do i ..?" and before you know it you're not asking it anymore you're
ed'fuing everywhere.

~~~
swiley
An ed for siri would be more intieresting. I feel like siri is eventually just
going to be the iphone's version of bash.

