Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can not find the mapping in bind -p nor in stty -a. Also, it only works in the terminal emulators I've tried (xterm, konsole, gnome-terminal) and not in the linux system console. I think it's traditionally an emacs mapping.

EDIT: When I enter ^V^/ bash prints ^_, which is mapped to undo in bind. But where is ^/ mapped to ^_?

share|improve this question

It's the terminal emulator which generates it (it does get raw X event and generate a stream of bytes and the pseudo terminal handling doesn't have a notion of modifier keys, ^_ is a control character of code 037).

The origin of this mapping is probably in VT100 which mapped both CTRL-? and CTRL-/ to character 037 and didn't apparently map CTRL-_ to anything. Terminal emulators I've tried map CTRL-? to either 037 of 177.

VT220 did something else, but some of its mappings are still available at least in an XTerm.

share|improve this answer
    
Does that mean the mapping would only be found in the source code of the terminal emulator? – bug Jul 4 '13 at 10:49
    
That or its configuration files (XTerm configuration is able to handle translation of X keypresses to strings -- but I don't see any in the appdefault installed here). – AProgrammer Jul 4 '13 at 10:51

As a general rule, the control modifier acts on the ASCII characters by removing all by the last 5 bits. That maps several different characters into the 0..31 range used for ASCII control characters.

Based on that rule, one would expect these to map into 031, using the control modifier:

037   31    1F    US  (unit separator)
077   63    3F    ?
137   95    5F    _
177   127   7F    DEL

and these would not:

057   47    2F    /
117   79    4F    O
157   111   6F    o

Alternatively, the control modifier could apply only to characters in the range 32..63, using the analogy of the shift key which is useful in ASCII for mapping the range 64..94 to 96..126 (upper/lowercase alphabetics). In that case, these might map to 031:

037   31    1F    US  (unit separator)
057   47    2F    /
077   63    3F    ?

and (it's been a while), @aprogrammer's observation sounds familiar. But it is not in the VT100 manual. In Chapter 3, it points to a table which documents keys and their control equivalents. That uses codes from the full 95-character range (32..126), but only documents one case for each control character. The other possible characters are all undocumented. But note that the table documents control?. On my keyboard, ? is a shifted key. The pictures which I find of the VT100 keyboard do not have it as an unshifted key. And (unsurprisingly) the unshifted code for that particular key is /. DEC may have documented these based on existing keys from an earlier terminal, but just as possibly they may have done that to keep the table short.

However, the conversion is not entirely up to xterm. It receives X events which have certain keycodes along with modifier information. Generally speaking, those keycodes correspond to the letters shown on your keyboard, while the modifiers such as shift and control are passed separately. xterm uses an X runtime function such as Xutf8LookupString or XmbLookupString to combine some events (such as shift). That is where the decision is made to translate these control characters. xterm later refines/amends the information for special keys (such as backspace), but most of the conversion is done in the X libraries using the keyboard configuration.

Further reading:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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