3

Emacs cannot currently pick up C-SHIFT sequences in terminal mode. For example, C-) and C-( are instead just read as 0 and 9 respectively. I'm aware that using GUI mode is one way around this, but I need terminal mode when working over SSH. I use iTerm2 on macOS.

I have been through the keyboard shortcuts both in system preferences and iterm preferences, and have tried disabling shortcuts that contain C-SHIFT in case they are conflicting with emacs, but I've had no luck. Is there any way of fixing this?

5
  • 2
    The other option is to identify the key sequences that do not work in terminal, and bind additional prefix key sequences that do work in terminal. For several Ctrl-<key> chords, I bind Alt-' <key> for terminal use. In practice this works fine, and the alternate key sequence is not so burdensome to remember. At least better than the alternative, which is having nothing.
    – InHarmsWay
    Apr 22, 2017 at 12:34
  • The answer you've accepted says "You can't", but I wonder if it is strictly true. I've used some unusual terminals (starting in the 1970s), and read about others. For instance, not all terminals used 7 bit character codes, or even used ASCII. So I would be surprised if there were never ever any terminal that provided a way of encoding Control and Shift separately. Apr 22, 2017 at 13:59
  • 1
    @DAVincent, if anyone posts info showing you can, I will definitely change my accepted answer. For now I've accepted it, because I thought "you can't" was a possibility when I asked the question, and I thought the answerer backed up his view pretty well. Also, a complex/unusual terminal wouldn't be a viable solution for me. But like I say, if anyone disproves "you can't", I'll review my accepted answer.
    – achalk
    Apr 22, 2017 at 15:01
  • 1
    See also Problems with keybindings when using terminal.
    – Dan
    Apr 22, 2017 at 15:38
  • 1
    Thanks @Dan, it looks like there's something I could use here. I have tried setting C-) to both [%d;0 and [%d;) using iterm, but no luck—I just get "Wrong type argument: characterp, nil" from emacs. Any ideas on tweaks that might work?
    – achalk
    Apr 22, 2017 at 15:52

2 Answers 2

4

You can't. There's no way for a terminal to communicate both control and shift modifiers. The very original terminals (teletypes, actually) implemented the control modifier by masking out the top two bits of the 7-bit character set, allowing for 32 control codes. A Q is character number 0x51, and q is 0x71. The bottom five bits of these are both the same (0x12), so the device on the other end (Emacs, in this case), can't tell the difference.

You could instead run Emacs locally, in a gui, and open your remote files using TRAMP. This lets both Emacs and your files stay where they belong.

0
1

I created a package which allows configuring Emacs and many terminal emulators to recognize any combination of modifiers:

https://github.com/CyberShadow/term-keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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