Classic Computer Magazine Archive COMPUTE! ISSUE 73 / JUNE 1986 / PAGE 87

Meet ED The AmigaDOS Editor

Christopher J. Flynn

AmigaDOS-the command-driven operating system which underlies the graphics-oriented Workbench-contains two text editors. Although they aren't full-fledged word processors, these editors are ideal for entering program source code, creating batch files, and even writing short documents. This article shows how to use ED, the more powerful of the two editors. For more information on AmigaDOS and batch files, see "Introduction To AmigaDOS," a two-part series in the January and February 1986 issues of COMPUTE!, and "AmigaDOS Batch Files," April 1986.


The Amiga comes with more software than most people realize. Besides Amiga BASIC, Electronic Arts' Kaleidoscope, Mindscape's Amiga Tutor, the RAM disk, the speech synthesizer, the printer drivers, the icon editor, the calculator, the clock, and numerous demo programs, there are also three complete text editors. Most people know about the Notepad because it's available from the Workbench. But the other two text editors-ED and EDIT-don't show up as icons and must be run from an AmigaDOS CLI (Command Line Interface) window.
    The most powerful of these text editors is ED. Although it doesn't handle multiple fonts and styles like the Notepad, it has many more editing functions and is the ideal tool for writing AmigaDOS batch files or program source code. EDIT, on the other hand, is a little more specialized. It is a sequential file editor. In practice, EDIT is best used to make changes to an existing disk file. You'll probably prefer to use ED for composing new text.
    We'll be exploring ED version 1.10. Future releases of ED may change things around a little and introduce new features, so keep this in mind.

Starting ED
Where is ED hiding? Even if you peek through every nook and cranny of the Workbench, you will not find an icon for ED. It turns out that ED is actually an AmigaDOS command. This means that you have to start ED from a CLI window.
    If you've never used a CLI window before, your first step will be to activate the CLI. Open the Work bench and check the contents of the System drawer. If CLIs are activated, you'll see a cube-shaped icon labeled CLI in this drawer. If the icon is not present, point to the Preferences icon and double-click the mouse's left button. Look for the CLI On/Off selector on the Preferences screen and click on the On box, then exit Preferences by specifying Save (not Use). Now when you reopen the System drawer, it should contain a CLI icon. If not, go back to Preferences and make sure CLI is turned on. (If you find yourself using the CLI often, you may want to drag the CLI icon from the System drawer into the main Workbench window to avoid the extra step of opening the System drawer.) To open a CLI window, double-click on the CLI icon. Now you'll have a window in which you can type AmigaDOS commands.
    ED can be started in two ways:

ED filename [SIZE n]

