0

When I'm using an xterm, the keyboard sequence Ctrl+/ produces Ctrl-_. Here is the result of showkey -a when first hitting Ctrl+Shift+-, then hitting Ctrl+/. I am on a US ANSI keyboard.

[ ~ ] showkey -a

Press any keys - Ctrl-D will terminate this program

^_       31 0037 0x1f
^_       31 0037 0x1f

I want to actually get ^/ (or whatever it would look like) because I have a customized binding associated with C-/ in Emacs, which works fine if I start an Emacs GUI, but not at all when I run emacs -nw because it just receives the C-_ (which does 'undo').

I don't need to mess with xmodmap (actual key mappings are okay). I've looked into vt100 translations, e.g. I have the following already (from documentation here, among others):

XTerm*VT100.translations: #override \n\
    <Key> Prior: scroll-back(1, halfpage) \n\
    <Key> Next: scroll-forw(1, halfpage)

But can I use translations to just get a different key rather than run a command? I've tried adding a line with Ctrl <Key> /: using insert() just to override, which didn't work. I've tried using string("0xffe4") string("0x2f"), and that gives me the slash but the attempt to put in the Ctrl failed with weirdness ... I got the keysym for Ctrl_R from looking at xev, but I'm not sure that's the right thing to use.

I've also looked at modifyOtherKeys and its documentation here, but setting it to 1 didn't help and setting it to 2 broke pretty much everything.

What is intercepting C-/ and turning it into C-_, and can I overcome it?

Critical note: I am not root nor have any superuser privileges on the system(s) in question. Stuff in this question looked relevant, but any call of loadkeys gives me an error to do with permissions.

8
  • The question's partly relevant, but other related answers point out that in a terminal, the control modifier usually acts as a mask (AND'ing with 0x1f), so control-/ and control-_ map to the same character. GUIs use different rules. Commented Oct 27, 2022 at 19:28
  • There's no such thing as a ^/ character Commented Oct 27, 2022 at 19:33
  • @ThomasDickey Um, I did get that yes GUIs use different rules. Is the 'ANDing with 0x1f' documented anywhere for xterm?
    – Ajean
    Commented Oct 27, 2022 at 19:36
  • 1
    Applications in terminals read bytes values from the /dev/pts/x device as sent there by the terminal emulator (from the master side of the pseudo-tty pair). Ctrl+_ sends the ^_ (aka US in ASCII) character, the 0x1f byte. There's no ^/, but you can send a sequence of characters starting with the ESC character (aka, ^[, \e, 0x1b) like the one sent upon Ctrl+/ woth modifyOtherKeys Commented Oct 27, 2022 at 19:47
  • 1
    So something like ^[[27;5;47~? (That's what shows up in showkey for Ctrl / when modifyOtherKeys is 2) I'll give that a shot!
    – Ajean
    Commented Oct 27, 2022 at 19:50

1 Answer 1

0

Thanks to Stéphane Chazelas I was able to do the following and solve the issue - I put Ctrl <Key> /: string("0x1b") string("/") into my vt100.translations resource, like so:

XTerm*VT100.translations: #override \n\
    <Key> Prior: scroll-back(1, halfpage) \n\
    <Key> Next: scroll-forw(1, halfpage) \n\
    Ctrl <Key> /: string("0x1b") string("/")

which makes Ctrl+/ transmit 'ESC-/' (it was using escape, and escape being 0x1b, or 27, that I was really missing). Then I was able to add another binding in Emacs to handle that just like my current C-/ binding. That way I am now able to hit Ctrl+/ on the keyboard and have Emacs receive M-/ (Emacs notation)1 so that it behaves the same in GUI and terminal.


1 Emacs has a default binding on M-/ already to 'dabbrev-expand'. Since I never use that, I had no qualms overriding it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .