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
  • 26,018
jumpnett
  • 5,975
  • Did you try following instructions provided at http://superuser.com/questions/290115/how-to-change-console-keymap-in-linux ? – Vitalie Ciubotaru Jun 29 '12 at 02:19
  • @VitalieCiubotaru I didn't know that QA existed. I'll be sure to check it out. – jumpnett Jun 29 '12 at 18:35
  • Please remember to accept/upvote the best answer to your question (tick/check mark on the left). This way, the question is marked as "answered" and future readers can refer to it knowing the solution works. Thank you...:) – ish Jul 08 '12 at 04:59
  • @izx I will when I test it. Unfortunately, I haven't had time to. – jumpnett Jul 09 '12 at 15:44

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
  • 139,926