One of the superpowers of ed is the ability to run shell commands from within the program, letting the user modify and manipulate the buffer on the fly. In fact, this superpower allows ed to be Turing-complete. But most of us mere mortals need only less cutting-edge powers when it comes to ed use. Say you've opened a file and realized (before you modify the buffer) that you want to backup the original. There are two ways to do this:
A quicker way to do this may be:
Or say you want to check and see what changes you've made in the buffer since the last time you saved your file. (You do use "w" to write your changes periodically so that they're not lost, don't you?) Try this:
Want a little bit of grep-like context for a search term? Try:
Is your screen getting cluttered with the results of searches and substitutions? How about clearing the screen and re-printing your file from the beginning?
If you want to get really fancy, you can use the trick "LoomisTook" has in his YouTube video and write a shell script called something like "cl" or "clr" which clears the screen, then uses an echo or printf command to put a 80-character-wide ruler at the top.
Or you can just forget the whole ruler-thing and make sure your text is formatted to 80-characters wide by issuing this command when you're done modifying the buffer:
If you set a mark (by typing kx or ka or k-and-any-letter-of-the-alphabet) before you clear the screen, you can just print from that point forward in the text with the following command:
Ed is a line editor: it edits an entire line at one time, making word-changes within lines a bit of work. However, adding text to the end (or beginning) of a line isn't hard:
If you want to change text *within* a line, you can use the substitute command. To add words within a line, one easy way is to use "&" which represents the search term within the substitution. For example:
The first substitution would replace "this and" with "this and that." The second would replace "read" with "reading."
I'm still not convinced that the ed editor would work well for some lengthy writing, such as a novel; but for scripts and even more involved things such as this web-page, it's more than adequate.
~~~~~~~~~~~~~~~~~~~~~~~~~