I currently have Caps Lock mapped to Ctrl when held and Esc when tapped (for vim) via these commands in .xinitrc

setxkbmap -option 'caps:ctrl_modifier'
xcape -e 'Caps_Lock=Escape'

This works, but leaves me without Caps Lock so I want to remap Esc to Caps Lock. I've tried setting it with xmodmap -e 'keycode 9 = Caps_Lock' but that overrides the mapping on the Caps Lock key as well. Is there any way to achieve these mappings?

Caps Lock -> Ctrl and Esc
Esc -> Caps Lock
  • @Fox Took me a while to understand what you meant. setxkbmap -option 'caps:swapescape' -option 'caps:ctrl_modifier'; xmodmap -e 'keycode 255 = Escape'; xcape -e '#66=Escape' works. 66 is the code for caps on my keyboard. Caps_Lock=Escape can't be used because the setxkbmap already gave Esc the Caps_Lock keysym (if I understand correctly). Post your comment as an answer and I'll accept it. – hopibel Feb 15 '17 at 9:08

You can use setxkbmap or xmodmap to swap Caps Lock and Escape. With xmodmap you could have:

! Remove Caps_Lock modifier from real Caps Lock key
clear Lock
! Set real Caps Lock key to present as (left) control
keycode 66 = Control_L
! Set real Escape key to present as Caps Lock
keycode 9 = Caps_Lock
! Make a fake key to hold the Escape keysym, so xcape can use it
keycode 255 = Escape
! Make Caps_Lock and Control_L work as one would expect
add Lock = Caps_Lock
add Control = Control_L

(The lines starting with ! are comments.)

Put this in ~/.xmodmaprc and run xmodmap ~/.xmodmaprc, then run xcape -e '#66=Escape' to add Escape functionality to the real Caps Lock key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.