19

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) ?

25

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.

| improve this answer | |
  • 2
    this didn't work at all until I also added or edited this to .Xresources: URxvt.perl-ext-common: default #also disable keycaps as per this answer: unix.stackexchange.com/a/444777/8827 – marinara Sep 24 '19 at 16:51
  • 1
    I had to do the same as @marinara. In my case, I am already using the font-size perl extension (allows for Ctrl+= and Ctrl+- to zoom in/out), so I had to list the two extensions as a comma-separated list, like so: URxvt.perl-ext-common: default,font-size . I'm using urxvt v9.22 on Ubuntu 18.04. – chimbo Mar 20 at 16:05
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.

| improve this answer | |
2

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:
| improve this answer | |
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
| improve this answer | |
  • 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

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.