9

I would like to enable Ctrl+C for copy and Ctrl+Shift+C for SIGINT/interrupt in xterm.

I have found the following.

XTerm*VT100.Translations: #override \
      Shift Ctrl<Key>V: insert-selection(CLIPBOARD) \n\ 
      Shift Ctrl<Key>V: insert-selection(PRIMARY) \n\ 
      Shift<Btn1Down>: select-start() \n\ 
      Shift<Btn1Motion>: select-extend() \n\ 
      Shift<Btn1Up>: select-end(CLIPBOARD) \n\

which I believe is partially there but doesn't give a demonstrate how to override Ctrl+C.

9

That's "partially there", but runs into the problem that there is no predefined (single byte) character corresponding to Ctrl+Shift+C or Ctrl+Shift+V. You need that single byte character for the interrupt (intr) setting with stty. Likewise, control+V is the literal next (lnext) setting in stty.

You could use the translation resource to send a Ctrl+C character using the string feature, e.g., something like these lines in a translations resource:

ctrl shift <key>C : string(0x03) \n\
ctrl shift <key>V : string(0x16) \n\

and then assign the unshifted keys (putting a tilde ~ before the `shift keyword).

From the followup comment, I agree that just specifying the unshifted pattern should be enough:

~Shift Ctrl <KeyPress> v: insert-selection(CLIPBOARD)\n\
~Shift Ctrl <KeyPress> c: copy-selection(CLIPBOARD)\n

a few notes (which might be documented, but the source code helps):

  • <KeyPress> means the same as <Key>
  • the modifiers (and <KeyPress>) are matched ignoring case.
  • the parts on the right-side of : are case-sensitive.

Normally there is no translation done for Ctrl+C with or without the shift-modifier. xterm simply gets an XKeyEvent which has the modifier information and the character, and decodes that. The translations resource alters the events which might be sent to xterm.

You would use modifiers in a translation to limit the matches, e.g., omitting Shift means it matches whether or not the shift-key is pressed. Adding an explicit ~shift (noshift) modifier has no effect on the match for shift.

Further reading:

3
  • Do you mind posting a slightly more complete example for both Ctrl+C,Ctrl+Shift+C,Ctrl+V,Ctrl+Shift+V. I am trying to accomplish the same thing as described and accomplished here askubuntu.com/questions/53688/… except for xterm
    – William
    Jan 21 '17 at 17:33
  • 1
    So this appears to work ~Shift Ctrl <KeyPress> v: insert-selection(CLIPBOARD)\n\ ~Shift Ctrl <KeyPress> c: copy-selection(CLIPBOARD)\n It appears there is no need to change the Ctrl+Shift+C and Ctrl+Shift+V because it does so automatically.
    – William
    Jan 21 '17 at 17:56
  • I have marked this as the accepted answer. Thank you! Is there a similar command that makes this work in gnome-terminal I'm try to find a way to select text over multiple pages which xterm doesn't seem to support unix.stackexchange.com/questions/339411/…
    – William
    Jan 23 '17 at 1:55
3

This appears to work in xterm

xterm -xrm 'XTerm*VT100.Translations: #override\n\
 ~Shift <KeyPress> Prior: scroll-back(1,halfpage)\n\
 ~Shift <KeyPress> Next:  scroll-forw(1,halfpage)\n\
  Shift <KeyPress> Prior: string(0x1b)string("[5~")\n\
  Shift <KeyPress> Next:  string(0x1b)string("[6~")\n\
 ~Shift Ctrl <KeyPress> v: insert-selection(CLIPBOARD)\n\
 ~Shift Ctrl <KeyPress> c: copy-selection(CLIPBOARD)\n
'

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.