RUN ED filename [SIZE n]

    The first method starts ED from the CLI which you've just activated. It ties up the CLI until you're finished with ED. In other words, you have to leave ED before issuing other AmigaDOS commands. When you specify RUN ED, AmigaDOS automatically starts another CLI task for you and starts ED in this new CLI. Thus, you can temporarily suspend ED by moving the mouse to another window. You can go back to the original CLI and issue other AmigaDOS commands. If you are adventuresome, you can even have multiple ED sessions in progress at the same time. (What you're really doing is multitasking more than one AmigaDOS simultaneously.)
    In either case, the ED command requires a filename. You can either supply the name of an existing disk file you wish to edit, or create a new file by specifying a new filename. Remember that Amiga filenames can be up to 30 characters long. So, choose filenames that take advantage of this feature. It helps you recognize your files later on.
    There is a SIZE option for the ED command. (Don't type in the brackets, by the way. Brackets just signify options.) A text document must be able to fit entirely in memory. ED just cannot handle a document partly on disk and partly in memory. The SIZE option gives you a way of telling ED how much memory you want to set aside for working on the document. If you don't type in SIZE, ED will set aside 40K for you. The maximum SIZE is determined by the amount of memory you have.
    Here are a few examples of commands for starting up ED:

ED GROCERY-LIST

ED WAR-PEACE-BOOK-REPORT SIZE
 90000

    When SIZE is used, type out the number. Note that 90,000 bytes is typed as 90000 and not as 90,000 or 90K.

Leaving ED
When ED has been successfully started, its display occupies the entire screen. So, how can you return to the CLI? There is no close gadget on ED's window. There is nothing to point at and click. Instead, ED requires either a Quit or an Exit command. Press the ESC (escape) key. An asterisk appears on the last line of the display. Type either Q for Quit or X for Exit and then RETURN. That's all there is to it.
    There is a difference between Quit and Exit. Q leaves the editor without saving the document to disk. Anything you have typed will be lost. ED recognizes that this can be quite an inconvenience, so if you do type Q, ED displays the following warning message:

Edits will be lost - type Y to confirm:

    Pressing Y at this point gets you out of ED, and no text is saved. If you type anything else, ED lets you continue working on your document.
    ESC-X, the Exit option, does save the document on disk, using the filename you specified when you started ED. No messages are given. When ED finishes, you're back in the CLI and can then proceed with other AmigaDOS commands. When you're finished with the CLI, type ENDCLI. If you've got only one CLI window running, this returns you to the Workbench.

ED Commands
There are two types of editor commands in ED. The more direct ones are called immediate commands because you can enter them while typing text. Examples are line insertions and deletions. Immediate commands are always CTRL key combinations. The other category-extended commands-can be typed only when in the command mode. ESC-Q and ESC-X are examples. Pressing ESC opens the lowest display line on your screen for these extended commands.
    When ED starts, it positions the cursor at the upper-left corner of the screen. If you are working on a new document, the screen is blank. Otherwise, the screen shows the first page of the document.
    If you're creating a new document, just start typing. Notice what happens when the text approaches the right side of the screen. If a word is too long to fit on the remainder of the line, ED pulls the word down to the next line. You can keep typing without being concerned about hitting RETURN at the end of a line as you would on a typewriter.
    There are several ways of correcting typos. The BACK SPACE key deletes the character to the left of the cursor. DEL deletes the character under the cursor. Table 1 lists other ways of deleting text.
    ED is a full-screen editor, so you can move the cursor wherever you want with the arrow keys. To insert text, position the cursor at the desired location and begin typing. Notice that ED does not have a strikeover mode. Unwanted text has to be deleted-you can't just type over it.

Table 1: ED Immediate Commands

Command

Description

Special Keys

BACK SPACE
Deletes the character to the left of the cursor.
DEL
Deletes the character under the cursor.
ESC
Switches to extended command mode.
RETURN
Ends the line at the cursor and starts a new line.
TAB
Moves the cursor right, adding spaces, to the next tab position.
up-arrow
Moves the cursor up one line.
down-arrow
Moves the cursor down one line.
left-arrow
Moves the cursor one character position to the left.
right-arrow
Moves the cursor one character position to the right.

Control Key Combinations
CTRL-A 
Inserts a line after the line on which the cursor is located.
CTRL-B
Deletes the line on which the cursor is located.
CTRL-D
Scrolls the text down 12 lines toward the beginning of the document.
CTRL-E
If the cursor is at the top of the screen, moves the cursor to the bottom of the screen. If the cursor is at the bottom of the screen, moves the cursor to the top of the screen.
CTRL-F
Switches the case (upper to lower or lower to upper) of the character under the cursor.
CTRL-G
Repeats the last extended command which was issued.
CTRL-H
Deletes the character to the left of the cursor. Equivalent to the BACK SPACE key.   
CTRL-I Moves the cursor right to the next tab position.
Equivalent to the TAB key.
CTRL-M
Equivalent to the RETURN key.
CTRL-O
If the cursor is on a nonblank character, deletes all characters from the cursor to the first space. If the cursor is on a space, deletes all spaces from the cursor to the first nonblank character.
CTRL-R
Moves the cursor left to the first space after previous word on the current line.
CTRL-T
Moves the cursor right to the first character of the next word on the current line.
CTRL-U
Scrolls the text up 12 lines toward the end of the document.
CTRL-V
Redisplays (Verifies) the screen. Insures that all the text is visible and is useful after moving or sizing the display window.
CTRL-Y
Deletes all characters on the line starting with the character under the cursor.
CTRL-[
Switches to the extended command mode.
Equivalent to the ESC key.
CTRL-]
If the cursor is at the start of the line, moves the cursor to the end of the line.
If the cursor is at the end of the line, moves the cursor to the start of the line.

The Insertion Gotcha
Try typing a few fairly long lines. Now, move the cursor to the beginning of the text. Start typing again. The existing text on the current line is moved to the right off the edge of the screen. During insertions, ED neither brings the excess text down to the next line nor enforces margins.
    The disappearing text is not lost, however. ED has made one long line. The long line can be split at any point by placing the cursor where you want and pressing RETURN. If you're working with ordinary text, not source code or batch files, this may leave gaps of several spaces between sentences. To clean up the appearance, the extra spaces will have to be removed. Some other lines may need adjusting as well.

Using The
Extended Commands

Extended commands (Table 2) can be typed only when ED is in the extended command mode, entered by pressing the ESC key. The cursor appears on the last line of the display. At this point, you can type one or more extended commands. It's quite handy to be able to give ED a series of commands separated by semicolons (;). When you press RETURN, ED acts on the command or commands you've requested.
    Extended commands can move the cursor, mark blocks of text for certain operations, and perform searches and exchanges. Some of the operations are tricky and require care. Cursor commands apply only to the cursor position in the text and not to the command line. This is fine except that you can't see the cursor in the text. You have to remember where the cursor is before you use some of the extended commands.
    Sections of text can be marked by block start (BS) and block end (BE) commands. Blocks can be deleted, copied elsewhere in the document, or saved to disk. Marking a block involves moving the cursor to the first line in the block and executing the BS extended command. The end of the block is marked similarly with BE. Unfortunately, there is no visible indication of the defined text. Be very careful of cursor movements. The only help ED offers is the show (SH) command. It displays the first and last line of the block and some other information.

Table 2: ED Extended Commands
Note: /s/ refers to a single text string ( /this is a string/ ).
     /s/t/ refers to two text strings ( /brown/blue/ ).

Command
Description
A /s/
Inserts the string on a new line after the current line.
B
Moves the cursor to the end (bottom) of the document.
BE
Places an end-of-block marker at the cursor.
BF /s/
Searches the document for the string going in a direction from the cursor toward the beginning of the document (backward find).
BS
Places a start-of-block marker at the cursor.
CE
Moves the cursor to the end of the current line.
CL
Moves the cursor one character position to the left.
CR
Moves the cursor one character position to the right.
CS
Moves the cursor to the start of the line.
D
Deletes the current line. Moves all following lines up.
DB
Deletes the text marked by start-block and end-block markers.
DC
Deletes the character at the current cursor position.
E /s/t/
Replaces (exchanges) occurrences of the first string with the second string.
EQ /s/t/
The same as E, but asks you to confirm the replacement each time a match is found. Type Y or N in response to the Exchange ? prompt.
EX
Extends the right margin allowing additional text to be typed.
F /s/
Searches the document for the string going in a direction from the cursor position toward the end of the document (find).
I/s/
Inserts the string on a new line before the current line.
IB
Inserts the block of text marked by start-block and end-block markers after the current line.
IF /s/
Inserts the contents of a file before the current line. The filename is given by /s/.
J
Joins the current line with the next line. This makes one new line where there were formerly two.
LC
Treats upper- and lowercase characters as different in searches.
M n
Moves the cursor to the line number given by n.
N
Moves the cursor to the starting position of the next line.
P
Moves the cursor to the starting position of the previous line.
Q
Quits ED without first saving the text. A warning message will be given stating that the text may be lost.
RP
Repeats commands. Commands are typed following RP. For example, T; RP E /brown/red/ moves the cursor to the top of the document. The Exchange command is repeated, thus changing all occurrences of brown to red. Repeat ends when an error is found. In this case, an error occurs after all thechanges have been made since brown can no longer be found.
S
Splits the current line at the cursor location. This makes two lines where there was formerly one.
SA
Saves the document to the file specified by the original ED command. Use SA periodically to make sure you have a good copy of the text on disk.
SB
Shows the text block marked by start-block and end-block markers. The block (and any following text) will be displayed starting at the top of the screen.
SH
Shows the filename, tab distance, margin settings, first and last line of any marked text block, and the buffer full percentage.
SL n
Sets the left margin to the position specified by n. SL affects the margin setting for the entire document. New text will be typed within the margins. Existing text is not automatically reformatted when the margins change.
SR n
Sets the right margin to the position specified by n. SR affects the margin setting for the entire document. New text will be typed within the margins. Existing text is not automatically reformatted when the margins change.
ST n
Sets the distance the cursor moves when the TAB key is pressed.
T
Moves the cursor to the top of the document.
U
Undoes any changes made to the current line. This does not restore line deletes (D). It also does not work if you have moved the cursor from the current line.
UC
Treats upper- and lowercase characters as equivalent for searches (for example, A will match a).
WB /s/
Writes the text block marked by start-block and end-block markers to the file specified by /s/.
X
Exits ED first making sure that the document has been saved on disk.

    Text search and exchange operations work without a hitch. You can search forward (F) or backward (BF) through the document. You can exchange (E or EQ) one text string for another. Lowercase text can be treated as matching uppercase text (UC), or it can be treated as not matching (LC).
    The repeat (RP) command is often used for exchanges. RP causes the command following it to be exe cuted repeatedly until something (an error, for example) stops it. Thus, RP E carries out multiple exchange operations. Here is an example:

T; RP E /Compute/COMPUTE/

    Here, the typing of COMPUTE! is being corrected. T moves the cursor to the top of the document so that the entire document will be examined. RP precedes the exchange command. Note that the two text strings are delimited by slashes. This is ED's convention when text strings are used. A "Search failed" error occurs when Compute can no longer be found in the text. This halts the repeat command, and the entire document will have been corrected.
    The save command (SA) saves the document to disk without exiting ED. You should do this periodically to prevent disasters in the event of a power failure.
    Overall, ED is an excellent general-purpose text editor. You can use it when programming, since it works with any language that accepts ASCII text files as input (including Amiga BASIC). ED can also prepare data files or help you write short letters and notes. It's not a fancy word processor, but it can handle smaller, less complex tasks quite well.