Three bonus keys—‘C-i’, ‘C-m’ and ‘C-[’—for your GUI Emacs; all with zero headache

Terminal Emacs handicaps your GUI Emacs, and makes less number of keys available to you

If you are on GUI Emacs you can get atleast three additional keys. Ctrl-i, Ctrl-m and Ctrl-[.

Experienced users of Emacs “know” that

  • Ctrl-i behaves similar to key labeled Tab
  • Ctrl-m behaves similar to the key labelled Enter or Return
  • Ctrl-[ behaves similar to the key Esc

Expert users know that the above “equivalence” in keys exist to make Emacs function well with modern keyboards on terminals.1

In other words, the overloading of certain Ctrl keys with their function brethren is a handicap imposed by terminal Emacs on GUI Emacs.

What this means is that you can configure your Emacs to break the historical umbilical cord, and gift yourself three bonus keys—Ctrl-i, Ctrl-m and Ctrl-[—in GUI Emacs.

Define bonus keys

Add the following snippet to your early-init.el, and enjoy three additional keys.

Let me reiterate, put this snippet in your early-init.el,and NOT the regular init file.

 (defun setup-blah-keys (frame)
   (with-selected-frame frame
     (when (display-graphic-p) ; don't remove this condition, if you want
                                        ; terminal Emacs to be usable
       ;; - When you type `Ctrl-i', Emacs see it as `BLAH-i', and NOT as 'Tab'
       ;; - When you type `Ctrl-m', Emacs see it as `BLAH-m', and NOT as 'Return'
       ;; - When you type `Ctrl-[', Emacs see it as `BLAH-lsb', and not as 'Esc'.
       ;; That is,
       ;; - `Ctrl-i' and 'Tab' keys are different
       ;; - `Ctrl-m' and 'Return' keys are different
       ;; - `Ctrl-[' and 'Esc' keys are different
       ;; The three BLAH keys are the bonus keys.
       (define-key input-decode-map (kbd "C-i") [BLAH-i])
       (define-key input-decode-map (kbd "C-[") [BLAH-lsb]) ; left square bracket
       (define-key input-decode-map (kbd "C-m") [BLAH-m])
       ;; You can replace `BLAH-' above with `C-' or
       ;; `CONTROL-', it doesnt' matter.
       ;; BLAH is merely a symbol / name; feel free to change
       ;; it to whatever you like .

How to bind the bonus keys

Down below, I show you how you may bind the bonus BLAH keys. The important thing to note is that you need to enclose your new keys within “<>”. These BLAH keys are no different from any other key on your Emacs.

 ;; Default value of `outline-minor-mode-prefix' is "C-c @".
 ;; @-bindings are cumbersome to type; setup a convenient prefix.
 '(outline-minor-mode-prefix (kbd "<BLAH-i>")))
;; I use keyboard macros frequently;
;; C-c C-k is too long a prefix for commands that are frequent.  So,
;; put the keyboard macro keys on "BLAH-m"
(define-key global-map (kbd "<BLAH-m>") 'kmacro-keymap)
(define-key kmacro-keymap (kbd "(") 'kmacro-start-macro)
(define-key kmacro-keymap (kbd ")") 'kmacro-end-macro)
(define-key kmacro-keymap (kbd "C-x") 'kmacro-end-and-call-macro)
(put 'kmacro-end-and-call-macro 'repeat-map 'kmacro-keymap)
;; Some keybindings to generate the `super', 'hyper' and `alt' modifiers,
;; when your keyboard has none of these modifiers.
(define-key function-key-map (kbd "<BLAH-lsb> h") 'event-apply-hyper-modifier)
(define-key function-key-map (kbd "<BLAH-lsb> s") 'event-apply-super-modifier)
(define-key function-key-map (kbd "<BLAH-lsb> m") 'event-apply-meta-modifier)
(define-key function-key-map (kbd "<BLAH-lsb> a") 'event-apply-alt-modifier)
(define-key function-key-map (kbd "<BLAH-lsb> S") 'event-apply-shift-modifier)
(define-key function-key-map (kbd "<BLAH-lsb> c") 'event-apply-control-modifier)

Down below you see a screenshot of the BLAH keys in action.

When you type Ctrl-i, Emacs sees it as BLAH-i, and NOT as Tab
When you type Ctrl-m. Emacs sees its BLAH-m, and NOT as Return
When you type Ctrl-[, Emacs sees it as BLAH-lsb, and not as Esc



With the advent of the package-manager, there is an explosion of third-party packages. This means more and more command-s are available to you as a user. At some point in time every Emacs user feels the need for additional keys on the keyboard. The recipe outlined in this article lays three bonus keys at your disposal.

I am using the BLAH keys even as I type now, and I am sure that these BLAH keys will find a permanent place in your early-init.el file.


2 thoughts on “Three bonus keys—‘C-i’, ‘C-m’ and ‘C-[’—for your GUI Emacs; all with zero headache

  1. I was trying to write a package to wrap this and realized, in Emacs server-client mode, I don’t know if you can bind a key to only one frame. So I’m not sure if it can work in a server-client application..


  2. Thanks for your interest. I have updated the recipe to work when Emacs is run as a daemon.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close