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 Answers5

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
pilona
  • 1,783
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
Atropo
  • 1,643
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 :)

uzsolt
  • 1,305
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.

Lucifer
  • 1,425
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']"

KDE Plasma 6.2.5

From System Settings, Keyboard -> Keyboard -> Key Bindings

enter image description here

Configure keyboard options -> Caps lock behavior -> Swap Esc and Caps lock

enter image description here

Plasma 5.27 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