Dissociate C-i, C-m, and C-[ in emacs
Emacs
Linux
Every now and then, I bind functions to keys such as C-m
, C-i
, and C-[
, but run into issues as these keys are identical to RETURN
, TAB
, and ESC
. See this and the named ascii list for more information. I tried many solutions before but never got them to work. I finally ran across a solution that works, namely Caio's solution on this post. At the time of this writing, it shows as the last place answer on stacked overflow, so I (and many others) must have missed it. Note that this works only on GUI instances of Emacs and not terminal ones. I will reproduce the solution:
;; Translate the problematic keys to the function key Hyper:
(keyboard-translate ?C-i ?H-i)
(keyboard-translate ?C-m ?H-m)
;; Rebind then accordantly:
(global-set-key [?H-m] 'delete-backward-char)
(global-set-key [?H-i] 'iswitchb-buffer)
Basically, translate the keys using the hyper, and define the new keybindings using the hyper key. For my use, I did
(global-set-key (kbd "C-]") 'elscreen-next)
(keyboard-translate ?C-[ ?H-[)
(global-set-key (kbd "H-[") 'elscreen-previous)
Finally!