notes

Things I've written down that I might want to reference later.
Log | Files | Refs | README

using-ed.md (3090B)


      1 # Editing with `ed(1)`
      2 
      3 If you're at all insterested in UNIX, you've surely run across mention of `ed`, and maybe you've even tried to use it. After all, it [is the standard editor](https://www.gnu.org/fun/jokes/ed-msg.html). If you've tried it, you probably thought it was a relic. Hokey religions and ancient text editors are no match for a good IDE at your side, right?
      4 
      5 But writing and editing in `ed` can be fun and, indeed, fast! It's a great program for taking notes. Since, unlike modern apps like `vi` and notepad.exe, it's not exactly fast to get out of edit mode, once you start typing, you're encouraged to just keep going! Additionally, since `ed` doesn't work on characters, but instead on lines, it encourages you to think of what you're writing in terms of blocks of text, rather than characters.
      6 
      7 ## Okay, you've sold me. How do I actually *use* this thing?
      8 
      9 That's the great part, if you know how to use `vi`, you already know how to use `ed`! This is because `vi` was started as a visual mode for `ed`. Pretty neat, huh? So, to get into insert mode, you do the same thing as in `vi`, and type `i`. Then `enter`, which I suppose you don't have to do in `vi`, but what's one extra key? Start typing, and when you're done, put a single dot (`.`) on a line by itself to get out of insert mode. Other commands are similar. `/` to search, `c` to change (But remember: `ed` operates on lines, not characters!), and `wq` to write and quit.
     10 
     11 So that's the basics, learn that and you're well on your way to `ed` mastery! Need to replace a word in the middle of a line? Well, use `sed`-like syntax to do that. Let's examine that. Say I have a block of text, "Henlo world." Oops! I meant to type "Hello world." Easy enough:
     12 
     13     s/Henlo/Hello/p
     14 
     15 "Wait," you might say, "I've seen this syntax before!" Well, I did just tell you this was `sed` syntax, right? A lot of programs use it with the assumption that you're familiar with it already. 
     16 
     17 ## What about spell check?
     18 
     19 What about it? Your system probably already has `aspell(1)` installed, so why would you want an editor that includes yet another spell checker? Just use the one you already have!
     20 ## Some other things you might want to know
     21 
     22 Okay, so here's one of my favorie things about `ed`. If I'm writing, but then notice an error on a previous line, I can simple exit insert mode (`ret+.`) and then address the line I want to change, for example: `29s/foo/bar/p`. This moves to the 29th line, replaces the first occurance of `foo` with `bar`, then `p`rints the line so I can see what I did. If I'm happy with the edit, I can just type $a` to resume typing at the end of the file. `$` returns to the last line of the document, and `a` tells `ed` to append (That is, put this text on the next line). 
     23 
     24 What to print the last n lines? `$-n,$p`.
     25 Need line numbers? Replace `p` with an `n`.
     26 
     27 `ed` is so very useful, even today. `ed` is fast, and likely has (when combined with your other system utilities) all the functionality you could want! `ed` is fun, `ed` is the standard editor.
     28 
     29 using-ed.md
     30 
     31 2019-09-26 | First published.