15

Since URxvt 9.20, text can be copied to the clipboard with Ctrl+Alt+C (and also pasted from with Ctrl+Alt+V).

But, I already use these bindings for another thing.

So how can I rebind, in URxvt >=9.20 it to Ctrl+Shift+C (and Ctrl+Shift+V for paste) ?

21

The eval extension shipped with rxvt-unicode has paste_clipboard and selection_to_clipboard actions for this, that can be bound to any keysym (see here).

In your .Xresources add:

URxvt.keysym.Shift-Control-V: eval:paste_clipboard
URxvt.keysym.Shift-Control-C: eval:selection_to_clipboard

To disable the previous keybindings, you'll also need:

URxvt.keysym.Control-Meta-c: builtin-string:
URxvt.keysym.Control-Meta-v: builtin-string:

You can reload the file with:

xrdb -load .Xresources

You'll need to restart rxvt for the changes to take effect.

2

The code implements these two bindings like this:

  if (ctrl && meta && (keysym == XK_c || keysym == XK_v))
    { 
      if (keysym == XK_v)
        selection_request (ev.time, Sel_Clipboard);
      else if (selection.len > 0)
        { 
          free (selection.clip_text);
          selection.clip_text = rxvt_wcsdup (selection.text, selection.len);
          selection.clip_len = selection.len;
          selection_grab (CurrentTime, true);
        }

      return;
    }

You cannot use the keysym resource to rebind something else, since that only maps to strings (no modifiers such as control and alt).

However, you could use the Perl extension, which has methods for working with selections. But you'd have to write a Perl script to tie those together.

1

To use the eval extensions (paste_clipboard and selection_to_clipboard) mentioned in @Enno's answer you can add the following to your .Xresources file:

URxvt.keysym.Shift-Control-V: eval:paste_clipboard
URxvt.keysym.Shift-Control-C: eval:selection_to_clipboard
  • By itself, this doesn’t really answer the question.  You can improve it by describing how to use the .Xresources file to bind the keys, since Enno’s answer doesn’t. – G-Man Says 'Reinstate Monica' Apr 27 '17 at 3:25
1

All of the existing answers handle the second half of the question (how to add keybindings for clipboard operations to new keys), but don't answer the first half (how to free up the original keybindings).

The answer is to simply bind them to builtin-string: (if you wish them to be sent verbatim; otherwise, to the desired action). I.e., in .Xresources:

URxvt.keysym.C-M-c: builtin-string:

Or, on the command line:

-keysym.C-M-c builtin-string:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.