Skip Navigation
 Search | Directories | Reference Tools
UW Home > UWIN > Computing and Networking > Unix 

TED Editor Tutorial

LESSON 1: A QUICK TED SESSION

LESSON 2: CURSOR MOVEMENT, INSERTING & DELETING TEXT

LESSON 3: COMMAND MODE

LESSON 4: WORKING WITH TEXT BLOCKS

LESSON 5: EDITING DOCUMENTS WITH TED

LESSON 6: PROGRAMMING TED FOR REPETITIVE TASKS

LESSON 7: WORKING WITH MULTIPLE FILES

Ted is a powerful, general purpose editor available on the UW Technology Unix systems. The purpose of this tutorial is to acquaint you with the many features of this editor.


LESSON 1: A QUICK TED SESSION

Ted is a powerful and versatile editor. In addition to standard editing commands such as add, delete, and move for individual characters, lines of text or blocks of text, Ted has commands for sorting lines of text, converting case of text, searching for text strings and for programming sequences of commands to repeat automatically.

Ted can work with as many as four different files simultaneously, allowing rapid movement of text between files or allowing you to view one file while editing another.

To begin getting acquainted, let's first start Ted, enter some text, give some commands, and then exit from Ted.

Creating An Ted File

The Ted editor is invoked with the ted command. The syntax for this command is

       ted  filename.ext

where "filename.ext" is the file to be edited. When you give the ted command with a filename, Ted first looks for a file by that name. If no such file is found, Ted creates a new file.

To create a file named "myfile.txt" you would issue the following command:

       homer> ted myfile.txt

A Blank screen with a cursor will appear. The screen is 80 characters wide, which, with 10 characters per inch printing, is a little less than the full width of an 8.5 inch piece of paper without margins.

Let's give Ted a command. To set a right margin at the 40th character location, we would press the command key, enter the command RM 40 and then press <RETURN>. The command key the F7 key on on most keyboards. You can also press <ESC> and then Q. In the examples here, the command key will be indicated by <F7>.

       Press <F7>
       Cmd:  RM 40 <RETURN>

Now begin typing in the following long sentence without pressing <RETURN>:

       "When using Ted, you type  things just as you
       would using a typewriter."

What happened when you reached the fortieth column? It is as if you are working on a typewriter - you must press the <RETURN> key at the end of each line. To have Ted automatically wrap the sentence to the next line, issue the SET WRAP command.

       Press   <F7>
       Cmd:   SET WRAP <RETURN>

Now trying entering the line of text again. When you reach the fortieth column, Ted automatically moves the cursor to the beginning of the next line.

Enter several more lines of text.

Saving a File

You now have a file. You have several choices on what to do with this file when you exit.

      EQ   Exit quickly from Ted, erasing the file.
      E    Exit Ted,  saving it  as a permanent  file. You can
           also save the file under a new name, leaving the old
           file intact, by typing E [filename.extension]. For
           instance,
           E myfile.new
           saves the file you have been editing under the name
           myfile.new.

Let's save the file, so use the Exit command (E):

      Press  <F7>
      Cmd:    E <RETURN>

A message that the file has been written will appear, followed on the next line by the system prompt, indicating that you have exited Ted and are at the system level.


LESSON 2: CURSOR MOVEMENT, INSERTING & DELETING TEXT

In Ted commands are given either through a command key, or through control codes.

By holding down the CTRL key and pressing the appropriate letter, the cursor may also be moved and characters and lines may also be inserted and deleted. Study the following list of control code actions.

Control Code Action

      Cursor Positioning Actions
      <CTRL>T        Move to the top of the file
      <CTRL>B        Move to the bottom of the file
      <CTRL>F        Move forward (down the file) ten lines
      <CTRL>G        Move backward (up the file) ten lines
      Insert and Delete Actions
      <CTRL>E        (E)rase character
      <CTRL>W        Insert blank character - (W)iden line
      <CTRL>D        (D)elete line
      <CTRL>R        (R)eplicate line
      <CTRL>X        Delete rest of line (unrecoverable) - e(X)punge

Several other keyboard actions are available.

