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?

4
  • Did you try following instructions provided at superuser.com/questions/290115/… ? Jun 29, 2012 at 2:19
  • @VitalieCiubotaru I didn't know that QA existed. I'll be sure to check it out.
    – jumpnett
    Jun 29, 2012 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 8, 2012 at 4:59
  • @izx I will when I test it. Unfortunately, I haven't had time to.
    – jumpnett
    Jul 9, 2012 at 15:44

1 Answer 1

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.

2
  • doesn't appear to work over ssh Nov 3, 2012 at 10:44
  • Does this work in Wayland?
    – Flimm
    Sep 21, 2021 at 8:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .