Cutting, copying, pasting

An important part of any editor is the capability of loading multiple files simultaneously with the possibility of easily manipulating the files, removing parts of one to add them to another file as desired. Such operations are generally called cutting and pasting operations in obvious analogy with what can be done when working with paper. In some editors (and sometimes here) the cutting operation is referred to as yanking. As previously mentioned, stedi provides ten different buffers for such flexibility. Eight of these can be freely loaded with files for editing, cutting and pasting. The ninth and tenth buffers are used as cut and paste buffers, also called the yank buffers. You can move between buffers with the Alt-# command where # is a number from 0 to 9 (0 standing for 10) indicating the buffer to which you want to move.

For example, if you are editing a program and a couple of subroutines, you can put them in buffers 1, 2 and 3. Suppose you want to load a fourth program in order to copy a few lines of code from it into the program you are currently editing in buffer 1, you can load this fourth program in buffer 4 and copy the lines desired into the `paste' buffer (buffer nine by default or buffer ten) using the copy command. After this, these lines from the paste buffer can be copied to the desired place in your program in buffer 1 using the paste command. The copy and paste commands are easily accessed through the function keys.

The number and size of the files you can keep in the buffers at any given time is only limited by the amount of memory available in the computer. It makes no difference how many of the buffers are used; only the total memory matters. In this section you will learn how to use the yank, copy and paste commands and how to move back and forth among the buffers. In addition, cutting, copying and pasting in relation to specific columns will also be illustrated. The Marked Range

First let us introduce the concept of a `marked range' which is useful for various purposes. A mark can be set in a file using the F1 key.

The command line then announces that a mark has been set. Now if you move the cursor away from the mark, you can return to the mark by the Shift-F2 key. In addition the F2 key exchanges the cursor with the mark, i.e. after pressing this key, the cursor will move to where the mark was and a mark will be left where the cursor was. This allows you to move the cursor easily to the mark and back again with the same command.

If you do this repeatedly, the cursor will jump back and forth between the positions of the cursor and the mark. These are the two boundaries of a marked range.

A marked range is the range of text between the cursor and the mark. The range does not depend on the order of the mark and the cursor but starts with the character under the opening cursor/mark and ends with the character just before the second mark/cursor.

The marked range is important because all cut and copy actions are defined by this range (among other things). The cut (yank) command and the copy command of a marked range are executed by the keys F3 and F4 respectively. Now for example, to mark the range in which the word `printf' is:

The marked ranged is then between the `p' (inclusive) and the semicolon (exclusive). Now to cut the range:

The characters inside the marked range should now disappear from the text. They can immediately be restored by pressing F5, the paste command.

What we have demonstrated is a general feature of the cut and paste commands. Although the <Undo> key cannot be used with cut and paste commands, any cut action can be reversed by performing a paste command immediately afterwards. A paste can also be reversed by a cut immediately afterwards. These reversals are possible because after a cut the cursor and mark are left in the proper position to undo the operation. This serves as an `undo' feature for cut and paste operations,. Now let us copy the `Hello stedi' program from its current place in buffer 1 to buffer 2. Step 1: First we use the copy command to copy the program.

Step 2: Next you must switch from buffer 1 to buffer 2. (Recall that Alt-# is used to switch among the 10 buffers where # is a number between 0 and 9, 0 standing for 10.)

Since you have not put anything into buffer 2 yet, you will see a blank screen. Step 3: Now you can paste the program into buffer 2.

After using a paste buffer, a copy of what was cut, copied or pasted remains in the paste buffer. To see this,

You will see here a copy of the `Hello stedi' program left after the above operation. If desired, this bit of text is available for repeated pasting as long as it remains in the paste buffer. It will stay there until another cut or copy operation is performed which requires the use of that buffer.

One final point about paste buffers: Remember that buffer 9 and 10 can be used as regular buffers for editing purposes. If you are using either buffer 9 or 10 as a regular buffer, then the editor automatically sets the other buffer as the default for cutting and pasting purposes. So if you move to buffer 9, the default paste buffer becomes buffer 10. You can see this change by watching the `Y' in the message bar. An upper case `Y' indicates that 9 is the current paste buffer and a lower case `y' indicates that it is buffer 10.

For editing in one of the buffers 1 through 8, you can set the paste buffer to use by pressing Ctrl-Y which toggles between the buffers 9 and 10. The `block' cut and paste The possibility exists as well for a `block' cut and paste which is restricted to specific columns which are also specified by the position of the mark and of the cursor. The block yank, copy and paste operations are performed with the use of the function keys shift-F3, shift-F4 and shift-F5 instead of F3, F4 and F5, the normal yank, copy and paste command keys.

With these commands, only the box of rows and columns defined by the mark and cursor will be cut. It should also be mentioned that although the order of the mark and cursor doesn't matter for cutting purposes, an immediate `undo' can only be accomplished if the cursor occurs first. (If you had set the mark in the first position for cutting and only realize afterwards that you need to undo the action and paste the column back, you must re-position the cursor back at the beginning of the original block before you paste). The `Clear Buffer' One final command associated with buffers is the `clear buffer' command which is shift-F9. This command simply clears the current buffer. If the contents of the buffer have changed during the edit session (i.e. the `dirty bit' is on), the programmer will be queried before the action is taken.

This clearing action can be undone using the <Undo> key. In other words, after you press shift-F9, the editor puts the contents of the current buffer in a hidden `undo' buffer. Since the contents of this `undo' buffer will take up space in the computer's memory, if you are having memory problems, you may need to press shift-F9 again to clear the `undo' buffer. (What you are actually doing by this action is copying the contents of the - now empty - current buffer into it and therefore effectively clearing it.) For details on this and other aspects of the stedi's memory usage, see the section on `Memory Usage', in this manual.

Summary of Cut, Copy and Paste Commands
Command Action
F1 Places a Mark at the point of the cursor.
F2 Exchanges the cursor with the mark.
F3 Yank (or Cut) the contents of the marked
  range to the current yank buffer. (The
  contents are removed from the file being
  edited.)
F4 Copy the contents of the marked range to
  the current yank buffer. (The contents are
  not removed from the file being edited.)
F5 Paste the contents of the current yank
  buffer to the position of the cursor.
sh-F1 Delete the mark.
sh-F2 Go to the mark.
sh-F3 Yank a block of text to the current yank
  buffer.
sh-F4 Copy a block of text to the current buffer.
sh-F5 Paste a block of text at the current
  position of the cursor.