this file: https://dataswamp.org/~incal/tty-emacs-keys.txt --------------------------------------------------------------- the Linux Virtual Terminal: special shortcuts in Emacs --------------------------------------------------------------- This tutorial describes how to get special shortcuts - that by default are unavailable - working in an Emacs that runs in the console. An example of such a shortcut is C-0. This console/Linux VT/tty solution has been tested with Emacs 28 on a Debian OS [1] At the very least in the context of this tutorial, VT, tty and console all refer to the same thing. But they are not the same as any Unix "terminal emulator" (e.g., xterm, rxvt etc) that runs in X. For sure, none of this stuff works in X. If you are inpatient, you can deduct how it is done from these two configuration files: console remap: https://dataswamp.org/~incal/conf/vt/remap.inc Emacs bindings: https://dataswamp.org/~incal/emacs-init/console-keys.el -*- In the file /etc/console-setup/remap.inc type control keycode 11 = U+0110 As can be guessed, 'control' is the Control key, or C- in Emacs notation. '11' is the keycode for the key '0' in the console. Learn this from invoking showkey(1) and hitting 0. If showkey doesn't work, try disabling tmux and execute it in a tty with nothing on top. If you'd like it to work with tmux, one way of doing that is to first do 'chmod u+s' for showkey. If you like that solution, you might get some other tools ready all in once: $ sudo chmod u+s /bin/dumpkeys /bin/loadkeys /bin/showkey (in bash and zsh, use the shell builtin 'type' to find out where showkey is. you already knew that, of course) Another option is to use 'sudo' every time: $ sudo showkey Let's return to the remap.inc file. So there is control. There is also 'alt' and 'shift', and these can all be combined: alt shift keycode 28 = U+1000 -*- Let's return to the line control keycode 11 = U+0110 This syntax reads: assign the shortcut C-0 so that when pressed insert the char with Unicode designation U+0110. That char turns out a diamond which means the console can't print it. Good! Let's put it to good use, at last, poor char. Save the remap.inc file and use this zsh function (or a bash equivalent, or just type the command) to bring up the now modified keyboard: #! /bin/zsh lkeys () { loadkeys -q -c -s /etc/console-setup/remap.inc } Again, do the 'u+s' if you don't want to sudo each time with loadkeys(1). After invoking 'lkeys', hit C-0 in a tty. Now, the diamond should appear! \o/ Hint: The Unicode code or char, i.e. U+0110, is arbitrary in the sense that it doesn't matter what it is as long as the char isn't in use already. Make it exotic, one that turns out a diamond on the screen. When you have found one it is easy to find several others just by adding 1 for each shortcut you add. Note: When I posted this tutorial on gmane.emacs.help, Yuri Khan wrote that If you are going to recommend people to hijack arbitrary Unicode characters for extended keycodes, at least tell them to pick codes from the "Private Use Area" (U+E000 up to and including U+F8FF). It is the Unicode equivalent of RFC 1918 IP addresses — guaranteed to never have an official meaning. ikr? +1 -*- Ready for the last step? In an Emacs Elisp init file, type: (define-key input-decode-map [?\u0110] [C-0]) The same Unicode position is used, only the notation differs slightly, as is evident. The "C-0" is an arbitrary name, but it is a good name that is descriptive and adheres to the Emacs notation for keys. Evaluate the `define-key' function...done! Hit C-0, and it should say: (translated from diamond) is undefined At this stage one can bind C-0 to whatever, using the ordinary Emacs syntax: (global-set-key [C-0] #'switch-to-buffer) -*- [1] Emacs: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0) of 2020-10-23 Debian: Linux ebih 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux --------------------------------------------------------------- versions 2015-07-21 to 2022-09-02 by Emanuel Berg ---------------------------------------------------------------