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.
Cool! I used BSD ed (OS X) exclusively for a few months but I stopped because of a few things that were too clunky for me.
Wrapping text: I used fmt all the time. But you can't pipe text straight through fmt, so I ended up doing this a lot:
3w |fmt>fmt # create a file called fmd in cwd
3r fmt
3d
Which is OK if you have just one line to wrap. If there are newlines in the text you're wrapping, you have to remember the line numbers of the unwrapped text (or use ka, kb) to delete them.
Inserting text in the middle of a line. Either use s// (which is annoying if your inserted text has a lot of slashes) or split the line, add an in between line with the new text, and join.
Then use a or i to insert a line. Then join three lines with j. It gets old after a while.
And then there was my false hope that I learned a universal editor that was everywhere. Except GNU ed is not BSD ed is not OpenBSD ed is not Solaris ed.
Anyhoo, would be fun to read how someone who stuck with it (unlike myself) uses ed.
Thanks for sharing! I should admit I don't do any professional work with text editors (hopefully some day!), and if I ever do ed will likely not be my main editor. Just so you know, you can use most non-blank characters for substitutions. Personally I tend to use commas, as somebody else mention in the comments. If I see commas in the expression I'm about to replace I go for slashes or pipes.
It's interesting you mention inconsistencies across implementations, even more (I assume) going from BSD to GNU ed which unsurprisingly is almost a superset of features with heretical commands such as yank (!).
BSD tends to stick more to POSIX, so issuing just `t` won't duplicate the current line, which I've grown used to. I also like the paging command `z`, which seems to have been adopted by all major implementations. I'm sure Ken would find all of this bloatware!
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.
> 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".
I'm not sure if you use tmux, but the way I do it is to open a new pane below the original, edit what I need to, and then close that pane when I'm done. The original screen remains untouched.
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).
Aww. That's not terribly interesting at all. I mean, I get it, and I don't doubt it's validity. It's just so... mundane.
I would have thought there'd be utility in having a very small last-resort utility like ed by default. But then I don't use Vi much (or ed, normally I'm just touching up a file from the command line, so I use nano), so perhaps I'm out of touch.
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.
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.
It's not just Arch. I used to think ed was everywhere, so when I had to write some scripts that would be awful with sed I used ed.
And then it turned out that a lot of the platforms people run the scripts on, they had to install ed explicitly! Ha. Sorry, Arch/Debian/Fedora/Centos/OpenSUSE users.
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.
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...
Given that readline is basically a line-oriented version of emacs (or vi, if you set the config), it sounds like you actually wrote a readline editor with an ed-inspired UI.
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.
% 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.)
I routinely automate text-mangling tasks with short ex (most of them would probably work in ed, too) scripts. I find it simpler than using sed, most of the time. If you're comfortable using ex commands in vim, then it's almost a seamless transition
FreeBSD found out it is not perfect since they had to patch patch because it called ed. People figured out how to run arbitrary scripts in a privileged manner.
patch(1) outputs ed(1) commands. It always worked that way, and it demonstrates the power of the "do one thing and do it well": patch just does the analysis and generates the appropriate editting commands, but the editting is passed on to a program specialized for just that: ed(1). It as also a good showcase for UNIX modularity principle.
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:
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!
sponge is found on GNU/Linux, but is not a UNIX standard; when writing shell programs one must never assume GNU/Linux, because, as my ed(1) example shows, it is completely unnecessary and makes the code unportable for no reason whatsoever.
Also by relying on external tools, you have now forced your users down the dependency hell path.
Assume the environment you're writing scripts for. Most scripts need only be run on one machine, and thus one platform. Most that don't still run only on one platform. If you need a portable shell script, by all means write one, but that's rarely the case.
The clean / portable way is in my experience always simpler, or rather, more rudimentary than using unnecessary GNU/Linux-only commands and constructs, simply because the clean / portable methodology uses the lowest common denominator.
If you know of, or have such a case, I would be really interested to see it, out of purely professional interest.
Nobody wants to debug shell scripts.
I want to debug shell scripts, because of all the debugging I've done over the years, shell script debugging is by far the quickest / easiest:
DEBUG="${DEBUG:-false}"
$DEBUG && set -x
and one can see the machine state immediately. Best debugging experience by far.
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...
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.
Close; it was one of the Bell Labs versions of QED — 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.
You can use any character instead of / there. I prefer comma as its easier to type IMO. But slash is too and it's quite distinctive and easy to type too.
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"
}
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.
Interesting! I run Arch on a number of machines and your comment prompted me to check my assertion. There are in fact a couple that don't have ed. I think maybe it's often a dependency for more AUR builds? That's the major factor that varies.
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.
Ed? Maybe because I only ever typo into it, but as I said, I don't think I removed it anyway.
Nano... to be honest, mostly to mess with anyone who'd want to use it. There is no need for it to be on my system, at least not for me, so it's perfectly logical to remove it. But an additional reason is that nano is a terrible editor that nobody should use anyway. Might as well open Geany or something with mouse support if they're not going to take advantage of vi keys (I'm talking about my own laptop with a screen anyway).
I could understand getting rid of nano. For some users, apt-get remove might be the easiest way they can think of for not defaulting to having nano called from other applications, as opposed to finding out about the proper way that Debian would like you to use. Most users would likely know about apt-get long before they ever chance across update-alternatives, (or whatever today's editor-default-selection-method-of-choice is, if it's not that anymore).
I suspect that there are a range of user antipatterns due to either not knowing, or not having the time or inclination to lookup this month's correct method of doing some given task, and people will default to using old methods or silly workarounds.
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.
gNewSense is not a Debian version unless they gave sid a name, but this is Debian Stretch. If gNewSense (what a terrible name) is a distribution, they might have chosen to install it for you.
Apologies, I should have clarified: gNewSense [1] is a FSF sponsored distro based on Debian with a freed kernel and free packages (basically the equivalent of Debian main). gNewSense is currently at version 4.0 and based on Debian Wheezy.
lucb1e is absolutely right, in Debian wheezy itself, ed is an 'optional' package and not installed by default from the live iso (wheezy 7.11) I just checked. Just one of those choices people make I guess, or, as others have pointed out above, it might well be a dependency of something that I have installed since on my gNewSense install [2].
The full name of Debian is Debian GNU/Linux; the GNU part stands for "GNU is not UNIX". You have to go to a FreeBSD- or an illumos-
based operating system for UNIX.
Right, well, even on debian.org there is no mention of GNU. For what it's worth, to compensate, I've renamed my Cinnamon system menu to "GNU" (so I have a GNU button permanently visible on the left bottom) because they are indeed underrepresented next to Linux. Only in my /etc/issue I can find "Debian GNU/Linux" but it's still a bit of a mouthful, like saying The United States of North America or something when America is clear enough.
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.
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.
2) Save this as something (I call it `rled`)somewhere in your path:
Now you can use ed with readline which allows line navigation, insertion and history.