I like ed(1) for its simplicity and hidden power. But, as an Emacs user, I miss the endless hours spent on customization of my editor. I want to customize ed too! Maybe I can even spend more time customizing ed than actually using it! This post is my attempts at making ed more personal and accomodating.
BSD, GNU, Mac, Plan 9, or one of the dozens of ed forks? Take your pick and enjoy some killer features these might offer! And customize your implementation, if it gives you some customization space.
(No, I'm not considering patches to ed itself. Though that might be quite fun!)
I'm using GNU ed, so my non-portable customizations will be specific to it.
You can run ed with a line printer. You can run it in a terminal. You can run The Standard Editor™ in a graphical environment. You can run it in Emacs. You can run it on your phone!
Depending on the environment you use, customizations might differ. I'm mostly using ed inside terminal emulators, like suckless st and Emacs (e)shell. My non-portable customizations will be specific to these.
GNU ed provides some flags to pre-configure ed:
Other options are less useful, but do check them out anyway. Here's how my customization started:
ed -vG file
Some people may say there's only one customization point in ed: its prompt. You can set the prompt text to... any text! Want a Christmas vibe? Set it to Christmas tree! Want to show some love? Use purple (or whatever color you prefer—I like black hearts) heart! Want to pretend your ed is ex? Set the prompt to a mere colon!
Setting the prompt to random chars is fun and I tried many!
But we can use some non-portable hacks, like ANSI sequences! I like indian red, so I colored my prompt black on red:
ed -vGp "[30;48;5;210mPROMPT[0m"
You can go much further than that, though! It's just that I'm relatively boring. Here's a comprehensive listing of ANSI Escape Codes for your prompt engineering 🥁
When I moved to Arch, the default Bash prompt was quite nice.
User, hostname, and the current directory name:
With it, my prompt looks like
That's when ed fundamentalists (like me) will reach for their pitchforks.
ed should not be visual and immediate.
You're not supposed to edit your commands.
You need neither history nor completion.
Your prompt must be static.
Filtering the printouts is extraneous.
Right?
Still, I like
GNU ed has (heretical)
POSIX specifies that ed should pay attention to
Again, cheating by extending the scope.
But what if you run ed under tmux or GNU screen?
Or with a mere tabbed terminal emulator?
This way, you can open several files and work with their contents in parallel.
Maybe even copy-pasting between the screens/tabs.
Maybe setting the keybindings to some ed-specific actions, like
The next step is obvious:
No, that's too much.
Even though I have a Lisp-oriented ex/vi config.
Too much.
No.
But!
I'm thinking of writing my own front-end for ed.
Maybe using HTML&JS, because that's the most portable GUI there is.
And ed is quite suitable for the editing back-end role!
Time to wrap this all into a script.
So that I (and you) can reuse this configuration.
And improve it.
Here's the script:
scripts/aed.
(For "aartaka's ed", if you haven't guessed already.)
r !pwd
HASH() Replace HOME with tilde
g|^/home/aartaka/*$|s//~/
HASH() Remove prefix dir
g|/|s/.*\///
s/$/:/
p
Q
Using Readline
rlwrap -crq "/|" -H "$HOME/.ed_history" ed -vGp "[30;48;5;210m$dirname:[0m" file
Copy-Paste?
Localization
Multiple Files/Buffers?
Using a front-end like vi
Reusing My Customizations