7

I am using Archlinux. When I program , I like to swap the Escape and Caps Lock.

I know that gnome can do this job. But Gnome 3.6.2 in the Archlinux can not find this.

So i use the xmodmap and create a file : ~/.xmodmap

  clear Lock
  keysym Caps_Lock = Escape
  keysym Escape = Caps_Lock
  add Lock = Caps_Lock

when i run:

  xmodmap ~/.xmodmap

it works well.

But it can not work automatic when i login the gnome, even though i add xmodmap ~/.xmodmap to ~/.xprofile.

Am I doing something wrong ? How can I solve this issue?

5 Answers 5

7

Avoid using xmodmap as its another daemon that has to run. Unless touching other keys, ise the simpler and still Xorg upstream setxkbmap, which can be found in the extra/xorg-setxkbmap package.

See a similar question for how to automatically have this start when you start GNOME, but use the caps:swapescape option instead. For example, if you are using startx and ~/.xinitrc, add the following to it:

setxkbmap -option caps:swapescape
2
  • xmodmap is not a daemon: it only modifies keymap and then completely exits.
    – Ruslan
    May 12, 2018 at 21:07
  • Point. Fixing that.
    – pilona
    May 16, 2018 at 15:20
4

The file you should create is ~/.Xmodmap with the capital X. Depending on which login manager (gdm, xdm, etc...) you use the ~/.Xmodmap should be automatically loaded, if this isn't happing, as it seems in your question, you can edit your ~/.xsession and ~/.xinitrc files and add these line to force loading your ~/.Xmodmap:

 [ -f ~/.Xmodmap ] && xmodmap ~/.Xmodmap
2

I think you should create a file with name ~/.Xmodmap (note the big X). As I see in /etc/gdm/Xsession gdm loads ~/.Xmodmap if it exists so you don't need ~/.xprofile or similar hack :)

2

Try to add following command into your .bashrc file

xmodmap ~/.xmodmap

For example I keep the following line in my .bashrc file

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'

which adds an extra escape instead of Caps Lock.

1

The previous solutions works under X11.

GNOME On Wayland

If you have GNOME on Wayland, you can use this to swap your Esc with Caps Lock key:

gsettings set org.gnome.desktop.input-sources xkb-options "['caps:swapescape']"

Plasma On Wayland

If you have Plasma (KDE) on Wayland, please go to System Settings -> Input Devices -> Keyboard -> Advanced, and on the second "Caps Lock behavior" item, check "Swap Esc and Caps Lock".

This has been tested on Plasma 5.27.

enter image description here

2
  • how do you undo this? Feb 16, 2023 at 12:56
  • 1
    gsettings set org.gnome.desktop.input-sources xkb-options "[]" Feb 17, 2023 at 9:32

You must log in to answer this question.