Key Action

      <TAB>          Move cursor to next tab stop. Initial tab
                     settings are at columns 7, 16, 24 and every
                     eighth column thereafter. Tab stops may be
                     removed with the CT command and set with the
                     ST command.
      <DEL>          Deletes character to left of cursor and moves
                     cursor one space to left.
      <BACKSPACE>    Moves cursor one space to left.
       <F7>,   Enters Command Mode.  indicates the red
      or <ESC> Q     key on the Z19 and Z19 terminals.  On the Z29
                     terminals, the equivalent key is the F7 key.
                     On most   other terminals, <ESC>Q would be
                     used. In this document, "/<F7>" is used to
                     identify the Command Mode key.

Start up Ted with your practice file and try out these different actions.


LESSON 3: COMMAND MODE

Command Mode Example

The screen editor also has a command mode. This command mode greatly extends the power of the Ted editor. For example, using the Find command you can locate words or patterns of characters in your text without having to manually search through the text yourself.

If you have not already done so, exit Ted. The prompt should be showing.

Let's create a new file named file1.txt with Ted.

      Enter  ted file1.txt  <RETURN>

Initially, the cursor will be in the upper left-hand corner of the screen. Using what we have learned so far, enter the following text. Notice that the text has several errors - enter it exactly as shown.

             THE WIDE WORLD OF TRAVEL EXPENSES
     State University manual:
           "After the end of each month in which a staff member
     incurs reimbursable expenses, he should submmit a completed
     travel voucher with the required receipts attached to his
     department head."
     New Department of Energy requirements:.
           "A report of the traveler's most recent trip must be
     submmitted with the travel request unless previous
     submission of said trip report has been accomplished."
     MILEAGE REPORTS
       Name           Destination     Mileage     Purpose
      Rudolph Nuryev    Dubuque         309        Pleasure
      Linda Cartwright  Heidelberg     3023        Marketing
      Thomas Watson     New York        250        Installation
      John Heilman      Philadelphia    140        Consulting
      Henry DeVoe       Trenton         210        Conference
      Sue Bruckner      San Francisco  1900        Marketing
      Waldo Emerson     Seattle        1700        Research
      John Fredericks   Chicago         300        Consulting

Next, position the cursor at the top of the file. Let's do a search for the text string "submmit".

       Press <F7>
       Cmd:  F submmit <RETURN>

If the character string is found, the cursor immediately moves to it. To repeat the search for any subsequent occurences of "submmit",

      Press   <CTRL>Z

If no more occurences of the text string are found, the cursor will not move. If the string is found, the cursor will move to the next occurence of the string.

The F command will search for any text string or pattern, beginning at the current cursor location and progressing down the file.

To search up a file, that is, from the current cursor location up through the file toward its beginning, use the FB command. Try it. Position the cursor at the bottom of the file.

      Press <F7>
      Cmd:  FB submmit

The cursor will move up from the bottom of the file to the last occurence of the text string in the file.

Clearing and Setting Margins

The first step in editing a particular file is to set margins. The default settings are

      Left Margin    Column 1
      Right Margin   Column  80

Often these default settings are adequate. Margins are changed with the LM and RM commands.

Let's set the left margin to column 7 and the right margin to column 60.

      Press <F7>
      Cmd:  LM 7 <RETURN>
      Press <F7>
      Cmd:  RM 60 <RETURN>

Notice that the text did not change and the cursor did not move. Tab over to the middle of the page and press <RETURN>. The cursor will move down to the seventh column on the next line. Try moving the cursor to the sixth column and pressing <RETURN>. What happened?

Position the cursor at the left margin. Type in a long line of text. What happens when you try to type past the right margin at column 60?

Ted will not "word wrap" (automatically move the cursor down to the next line when the end of a line is reached) unless you tell it to using the SET WRAP command. You turn off word wrapping with the SET NOWRAP command.

Margin settings are not saved as part of a document. If you want to have the same margin settings next time you edit the document, you will have to use the margin commands to reset them.

Return the margins to their original settings.

      Press <F7>
      Cmd:  LM 1 <RETURN>
      Press <F7>
      Cmd:  RM 80 <RETURN>

Clearing and Setting Tabs

The default tabs settings are as follows:

      Tabs           Columns  7, 16, 24, 32, and every eighth
                          column thereafter.

