24

I'm trying to run Emacs in a terminal. I've turned on the "use option as meta" in terminal preferences and so it's about 95% working right.

The key sequence ctrl-/ (or in Emacs notation C-/) is "undo". This key sequence just causes the terminal to ring a bell. How do I fix this?

4
  • FWIW, this works in iTerm2 - iterm2.com — but I think I will just retrain myself to use ^_ everywhere, to be more portable. Nov 12, 2013 at 20:20
  • @StevenR.Loomis portable? neither control-/ nor control-_ work under Android...
    – Michael
    Feb 20, 2014 at 16:58
  • @Michael I said portable because it is representable in ASCII (see accepted answer) and thus can transit network connections without trouble. Plus, it seems to be usable on most physical keyboards I have seen. I did not try pairing a keyboard to the android device, are you referring to a soft or hard keyboard? Feb 21, 2014 at 17:33
  • @StevenR.Loomis software... the control part seems to get ignored resulting in attempts to undo inserting a slash or underscore.
    – Michael
    Feb 21, 2014 at 19:06

4 Answers 4

26

Control-/ is not a part of the set of standard control codes. It is not directly representable as a keystroke in many terminal emulations. Such a keystroke is only properly detectable in certain platform-specific “scancode modes” or “GUI mode” (where the API tells you exactly which keys and modifiers are being used). Your terminal emulator is beeping because it is effectively an invalid keystroke.

The standard control codes only cover “Control” versions of

  • @ AZ [\]^_ (ASCII 0 - 31), and
  • ? (ASCII 127)

In most terminal emulator programs running with most US key layouts you may need to press Shift to generate some of the “Control codes”:

  • C-@ is ControlShift2 (since @ is Shift2)
  • C-^ is ControlShift6 (since ^ is Shift6)
  • C-_ is ControlShift- (since _ is Shift-)
  • However, C-? may not always be ControlShift/ (since ? is Shift/); C-? is usually generated by either Backspace (on Apple keyboards, the key labeled just “delete” without the additional symbol ⌦) or Delete (the one with ⌦ on Apple keyboards).

In tty-based Emacs, you can usually use C-_ for undo instead of C-/.

2
  • 1
    Thanks for the thorough answer. I'm going to try playing with different terminal types to see if I can get it to work. Sep 7, 2011 at 21:36
  • 1
    "Different terminal types"? Do you mean different terminal emulator programs, or are you referring to the $TERM value, which in Terminal is set via Terminal > Preferences > Settings > [profile] > Advanced > Declare terminal as? (All that preference does is set the value of $TERM. It doesn't change the operation of the terminal emulation.) Control-/ is a feature of X11 and is not supported by Cocoa or Terminal.
    – Chris Page
    Sep 8, 2011 at 12:00
12

Ctrl-/ sends 0x1f which is equivalent of Ctrl-_ since the days of VT102. There are many VT100 emulators but they are actually VT102 emulators. iTerm2 works because it's following this behavior.

Only emulators that strictly conform to VT100 specification can't send Ctrl-/. I believe the Terminal app is one of them.

VT100 masks 2 most significant bits of 7 bit ASCII when the control key is pressed. / is 0x2f, o is 0x6f. When the 2 bits are masked they are both 0x0f. VT100 can send Ctrl-o but not Ctrl-/.

2
  • This should be the accepted answer.
    – ocodo
    Apr 29, 2018 at 8:20
  • How about Ctrl-\, really need to know this..
    – Raining
    May 31, 2022 at 3:58
2

Thanks for this answer: https://apple.stackexchange.com/a/260566/472959, add this content to ~/Library/KeyBindings/DefaultKeyBinding.dict:

{
    "^/" = "noop:";
}

then reboot, this annoying bell will disappear.

1
0

FYI, my problem is to know how to keymap Ctrl+\ and it turns out this is helpful: https://www.physics.udel.edu/~watson/scen103/ascii.html.

you can use this as an example to find what you want Ctrl+/

You must log in to answer this question.

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