Emacs has a primary selection, called the region. It also has a secondary selection. What for?
Use the secondary selection for, well, a second selection. This lets you use the region for other things, while keeping another selection available for yanking etc. In other words, think of the secondary selection as something less ephemeral than the region, something that is unaffected by changes in the region, i.e., a selection that stays put even as you move the cursor to a different position (point).
How do you use the secondary selection? See Secondary Selection. Selection and yanking are the same as for the region, except that you use the Meta modifier key.
You can also use the secondary selection as another way to do what you do with ‘query-replace’
– sometimes it is more convenient or more flexible:
(setq x-select-enable-clipboard t)
to my .emacs file; I don’t know if this is good or not, but it worked for me. – ShinTakezou‘t’
for ‘x-select-enable-clipboard’
. I also use ‘C-M-’
, not just ‘M-’
, for all of my secondary-selection bindings. (But I am on Windows mostly now, not GNU/Linux.) – DrewAdamsLibrary second-sel.el enhances secondary selection.
It adds the secondary selection to a new selection ring, ‘secondary-selection-ring’
, which is similar to, but separate from, the ‘kill-ring’
. It also prevents the secondary selection from being added to the ‘kill-ring’
, so you now have two separate selection-history rings.
‘M-y’
cycles items from the appropriate ring, depending on whether it follows a yank of the primary (region) or the secondary selection (see below).
second-sel.el
defines new secondary-selection commands. Library menu-bar+.el adds some of these to the Edit menu as items Paste Secondary, Move Secondary to Region, Swap Region and Secondary, and Select Secondary as Region.
[:secondary-yank|select|move|swap]
Command `secondary-yank|select|move|swap’ rolls several secondary-selection commands into one. Library setup-keys.el binds this to ‘C-M-y’
.
Its behavior depends on the prefix argument:
‘yank-secondary’
(also defined in second-sel.el
): Yank the secondary selection at point.‘secondary-to-primary’
: Select the secondary selection as the region, popping to its buffer.‘secondary-swap-region’
: Swap the region and the secondary selection. That is, also go to where the secondary selection was and select it as the region.‘primary-to-secondary’
.DWIM summary: Use ‘C-M-y’
:
‘C-1 C-M-y’
).‘C-0 C-M-y’
).‘C-- C-M-y’
), so you can easily bounce back.In Isearch, ‘M-y’
yanks the current kill into the Isearch string. Library setup-keys.el binds command ‘isearch-yank-secondary’
to ‘C-M-y’
for Isearch, so you can yank the current secondary selection.
Library setup-keys.el binds command ‘yank-pop-commands’
to ‘M-y’
. It cycles among selections in a selection ring: either the ‘kill-ring’
or the secondary-selection ring.
‘kill-ring’
.If the previous command was not a yank at all (from either the ‘kill-ring’
or the ‘secondary-selection-ring’
), then ‘M-y’
does nothing in vanilla Emacs. Here are two alternative enhancements that work together with second-sel.el
to let you yank arbitrary entries from either selection ring.
‘M-y’
means browse the last-used selection ring. With a prefix argument, or if you are already in a selection-ring browse buffer, it browses the other selection ring.‘M-y’
means yank by completing against either the ‘kill-ring’
or (with a prefix argument) the ‘secondary-selection-ring’
. IOW ‘M-y’
yanks a kill using completion, and ‘C-u M-y’
yanks a secondary selection using completion.The second-sel.el sections above show that you can use the keyboard instead of the mouse to yank the secondary selection. You can also use keyboard keys to define it, extend/retract it, and delete its text. Anything you can do with it using the mouse you can also do using keyboard keys.
‘set-secondary-start’
(I bind it to ‘C-x C-M-SPC’
) sets the start of the secondary selection at point. This also undefines it, e.g., if it was defined in some other buffer.‘secondary-save-then-kill’
(I bind it to ‘C-x C-M-RET’
) does the same thing that ‘mouse-secondary-save-then-kill’
does (e.g., bound to ‘C-M-mouse-3’
or ‘M-mouse-3’
), but it uses point instead of the ‘mouse-3’
click position. That is, it sets, extends/retracts, or deletes the secondary selection.If you’re using a touchpad (this is on CentOS 7.2), some actions are easy to remember:
If something happens which you don’t want, you can do C-/ to undo– multiple times, if desired.