3

I want to swap the Caps Lock and Escape key as specified in this answer:

Use the keyboard preferences to swap Caps Lock and Escape - seriously, how often do you use Caps Lock? Using vim you will be using Escape all the time, and having it available on the home row makes a huge difference. With the standard Ubuntu desktop, go through the menus: System -> Preferences -> Keyboard -> Layouts tab. Then hit the "Layout Options" button, click on the triangle next to "Caps Lock key behaviour" and select "Swap ESC and CapsLock".

but, I'm using Ubuntu Server with no gui, so how would I do this from the command line?

Artur Meinild
  • 31,035
jumpnett
  • 6,185

1 Answers1

2

Swapping Esc and CapsLock, with combinations, e.g. Ctrl-Esc

  • dumpkeys | grep -P -i "^keymaps.*|^keycode.*escape|^keycode.*lock" > swap.map
  • swap.map should look something like:
    keymaps 0-127
    keycode   1 = Escape
    keycode  58 = CtrlL_Lock
    keycode  69 = Num_Lock
    keycode  70 = Scroll_Lock
    
  • Swap the values of keycodes 1 and 58, while deleting the other _Lock lines; leave the first line intact though.
  • Try it out with sudo loadkeys swap.map
  • Assuming it works, simply add this line to /etc/rc.local, before the exit 0 line, to activate the swap upon boot:
    loadkeys /home/user/swap.map  # or whatever path you chose

See the source for a more general explanation.

ish
  • 141,990