Tabs locations can easily be changed. To remove (clear) a tab stop, position the cursor in the column of the tab (just <TAB> over to it) and use the CT (Clear Tab) command:

      Press <F7>
      Cmd:  CT <RETURN>

The ST (Set Tab) allows you to set a tab stop in any column. Position the cursor in the column where you want a tab stop and

      Press  <F7>
      Cmd:    ST <RETURN>

Note that the tab location settings are being made in the Ted editor, not in the document. In other words, the tab settings will not be preserved in the document when it is saved.


LESSON 4: WORKING WITH TEXT BLOCKS

Marking Blocks of Text

While editing, you will often want to copy, delete, and move a block of text. This is done with Ted by marking the block with a Start Index and a Finish Index. Once the markers have been placed, a command is given to carry out the desired operation.

Let's move the first paragraph in file1.txt down below the second paragraph.

Move the cursor to the first column of the first line of the first paragraph and place the Start Index.

      Press  <F7>
      Cmd:   SI <RETURN>

Now move the cursor to the first column of the last line in the first paragraph and place the Finish Index.

      Press  <F7>
      Cmd:   FI

Move the cursor down below the second paragraph and issue the command for copying the block. The block of text will be copied to the location of the cursor.

      Press  <F7>
      Cmd:   CB <RETURN>

When we moved the paragraph, the SI and FI indexes were both placed in the same column. Ted interprets this to mean that you want to include in the block all lines between the two indexes, including the lines the indexes are on. If you place the SI and FI indexes in different columns, the Ted assumes that you want the block to include everything between the two indexes, with one index marking one corner of a box and the other marking the opposite corner.

At the bottom of the file1.txt file are several columns of information. Let's copy the column of names from the left side of the table to the right side.

Move the cursor until it is on top of the first character of the first name.

      Press <F7>
      Cmd:  SI <RETURN>

Move the cursor down to the last line and then over until it is in a column that is just beyond the longest of the names.

      Press  <F7>
      Cmd:   FI <RETURN>

Move the cursor back up to the first row in the table and across until it is beyond the last column of numbers.

      Press  <F7>
      Cmd:   CB <RETURN>

How would you now delete the first column of names? Try it.

Sorting Lines of Tex

Find the table of names in your file1.txt file. Ted offers a command that will allow us to quickly resort the table by any of its columns.

Let's sort the table by the MILEAGE column.

Move the cursor until it is on top of the first character of the first mileage (the blank in front of the 300). Place a Start Index there.

      Press   <F7>
      Cmd:    SI <RETURN>

Move the cursor until it is on top of the last character of the last mileage (the second 0 in 1700). Place a Finish Index there.

      Press   <F7>
      Cmd:    FI <RETURN>

Issue the command to sort the lines based on the columns identified by the block.

      Press   <F7>
      Cmd:    SORT <RETURN>

Have the lines been correctly sorted?

Ted sorts the lines into a sequence of increasing key value toward the FI index. In other words, if you want the lines sorted in ascending key value order, place the SI on the first line and the FI on the last line. To have the lines sorted into descending key value order, put the FI on the first line and the SI on the last line.

Available Ted Block Commands

Ted has many block commands:

       CB   Copy block ("shoves" any text at the destination
                 out of the way)
       CBR  Copy block replace (overwrites any text at the
                 destination)
       DB   Delete block
       EB   Erase block (leaves a blank  space where the block
                 was)
       SORT Sort lines
       TB   Transfer block
       TBR  Transfer block replace
       UCB  Upper case block (converts text to all upper case)
       LCB  Lower case block (converts text to all lower case)

Other Uses for the SI, FI, and DI Indexes

Sometimes you may want to pick up lines from throughout your text and put them into one place. You can do this with the Copy Line (CL) command and the Destination Index. First mark the position where you want the lines to go by moving the cursor there and issuing the DI command. Next, place the cursor on the first line you want to pick up and issue the CL command. A copy of the line will appear at the location of the Destination Index. Move the cursor to the next line you want to pick up and press <CTRL>Z, and the CL command will be repeated but with the new line.

Indexes may also be used as place markers. Sometimes while editing a file you will want to jump back and forth between locations. By using the Jump (J) command you can jump to any of the three indexes, wherever they are in the file. For example, the following command would cause the cursor to jump to the location of the Destination Index.

      Press  <F7>
      Cmd:   J DI <RETURN>

