Turbo Pascal 2.0 course cover
← Back to Courses
module
5

Changing Your Mind

Introduction

A program is never typed right the first time, and the second time you usually want it to do something else. In S4 you could move a character or a line at a time and rub out one character at a time, which is fine for four lines and hopeless for forty.

Turbo's editor has more than forty commands. This section teaches the ones you will use every day. They are all CONTROL keys, and they are laid out on the left of the keyboard on purpose - once your fingers know them you will not look.

The Diamond

Put your left hand on the keyboard with a finger on each of E, S, D and X. They make a diamond, and with CONTROL held they move the cursor the way the diamond points:

        E
      S   D
        X
  • CTRL-E up a line, CTRL-X down a line.
  • CTRL-S left a character, CTRL-D right a character.

The keys just outside the diamond go further:

  • CTRL-A and CTRL-F - a word left, a word right.
  • CTRL-R and CTRL-C - a whole screen up and down. The editor shows 23 lines at a time.
  • CTRL-W and CTRL-Z - move the text on screen down or up a line without moving far, when you want to see the line above or below.

In MAME: CONTROL is Ctrl.

Further, With CTRL-Q

Put CTRL-Q first and the same keys go all the way:

KeysGoes to
CTRL-Q CTRL-SThe start of the line
CTRL-Q CTRL-DThe end of the line
CTRL-Q CTRL-RThe top of the program
CTRL-Q CTRL-CThe end of the program
CTRL-Q CTRL-EThe top of the screen
CTRL-Q CTRL-XThe bottom of the screen
CTRL-Q CTRL-PBack to where you were before the last jump

Watch the status line: Line and Col tell you where you have landed.

Rubbing Out More Than A Character

KeysDeletes
DELETEThe character before the cursor
CTRL-GThe character under the cursor
CTRL-TThe word to the right of the cursor
CTRL-Q CTRL-YFrom the cursor to the end of the line
CONTROL and -The whole line

That last one is CONTROL with the key marked - - the one that types _. In MAME: Ctrl and the - key.

Changed your mind about a line? As long as the cursor is still on it, CTRL-Q CTRL-L puts the line back as it was before you started on it. Once you move off the line, the changes stay. And it cannot bring back a line you deleted with CONTROL and -: that one is gone, so take care.

Inserting, And Typing Over

The editor starts in Insert mode, which is what the word on the status line means: what you type goes in before the cursor and pushes the rest of the line along.

CTRL-V switches to Overwrite: what you type replaces the characters under the cursor, which is handy for changing a word the same length. CTRL-V again switches back. The status line always says which you are in.

ENTER in the middle of a line splits it in two at the cursor. DELETE at the very start of a line joins it on to the end of the line above. CTRL-N splits the line too but leaves the cursor where it was, which is the quick way to open up an empty line to type into.

Finding

CTRL-Q CTRL-F finds a piece of text. The status line asks:

Find:

Type what you are looking for, press ENTER, and it asks:

Options:

Press ENTER for none. The cursor jumps to just after the next place the text appears. CTRL-L finds the next one, and the next. When there are no more, the status line says

Search string not found. Press <ESC>

and waits for ESC.

The search is exact about capitals: looking for Hello will not find hello. Give the option U and it will find both.

Finding And Replacing

CTRL-Q CTRL-A asks for the text to find, then

Replace with:

then Options:. With no options it goes to the next match and asks

Replace (Y/N):

Y changes that one; N leaves it. To change every match in the program without being asked each time, give the options GN - G for the whole program, N for no questions. Use that with some care: it does exactly what you said, everywhere.

Blocks

A block is a piece of text you have marked, from one character to the whole program, so that you can copy it, move it or delete it in one go.

  1. Put the cursor on the first character you want and press CTRL-K CTRL-B - Block begin.
  2. Put the cursor just after the last character you want and press CTRL-K CTRL-K - blocK end. To take whole lines, put it at the start of the line after the last one.
  3. Now move the cursor to where you want the block to go, and:
KeysDoes
CTRL-K CTRL-CCopies the block to the cursor
CTRL-K CTRL-VMoves the block to the cursor
CTRL-K CTRL-YDeletes the block

You cannot see a block on the Einstein. Turbo shows a marked block only if it has been told how to draw text dimmed, and the course disc's Turbo has not, so the marks are invisible. Keep track of where you put them. After a copy, the marks are round the new copy - so CTRL-K CTRL-Y straight afterwards deletes the copy, not the original.

Give It A Moment

After ENTER, and after the CTRL-K commands, the editor has work to do on the screen, and a key pressed in about the first second can be lost. Type straight on after ENTER and the first letter or two of the next line may simply not be there. It is not your typing. Let the screen settle - a heartbeat - before you type the next line, and if a line has lost its first letters, DELETE is no use; put them back.

The Code

program Find;
begin
  Writeln('Hello');
  Writeln('hello');
  Writeln('Goodbye');
  Writeln('Hello again');
end.

Type it in, run it, and then use it to try every command in this section. Nothing here can harm it that CTRL-Q CTRL-L or retyping cannot mend - and before you start, press S so that you can always load it again.

Starting from

Turbo freshly started, Y, a work file called FIND, CAPS LOCK pressed once.

What you should see

Hello
hello
Goodbye
Hello again

Change One Thing

  • Find hello with no options, then again with the option U. Which lines does each find?
  • Put the cursor on Goodbye, press CTRL-V and type Welcome. What happened to Goodbye, and what does the status line say? Now what does CTRL-V do?
  • Delete the Goodbye line with CONTROL and -. Now press CTRL-Q CTRL-L. Does it come back?

Exercises

5.1 In this section's program, change every Hello to Howdy with one command, without being asked about each. What does the program print now?

5.2 Type this program:

program Order;
begin
  Writeln('one');
  Writeln('two');
  Writeln('three');
end.

Using a block, move the Writeln('one'); line so that the program prints two, three, one.

5.3 Load your HELLO program from S4. Using a block, make it print Hello, Einstein four times - without typing the line again.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
The first letters of a line are missingYou started typing before the editor had finished with the ENTER. Give it a moment after each ENTER.
A CTRL-K command seems to have done nothingIts keys came too soon after the one before. Press it again, a little more slowly.
Text you type eats what is already thereYou are in Overwrite - the status line says so. CTRL-V.
Search string not found. Press <ESC>There are no (more) matches after the cursor. ESC; CTRL-Q CTRL-R to go to the top and look again.
A search does not find something you can seeCapitals differ. Use the option U.
CTRL-K CTRL-C copied nothing, or the wrong thingThe block's marks are not where you think; you cannot see them. Mark it again, both ends.
A line you deleted will not come backCTRL-Q CTRL-L only restores a line you changed and are still on.
The arrow keys type [ ] ^They do on the Einstein. Use the diamond.

Summary

The diamond - CTRL-E, S, D, X - moves the cursor; A and F go by words, R and C by screens, and CTRL-Q in front goes all the way. DELETE, CTRL-G, CTRL-T, CTRL-Q CTRL-Y and CONTROL-- delete ever more; CTRL-Q CTRL-L undoes changes to a line you are still on. CTRL-V switches Insert and Overwrite. CTRL-Q CTRL-F finds, CTRL-L finds again, CTRL-Q CTRL-A replaces. CTRL-K CTRL-B and CTRL-K CTRL-K mark a block, which you cannot see, to copy, move or delete.

Next

S6, Keeping Your Work - saving, what happens to the old copy, working on more than one program, and a program that runs without Turbo at all.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.