@eris Do you want to know how line editors work, or do you want to know the most important features from a user's perspective?
@eris I'll talk about how I use "ed".
When programming, I rarely type a new line from scratch, instead I copy an old line with "t" and then modify it by regex replacement "s". This means I never have to manually count leading spaces.
If you want fewest possible commands, make copy "t" and delete "d", and don't bother with move line "m", it is rare.
Search "/" is SO important for navigating. Don't expect people to memorize line numbers, which will be changing constantly. I search for landmarks, like section headings that I know live in a particular place.
Avoid absolute line numbers. Anyplace that supports an absolute line number (like 1234) should also support a relative line number based on current position (like -5 or +5) and a search based on current position (like /foo/ or ?bar?)
For writing prose, I don't wrap to 80 columns because it's such a pain to re-wrap it when making edits. So the max line length should be unconstrained.
Does this help?
@devinprater I don't use ed as a primary editor. It is usually not the right tool. That said, it leads to a different way of thinking, which can be useful sometimes.
When I prepare pull requests in ed, I am always thinking about how to make my change as small as possible, because typing and editing has a real cost. It is the opposite of vi, where making massive bulk changes is super fun so I edit more than I should.
@psf I guess I just have to use it more. Line editing is just, so different than anything I've ever used before, even VIM.
@devinprater If you are already comfortable with Vim, try dropping into ex-mode with "Q". This puts the editor into a line-oriented mode where you can quickly enter a lot of Ex commands. Which is just another name for the colon-prefixed commands that you are probably already familiar with, like :w and :q.
This lets you use Vim as a strangely powerful line editor that just happens to allow switching back to screen mode if needed.
The Ex command is very nearly a straight superset of Ed. This is how I learned Ed.
@eris Okay, so in ed, each editing command takes a range prefix. Here is an example.
d = delete the current line
10,15d = delete line 10 through 15
-5,+5d = delete five lines before current and five lines after current
?foo?,/bar/d = delete backwards to the line containing foo, and forwards to the line containing bar
Does this make sense? This is the only reason ed is usable with large editing tasks... otherwise you'd be stuck doing everything one-line-at-a-time, which is very laborious.
There's also the g command, which works like this:
g is a special command that collects all the lines matching /regular expression/, and lets you run a command on all of them.
"d" is the delete command, so g/re/d would delete all lines containing re.
"p" is the print command, so g/re/p will print all lines matching re. Which incidentally is how the unix grep command got its name.
The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!