Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs doesn't recognize C-/ in shell over ssh

Tags:

emacs

I am using Emacs in shell mode through Bash in Mac Terminal, and Emacs doesn't recognize C-/ as the undo key. It seems not to recognize C-/ at all actually, as nothing happens when I use C-hkC-/ (i.e. describe-key then C-/). Any ideas? Undoing with C-xu is intolerable.

Thanks.

like image 274
Zach Avatar asked Oct 01 '11 02:10

Zach


2 Answers

The problem here is that Emacs believes any modifier key (control, shift, meta etc) can be applied to any regular key. This is true when Emacs is talking directly to the OS, but not when it's running inside a traditional (pseudo-)terminal, which is what you've got when you're using emacs inside ssh. In that case, only the modified keys that map to traditional ASCII control characters can be used. C-/ is not one of those keys.

The good news is, because Emacs dates back to the days when ASCII terminals were the only game in town, there's another binding for undo that is an ASCII control character: C-_ (control-underscore, aka control-shift-minus, aka U+001F UNIT SEPARATOR).

Yr hmbl crspdt was in fact not aware C-/ did anything; he also dates back to those days, and C-_ is what is wired into his fingers. He cannot say whether you will find this keystroke tolerable -- it does involve the use of both Control and Shift -- but he suspects it's less bad than C-x u.

like image 131
zwol Avatar answered Sep 24 '22 16:09

zwol


The terminal cannot send C-/. All you need is a way to send an undo alias like C-_ when C-/ is typed. There are two relatively easy ways to do this:

  1. Use iTerm 2 instead of Mac Terminal. It remaps the key out of the box.
  2. Use KeyRemap4MacBook to remap C-/ to C-_ in Mac Terminal.
    1. Install KeyRemap4MacBook.
    2. Reboot.
    3. Open System Preferences > KeyRemap4MapBook
    4. Enable the following Change Key option (search for "control+slash"):

      For Applications > Enable at only Terminal > Change Slash(/) Key

like image 20
slamm Avatar answered Sep 20 '22 16:09

slamm