Remapping caps-lock to escape, and menu to compose, on the linux console
Solution 1
You'll have to edit your console keymap. On my console, I have mapped Escape to Caps Lock and Caps Lock to Escape. Here's how it works.
- First you need to find your keymap. I use the standard US layout. On my system, it is located under
/usr/share/keymaps/i386/qwerty/us.map.gz
. - Make a copy of the file under a new name, for example
us-nocaps.map.gz
. - Unpack the file and open it in a text editor:
gunzip us-nocaps.map.gz && vim us-nocaps.map
- Change the mappings in the file to your liking, for example I had
keycode 58 = Caps_Lock
which I changed tokeycode 58 = Escape
. - Gzip the file and load it:
gzip us-nocaps.map && loadkeys us-nocaps
.
One more thing: You'll probably have to configure your distribution somehow to make sure the new keymaps always gets loaded on boot, otherwise you'll have to load your keymap manually with loadkeys
all time. How you do that depends on what distribution you're using.
Solution 2
For newer Debian distributions you do not need all this anymore.
The keyboard file describes the properties of the keyboard. It is read by
setupcon(1)
in order to configure the keyboard on the console. In Debian systems the default keyboard layout is described in/etc/default/keyboard
and it is shared between X and the console. (man keyboard)
In /etc/default/keyboard
set XKBOPTIONS="caps:escape"
and then do:
~$ sudo setupcon
Description of all available keyboard models, layouts, variants and options is available in
/usr/share/X11/xkb/rules/xorg.lst
." (man keyboard)
Solution 3
With some help from Cedric, I've discovered that Ubuntu hasn't installed the keymaps where $ man loadkeys
says they are supposed to be (/usr/share/keymaps
). This is a brand-new install, so maybe I just need to install a package in order to get keymaps other than the one I selected during installation.
In lieu of pursuing that angle, and in an effort to make the solution a bit more robust and convenient, I'm doing this:
$ sudo dumpkeys | sed 's/CtrlL_Lock/Escape/' | sudo loadkeys
Although I'm a bit confused as to why Cedric's system uses Caps_Lock
for caps lock and mine uses CtrlL_Lock
, it is working regardless.
Related videos on Youtube
Comments
-
msaif over 1 year
When running X I use a .xmodmaprc to remap certain keys thusly:
! Make it so that both Caps Lock and Escape do Escape clear Lock keysym Caps_Lock = Escape ! Remap the menu key as Compose keysym Menu = Multi_key
How can I accomplish the same things on the console?
update
In addition to the partial solution given in my answer, I've learned that the console maps CTRL-
.
to Compose. So I may be able to get used to that. Setting up the Menu key as Compose is not so easily done, as there are a ton of nul-assigned keycodes and no obvious contender for an alternate name for Menu.I've also realized that the compose bindings themselves are much more limited than what I'm used to under X, and that most of the special characters I use frequently are not there. Perhaps there is a utility that will translate X-syntax compose bindings into something that
loadkeys
can read?-
Gilles 'SO- stop being evil' about 13 yearsTraditionally: with
loadkeys
. I think nowadays you can get the Linux console to read the X configuration, but I don't know how this works.
-
-
Cedric about 13 yearsThat's interesting, I didn't know there where differences across distributions with those keymaps. Personally I use Gentoo, the keymaps are from the sys-apps/kbd-1.15 package.
-
Gilles 'SO- stop being evil' about 13 yearsAs of Ubuntu 10.04, the keymaps are in the
console-data
package. They're not installed by default. You can find out what package installs files in/usr/share/keymaps
by runningapt-file search /usr/share/keymaps
. -
glittershark almost 9 yearsThe gunzip step isn't actually necessary here - in most versions of
vim
you should just be able tovim us-nocaps.map.gz