Exit Ted so that the original file1.txt file is not changed.


LESSON 5: EDITING DOCUMENTS WITH TED

Ted has a number of features helpful in preparing text documents. In addition to the text copy, delete and transfer commands discussed in Lesson 4, Ted offers automatic line wrap, and several reformatting commands.

Setting Margins and Word Wrap

Start Ted with file1.txt and move to the bottom of the file.

Reset the margins and start automatic word wrapping just as we did in Lesson 1.

      Press   <F7>
      Cmd:    RM 60 <RETURN>
      Press  <F7>
      Cmd:   SET WRAP <RETURN>

Enter the following paragraphs:

     The DOUBLESPEAK DICTIONARY is a collection of
     "deceptive, distorted language" spoken or written
     by politicians, bureaucrats, and other public
     figures.
     CRANK-UPABLE - Used by a Consolidated Freightways
     spokesman who said capital spending in the
     trucking industry "tends to fluctuate widely
     because much of our spending is very deferrable
     and quickly crank-upable."
     EMITTING DESIRED BEHAVIORS - A behavioral
     psychologist wrote "Many of the problems
     encountered by teachers in the daily management of
     their classes could be resolved if the emission of
     desirable student behaviors was increased".
     FELT NEEDS - The opposite of "unfelt needs",
     according to psychologists. If you don't know the
     difference, you need "corrective feedback" to
     develop your "latent abilities".

Inserting Text When WRAP is On

Position the cursor on the period at the end of the first sentence.

Press the <IC> key on the keypad, turning on insert character mode.

Type in the following text:

     The dictionary includes the following phrases:

Note that as you entered the phrase, text was "shoved" over to make room for it.

Using the SPL, APL, and ADJ commands

Often, you will want to split text blocks, join text blocks back together, or readjust the length of text lines within a paragraph. The SPL (Split Line), APL (Append Line) and ADJ (Adjust) commands have these functions.

Position the cursor immediately after the word "DICTIONARY" at the beginning of the second sentence.

      Press   <F7>
      Cmd:    SPL  <RETURN>

The line of text was split, with text after the "DICTIONARY" being moved to the next line.

Now enter the following text:

      by Harold Lambdin

Leaving the cursor positioned at the end of the new phrase, enter the Append Line command (APL).

      Press   <F7>
      Cmd:    APL  <RETURN>

The line of text from below was brought up and appended to the end of the line.

The Adjust command is used to even out the length of lines within a paragraph.

Let's say you wanted to move the right margin out to column 75 and readjust the text to fill the wider space.

      Press   <F7>
      Cmd:    RM 75  <RETURN>

Move the cursor to the middle of the paragraph.

      Press   <F7>
      Cmd:    ADJ  <RETURN>

What happened? The text was shifted so that each line has about the same length. Note that the line breaks are made between words.

Play around with these commands, then exit Ted so as to not disturb the permanent file.


LESSON 6: PROGRAMMING TED FOR REPETITIVE TASKS

Occasionally you may want to repeat a sequence of commands several times. Ted offers a Program (P) command that will record a sequence of commands. A second command, Repeat (R), will cause the sequence of commands to be executed a specified number of times.

Once you enter the P command, everything you type (including arrow key movements, characters and numbers, and other commands) is both acted upon and recorded until you give a P or R command. Each time you give the P command, any pre-existing program is eliminated, so if you make a mistake entering a program, start over again with a new P command.

Let's use the program command to create a scale at the bottom of the file1.txt file.

      Press  <F7>
      Cmd:   P <RETURN>
      Type   ----+----|
      Press  <F7>
      Cmd:   R 1 <RETURN>

A duplicate set of characters was added onto the end of the first set.

Move the cursor down to the next line and have the characters printed out five times.

      Press   <RETURN>
      Press  <F7>
      Cmd:   R 5 <RETURN>

Note that the Repeat command begins the recorded sequence of commands from the current cursor location. If you want to move down through a series of lines, you have to include a carriage return or other cursor movement actions to position the cursor properly for the next repeat.

How would you enter a column of five identical numbers using the P command?

First, move down to the beginning of the next line.

      Press   <RETURN>

