MAKING FRIENDS WITH ED(1) For the past two weeks I have been using ed(1) as my primary text editor at work. Previously, I used a very nearly plainly configured Emacs. The switch is owed to a few of my favorite characters on an IRC server I visit. They often post ed(1) commands alongside commands to use ed(1). For a long time I thought they were joking. Finally after they said "use ed(1)" for the bah-zillionth time I obeyed... I build WordPress websites. Code I write is in PHP or JavaScript, markup in JSX or HTML, package definitions in JSON, and stylesheets in SCSS. To my surprise, ed(1) performs well within each of these contexts and its related workflows. Although ed(1) takes very few commands they can each be very powerful. I have quickly learned how to adapt commands to the given syntax. It is nice being able to do this without learning a new "mode" or set of keystrokes... ed(1) is a line editor. A given file is modified through the accumulation of many commands. If I were very good at programming I might be able to use just one ed(1) command, `a', which appends all subsequent lines to the given file. But I make mistakes, generate new ideas, and refactor code over time. So I also make use of "c" (change), "i" (insert), "p" (print line), and "s" (search and replace) quite a bit. Initially I used these commands in a rather straightforward manner, like rewriting an entire lines with "c" to fix a single typo. Now I am more nimble. I get ed(1) to surgically target text using "s". I perform sequences of commands using "g". Incidentally, an efficient ed(1) programming experience is aided by other tools. In keeping with the spirit of UNIX (do one thing well), ed(1) does its one thing well without eclipsing the purpose of other programs. Happily, I have become a frequent user of: - less to view files - sed to search and replace - grep to find files containing certain strings - find to run many commands over many files - git to take risks without consequence When I used Emacs to code it was my only friend. I did everything inside Emacs. With ed(1), I have widened the social circle and I am glad for it for two reasons: my knowledge of the standard tools has improved; and, my workflow has become modular (I can easily swap one program for another (bat for cat, say)). Another new perspective brought by ed(1) is: there's a cost to every keystroke--either when it is first made or when it is future changed. ed(1) helped me tangibly grasp that cost, so now I challenge myself to keep it cheap. (Sometimes cheap means sloppy, poorly indent text that gets prettified by a linting program). Editing with ed(1) is efficient. I feel more oriented towards following logically sequential programming operations. I'm no longer gallivanting around buffers, wobbling my way over to some line or character I need to add or edit. ed(1) keeps me on task. The line editing style of ed(1) encourages me towards an economy of keystrokes and operations---I only run commands when I can anticipate the result. Further, my brain is uncluttered by configurations, complicated keystrokes, or a plethora of commands. Like a good friend, ed(1) is growing alongside me. I feel our conversations reaching greater depths and eloquence. And I know still more interesting chats lie ahead! Favorite commands so far ---------------------------------------------------------------------- `!less -N %' to view the current file in less. `s/some pattern/\' to split a line. `/some pattern/s/some pattern/a replacement' to replace all matches in a file. `G/some pattern/' to interactively replace. `10z20' to print the 20 (or some other number) of lines from 10 on. `.t.' to copy the current line. |