I did a fresh installation of jammy 22.04. In my previous Ubuntu version, I'd remapped Caps lock to Esc when pressed and released, and to control when held in combination with other keys. It's good for vim, of course. I can't get it working in 22.04, maybe because of the switch to Wayland. The solutions I've found from Googling haven't worked, maybe because they were for earlier versions of Ubuntu.

I added XKBOPTIONS="ctrl:nocaps" to /etc/default/keyboard, but it didn't work. I also tried caps2esc and xcape but haven't had success since I don't entirely know what I'm doing. I'd like to do this mapping with my dot files, not by downloading a package or adding a repository unless it's really much more convenient to do that. Can someone provide me with some code I can put into my dotfiles in jammy 22.04 so that the Caps lock key gets mapped to Escape when pressed and released, and mapped to Control when held down in combination with other keys? Thanks for any help here.

  • You can remap the Capslock to become Control, but I do not see an option to also have it behave as Esc when pressed and release. Perhaps there something could be achieved with xcape, i.e., map releasing Ctrl (or Capslock after reconfiguration) to Esc.
    – vanadium
    May 22, 2022 at 16:53

3 Answers 3


Use GNOME Tweaks

  1. Keyboards & Mouse → Additional Layout Options → Caps lock behavior.


  • I don't see any option for that.. I also want capslock as control and escape both. Jul 29 at 10:38

Try either this:

setxkbmap -option caps:ctrl_modifier

Or use dconf:

dconf write "/org/gnome/desktop/input-sources/xkb-options" "[ 'caps:swapescape']" `

I understand that it is a year-old question but still (I had to do it myself today on Ubuntu 22.04):

  1. Install Gnome Tweaks
  2. In Gnome Tweaks, choose Keyboard -> Additional Layout Options
  3. Set in Caps Lock behavior the option Make Caps Lock an additional Esc
  4. Set in Ctrl position the option Caps Lock as Ctrl.

UPDATED My approach with Gnome Tweaks does not fully work, ha ha. Caps Lock pressed alone does not act as Esc. The following command in terminal does everything:

setxkbmap -option 'caps:ctrl_modifier' && xcape -e 'Control_L=Escape'

You must log in to answer this question.

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