Up to Main Index Up to Journal for June, 2016 JOURNAL FOR WEDNESDAY 8TH JUNE, 2016 ______________________________________________________________________________ SUBJECT: A quirky little editor DATE: Thu 9 Jun 23:59:16 BST 2016 For whatever reason I often find myself working on hardware that is either slow, low powered or on the end of a really slow connection. More frequently all three. So what do you do in such a situation when you need to edit files? The editor I normally use for ALL of my editing, coding, writing and emails is Vim. If I look at the size of the Vim executable on the desktop I am writing this on I get 3Mb and it uses 65 shared libraries that total 29Mb in size. Once loaded[1] - say while writing this - it's using about 15Mb RAM. Not bad, but not light. There is another editor I use. If I look at the executable for that it's 51K with 3 shared libraries: libc.so.6, ld-linux-x86-64.so.2 and linux-vdso.so.1 which come in at less than 2Mb in size. Editing the same file it's using under 2k of RAM. Quick recap: Editor: Vim Other Size: 3Mb 51Kb Dependencies: 65 3 Library size: 29Mb >2Mb RAM: 15Mb 51kb Note that the number and size of the dependencies are based on the output of the ldd command. Some of the dependencies may have their own dependencies(?). There are also plugins and other file loaded up at runtime for Vim. So what is this mystery little editor? Those who regularly read this journal know I have a predilection for arcane Unix and it's tools and so may have already guessed. The editor was written in 1969 as one of the first parts of the Unix operating system by Ken Thompson. The editor is ed[2]. It is the "standard Unix editor" being the original editor and it is included in nearly every Unix like system being part of the POSIX and Open Group specifications. The particular version I'm using at the moment is GNU ed[3]. ed is infamous for being terse and user hostile. Personally I think that's a little harsh. With practice you can edit quite quickly with it. One thing I do wish it had is better line editing when entering commands and text - odd for a line editor! :) ed works on a single file at a time. It supports regular expressions for making changes and searching. It can be scripted by feeding commands into standard input. The GNU version of ed has a lot of additions which means in theory an ed binary could be even smaller than 51k. A 'standard' ed has about three dozen commands. Here is a command reference table covering versions I have used as well as the POSIX specification version: ed Command Reference -------------------- a - append lines (9) b - browse lines (like z and &) c - change lines d - delete lines e - edit file E - edit file discarding unsaved changes f - filename g - global (BGP) G - interactive global h - help on last error H - toggle help mode i - insert lines j - join lines k - mark line l - list lines m - move lines n - number lines (C) o - change options p - print lines (9) P - alias of p (BGP) P - set prompt and/or toggle prompt on/off q - quit Q - quit discarding unsaved changes r - read from file or command s - substitute t - copy lines u - undo last change v - non-matched global (BP) V - interactive non-matched global w - write to file or command W - append file (BG) wq - write file and quit (G) x - append cut buffer (B) x - prompt for encryption key (G) y - yank lines to cut buffer (BG) z - 'scroll' lines (like b and &) ! - shell escape # - comment (for scripts?) (C) & - print 23 lines (like b and z) / - search forwards (not strictly a command but a line address) = - line number ? - search backwards (not strictly a command but a line address) (C) ? - help on last error (like h) - null command KEY: B-BSD G-GNU P-POSIX specification C-Coherent Unix 9-Plan9 Notice the g (global) command? It takes a regular expression and prints (p command) matching lines. If you write out the command synopsis you end up with g/re/p - this is where the grep utility got its name from :) Why do I bring all of this up? A MUD usually has a 'primitive' text editor built in. It can be used to compose mail if there is an internal mail system. Compose entries for post boards and message boards. It can also be for in-game building. Usually the editor is a lot like ed! If I was to write a version of ed I would make minimal changes. It would handle Unicode and not just ASCII. It would have readline like editing for the current input line. Currently if you start entering 'The quack brown fox jumps over...' and notice you put 'quack' instead of 'quick' you have two options. Delete the text until you get back to the 'u' in quack and then type the text following it over again. Or complete the line and then do a substitution on the line like 's/qua/qui/' to make the correction. You can't even move the cursor backwards to correct a minor typo - you just get '^[[D' displayed when you hit the left cursor key. I also have a bonus wish list item that I think would be very useful. A 'pipe lines to command and append output' option for the 'c' change command - like the 'e','r' and 'w' commands have. This would make it easier for users to pipe text to a command, transform the text in some way and replace the original changed lines with the results. Examples of external tools could be text/code formatters - such as gofmt - and spell checkers. The rest of the editor I would leave alone :) For sheer perversity I would write the editor using only ed - until it was capable of editing it's own source code. Hrm, what would I call the new editor? Goed seems obvious. Gored - Go reimplementation of ed? Yaed - yet another ed? Gophered - gopher ed? I like that one, has a nice ring to it :) -- Diddymus [1] Heavily tweaked configuration to drop a lot of fancy plugins. [2] ed editor: https://en.wikipedia.org/wiki/Ed_(text_editor) [3] Gnu ed homepage: https://www.gnu.org/software/ed Up to Main Index Up to Journal for June, 2016