TOPS-10: The TECO editor

We looked at the SOS editor previously, now let's try the more powerful - and more complex - TECO (Text Editor and Corrector) on TOPS-10.

History

Dan Murphy wrote the first version of TECO for the PDP-1 in 1962 while working at MIT. The name originally stood for Tape Editor and Corrector - "tape" here meaning paper tape. For this machine programs were prepared offline using a teletype that could write a paper tape from the user's keystrokes. The tape was then taken to the PDP-1 and loaded. The problem was how do you make corrections to a continuous reel of paper tape? The solution Murphy came up with was to write a program that would take the user's source tape and a set of instructions punched to a second tape to edit it. It would apply the corrections in a batch and produce a new paper tape - so TECO was more like a language for processing text than what we would think of as an editor.

It became popular and the program was extended, adding interactive editing and many new commands. The program was ported to most of DEC's operating systems and other machines, and even became the underlying program for the first version of Emacs.

TECO concepts

Some important concepts to keep in mind when using TECO. Unlike the line-orientated SOS, TECO is character orientated: it keeps track of your location in the file via a pointer to a character position - or more precisely the position between two characters. This also means that TECO does not create line numbers and save them like SOS does.

TECO also uses the concept of pages in a file. Each page can be arbitrary length and the separator between pages is a form feed (or Control-L). When TECO starts, it will read in the first page and operate on that; you can then use commands to move on to the next page. This feature allows files that would be larger than core memory to be edited. In practice, if you are creating or editing your own files you will probably not use this feature, but it's something to watch out for if editing older files.

Getting in and out

There are two ways to start TECO: MAKE file.ext will create a new file file.ext and start editing it, and TECO file.ext will open an existing file and position you at the top of the first page. TECO will create a backup file file.bak containing the version of the file before you made edits. Whichever way you invoke it, TECO will print the * prompt showing it is ready to accept commands.

The EX command will save and exit; pressing Control-C will abandon your edits and return you to the command line.

Commands

TECO commands are single or two letter combinations, with an optional numerical prefix and a textual suffix. Textual suffixes must be terminated by pressing Altmode (ie Escape on your keyboard, which will print a $). Several commands can be entered as one long stream. To tell TECO that your command is ready to process, press Altmode twice; just pressing Return will be treated as a textual suffix and will not submit the command.

An example: the C command moves forwards by one character. With a prefix it moves by that number of characters, eg 4C moves forwards 4 characters and -2C moves back 2.

Other useful navigation commands are L to move by line (with 0L meaning move to start of line), J to move to start of buffer and ZJ to end of buffer.

The S command searches for text and if found, moves the character position. The prefix determines which match to jump to and the suffix what text to look for, so 2Shello would jump to the second instance of hello in the buffer.

TECO will not print any of your file unless you tell it to. T will print from the character position to the end of line, and takes prefixes if you want to print more lines. HT prints the whole page.

I will insert the text in the suffix to the current character position, including any whitespace like Return. The Tab command works the same way but will insert an actual tab followed by the text in the suffix.

D will delete the number of characters supplied in the prefix; K will delete by lines.

A sample session

Let's take as an example our hello world program.

        DO 1 J=1,5
1       WRITE(5,2)
2       FORMAT(' HELLO, WORLD')
        END

We want to change 'WORLD' to "EARTH'. The session could look like this:

.teco hworld.for

*sWORLD$$
*-5d$$
*iEARTH$$
*0lt$$
2	FORMAT(' HELLO, EARTH')
*ex$$
.

After invoking TECO we search for the first instance of 'WORLD'. We then delete the preceding five characters (as S places us after the search match) and use I to insert the replacement text. We then use 0L to move us to the start of the line and T to type out the line to confirm the change looks OK. We then use EX to save and exit.

If we were feeling confident, we could do this whole change on a single line:

.teco hworld.for

sWORLD$-5diEARTH$ex$$

.

There's also a find and replace command that can do the above: FSold$new$ will replace 'old' with 'new'

Advanced usage

This only scratches the surface of what TECO can do. Some of its other features are to automatically type out where you are when a search is executed. "Q-registers" where you can store and retrieve sections of text, and iteration and branching - so TECO is Turing complete. The Programmer's Reference Manual weighs in at 144 pages and describes each command fully.

Summary of commands discussed

Command Meaning
C Move by character
D Delete characters
EX Save and exit
F Find and replace
I Insert the text in the suffix
J Move to start of buffer
ZJ Move to end of buffer
K Delete lines
L Move by line (takes prefix)
0L Move to start of line
R Move back by character
S Search by suffix text
Tab Like I, but inserts a tab first
T Type out text
HT Type out the whole file

Further information

On Bitsavers, the 1975 Introduction to TECO is a good place to start. The TECO Programmer's Reference Manual gives a complete description of each TECO command.

Dan Murphy, the original author of TECO, describes the origin and initial development of the editor in The Beginnings of TECO.

There's a version of TECO for modern computers on Github.

Questions, corrections, comments

I welcome any questions or comments, and also especially any corrections if I have got something wrong. Please email me at rupert@timereshared.com and I will add it here and update the main text.