Linux – Remapping caps-lock to escape, and menu to compose, on the linux console

consolekeyboardlinuxterminalxmodmap

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?

Best Answer

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.

  1. 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.
  2. Make a copy of the file under a new name, for example us-nocaps.map.gz.
  3. Unpack the file and open it in a text editor: gunzip us-nocaps.map.gz && vim us-nocaps.map
  4. Change the mappings in the file to your liking, for example I had keycode 58 = Caps_Lock which I changed to keycode 58 = Escape.
  5. 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.

Related Question