Next start the program recorder and enter a number followed by a carriage return.

      Press  <F7>
      Cmd:   P <RETURN>
      Type   12345
      Press   <RETURN>
      Press  <F7>
      Cmd:   R 5 <RETURN>

How would you use the program recorder to add a period at the end of each line of the MILEAGE REPORTS list in the file1.txt file?

Position the cursor at the beginning of the first line of the text.

      Press  <F7>
      Cmd:   P <RETURN>
      Press  <F7>
      Cmd:   EOL <RETURN>
      Type   .
      Press  <RETURN>
      Press  <F7>
      Cmd:   R 5 <RETURN>

The program recorder may also be invoked with <CTRL>P.


LESSON 7: WORKING WITH MULTIPLE FILES

With the Ted editor you are able to work with up to four files at the same time, switching between files quickly, copying text from one file to another and even viewing more than one file at a time.

To work with multiple files, each of the files you want to access must first be made into a local file.

Let's edit the four files at the same time.

The file you specify when you initiate Ted will be the "primary" file. Make file1.txt the primary file.

      homer> ted file1.txt <RETURN>

The contents of the file1.txt file will appear. Now let's start editing "environments" for the other three files.

      Cmd:  <F2>
      File:    file2.txt <RETURN>

The contents of the file2.txt file will now appear. Since file2.txt is a new file, you will see a blank screen. file2.txt is now in the second Ted environment, ready to be edited. Enter some text - anything.

Next, create new files in the third and fourth environments.

      Cmd:  <F3>
      File:    file3.txt<RETURN>

Enter some text.

      Cmd:  <F4>
      File:    file4.txt <RETURN>

Enter some text.

Now all four files are in Ted, each in their own separate "room". You can switch back and forth among the files by using the F1-F4 functions keys. F1 takes you to the first file (the primary file), F2 to the second, F3 to the third, and F4 to the fourth.

NOTE: Some terminals will not have these function keys defined. If pressing a function key does not get a response, try pressing <ESC> n, where 'n' is the number of the environment you want to go to. You can also move among environments by pressing the command key and entering the command ENVn, where n is the number of the environment you want. For example, ENV3 would move you to environment 3.

Try moving around from file to file by pressing the function keys.

Editing Multiple Files

Working with multiple files in Ted is very similar to working with a single file. Let's copy the contents of the file2.txt file into the file1.txt file.

First, go to the the Ted environment containing file2.txt.

      Cmd:  <F2>

Identify the text to be copied with the SI and FI indexes. Move the cursor to the beginning of the first line of the text.

      Press  <F7>
      Cmd:   SI <RETURN>

Move the cursor to the beginning of the last line of the text.

      Press  <F7>
      Cmd:   FI <RETURN>

Move back to the environment containing the file1.txt file.

      Press  <F1>

Position the cursor at the bottom of the file1.txt file and copy the text block from the file2.txt file.

      Press  <SHIFT> <HOME>
      Press  <F7>
      Cmd:   CB <RETURN>

The block of text from file2.txt will appear at the bottom of file1.txt.

Viewing Multiple Files Simultaneously

You may want to enter information into one file depending on the contents of a second file. Instead of having to jump back and forth between the files using the function keys, you can have both files displayed at the same time by using the Windows (W) command. The format of the command is W followed by the numbers of the environments you want simultaneously displayed.

Enter the Windows command to have the file1.txt and file3.txt files displayed both at the same time.

      Press  <F7>
      Cmd:   W 1 3  <RETURN>

Now display all four files at the same time.

      Press  <F7>
      Cmd:   W 1 2 3  4 <RETURN>

The Windows command controls how the files are displayed. You still will use the F1, F2, F3 and F4 keys to move back and forth among the files. In other words, to edit a file or to move around in it, you must first use the function key to get to the appropriate environment.

Exiting Multiple Files

Be careful when exiting a session where you were working with multiple files. If you want to save the contents of one of the non-primary files, you must separately ER that file before exiting from the primary file (the file in environment 1). When you exit (E, EQ, or ABT) from environments 2, 3, or 4, you will be returned to the primary file. However, when you exit from the primary file Ted simply exits all remaining files, not saving or replacing their contents as permanent files.

Exit from this session so as to save the changes in file1.txt but not cause the file to be rewritten.