Why is the Secondary Selection so useful?

Consider the customary ways of copying bits of text, both within one window and between windows:

  1. Copy-Paste. Set the (Primary) Selection, use Copy/Cut and then Paste it where you want it.

  2. Middle Button. Set the (Primary) Selection, and then use the Middle Button to paste it where you want it.
    Note that when X-Windows was first invented, they could not agree on which of these two methods was best, so they provided both. Since then, it seems generally agreed that this was a mistake, and most systems provide an option to disable method 2 (leaving the Middle Button free for other usages, though there is little agreement on such alternatives – my own preference would be to use it to extend the selection, as that is what (mostly) happens in Solaris).

  3. Drag'n'Drop. Set the (Primary) Selection, then press the Left Button over it and drag it to where you want it, and release the Left Button to paste it there.

  4. Secondary Selection, as will be described.

So what could possibly go wrong?

Usually, when editing text (e.g. some piece of program), you are typing new material at the Insertion Point (usually marked with an I-beam), and then you want to include some text (e.g. the name of some function) which is available somewhere else (either in the same document or from some other window) and have it appear at the Insertion Point.
Note: setting the Insertion Point requires clicking at the precise point in the text that you want, and it is easy to miss it by a character to two (if the characters displayed are too small, or it your hand shakes, or whatever); so you don't want to do it more often than you need to – and there is the Rub.

Let us look at a simple example, using the Gedit editor.

Observe that the Insertion Point is in line 3. We propose to copy the various words from line 1 to line 3, but in the opposite order. Let us try the various methods:

  1. Copy-Paste. Select baz by double clicking

But where has the Insertion Point gone? By definition, if there is a (Primary) Selection, the Insertion Point is at one end of it (usually at the right hand end, unless we selected by dragging R to L). So let us Copy it to the Clipboard (by pressing ctrl-C, or whatever). So now we need to click (carefully!) in line 3, to put the Insertion Point back exactly where it was before.

Observe that baz is no longer selected (because any Selection is always where the Insertion Point is. Now we can Paste (ctrl-V) and baz will appear at the right place, and then we type a space from the Keyboard.

  1. Now try the Middle Button method. Select bar by double clicking as before, but don't Copy it.

Now move the cursor (carefully!) to where the Insertion Point used to be, and click the Middle Button.

So bar has appeared where we wanted it, so we want to type a space to follow it. So type space:

Oops! What went wrong? Look back at the state after clicking the Middle Button. Bar was put in the right place but the Insertion Point was still after the old bar (which was still selected), so that is where the space went, overwriting the selection. It will cost you an Undo to get it back to where it was, and then you have to move the cursor (carefully!) to after the new bar to set the Insertion Point, and then we can type the space. Note that this has cost us two “carefully!”s.

  1. Now try the Drag'n'Drop method. Select foo by double clicking as before.

Now click again over the selected foo, and drag it (carefully!) to where we want to drop it (one space after the bar, where the Insertion Point used to be).

Oops! We forgot that the default action for Drag'n'Drop is to Move the selection. If you want to Copy it, you have to hold Ctrl down; counterintuitive, but that is how it is. So Undo and Drag it again with Ctrl down, and finally we have want we want. Hit Return to move the Insertion Point to line 4.



  1. Finally, let me demonstrate the Secondary Selection method, using the experimental extension I have made to Gtk.

The Insertion Point is already in the right place. Do a Secondary Selection on baz (hold down Ctrl while you double click on it and keep Ctrl down until you are ready).

Note that Secondary Selections are shown by blue underlining; and the Insertion Point is still there. That is the whole point of Secondary Selections: they are entirely independent of the Insertion Point. You still have Ctrl down; when you are satisfied you have selected exactly what you want, release Ctrl:

Et Voila! Baz has been pasted at the Insertion Point, which has moved on so you can continue typing. So type a space (we shall not bother to show that). Now we are ready to grab bar and, just to be different, we shall grab the space following it at the same time. So Ctrl and double click on bar (and keep Ctrl down):

bar is now secondarily selected, and we can now extend that Secondary Selection by holding Shift down (as well as Ctrl) and double clicking over the space (as with Primary Selections, double clicking between “words” selects all the “non-word” stuff between them). Or, if you prefer, a single click (with Ctrl-Shift) just after the space.

So now release Ctrl (and Shift as well) to past bar and space at the Insertion Point:

Finally, grab foo from the top line (Ctrl double click, and then release Ctrl)

and we are done! Note that all the various ways of multi-clicking and extending that work for the Primary Selection work just the same as for the Secondary Selection. Just remember to keep Ctrl pressed until you are ready, because when you release it the paste happens and the Secondary Selection is gone, so it is too late to change your mind. And how many times did I have to write “carefully!” in all that lot? None!


CONTINUE