23

I followed some post a while ago, and it said to make an ~/.xmodmap file like so:

! Swap caps lock and escape
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock

I did, and it now I can swap esc and caps lock by doing xmodmap ~/.xmodmap. I wanted this to be permanent, so I added that command to my ~/.bash_profile, but it doesn't seem to work; I still have to manually xmodmap. As an EEng dropout, I am tempted to just rewire my keyboard }:-) but I know there must be a better way. How can I make this work, permanently?

don_crissti
  • 82,805
Dan Ross
  • 615
  • 2
  • 6
  • 14

9 Answers9

15

Execute xfce4-settings-manager, in Session and Startup -> Application autostart, add an entry, which executes xmodmap ~/.xmodmap

Or rename the file to ~/.Xmodmap

daisy
  • 54,555
  • 2
    I renamed the file (it worked!), but I am surprised that my .bash_profile method didn't work. I thought my bash-fu was not weak :P – Dan Ross Mar 04 '13 at 18:23
  • I use a Rosewill USB 2.0 switcher (RCUS-17001) to share my keyboard among two PCs, and this option would revert behavior after switching to the other PC output and back. Same for the setxkbmap options. Adding an X config file worked best for me. – Johann Mar 25 '24 at 21:52
8

xkb has an option that does just that:

caps:swapescape      Swap ESC and Caps Lock

so you could simply add1

/usr/bin/setxkbmap -option "caps:swapescape"

to your XFCE autostart items.


1: there might be a better way to do this but I'm not a XFCE user

don_crissti
  • 82,805
  • Cool, I'll give it a shot on my next reboot. Xmodmap doesn't quite work perfectly for me, I have to manually trigger it after switching keyboard languages, for example. I'm also not on XFCE anymore. That was cool, but I wanted more control at home (Arch) and better interop with the stuff my colleagues use at work (vanilla Ubuntu). – Dan Ross Nov 24 '15 at 18:32
  • @DanRoss - Well, if you're using gnome (the only DE that I'm familiar with) it's as simple as adding caps:swapescape to your xkb-options – don_crissti Nov 24 '15 at 18:47
6

In Xfce on Opensuse I swapped my Esc and Caps Lock keys by editing the /etc/X11/xorg.conf.d/00-keyboard.conf file as explained at the archlinux wiki. I added a line that says

Option "XkbOptions" "caps:swapescape"

to the section that starts with

Section "InputClass"

then restarted my computer and the deed was done.

Back up the file before you edit it. If you make a mistake your gui might not start and you will have to restore or edit the file from a command prompt. In Ubuntu I recall that I had to put add the option line in a keyboard configuration file that had a different name.

2

Using the .Xmodmap didn't work for me.

However, a quick man xmodmap says that this works and did:

.xmodmaprc

which can be executed:

xmodmap .xmodmaprc

EDIT: ack...I'm wrong...the default did change a few years ago to .Xmodmap from .xmodmaprc. Creating the .Xmodmap file caused my xfce to load "funny". In .bash_profile, I put:

xmodmap .xmodmaprc

Then it worked, and I have a script that restarted my Xfce so it all works.

wbg
  • 121
1

Edit /etc/default/keyboard and change

XKBOPTIONS=""

to

XKBOPTIONS="caps:swapescape"

This works for all users, and also when not logged in.

(Xmodmap settings get lost when you plug in/out external keyboards (including usb headphones with volume keys since they register as (very small) keyboards), unless the file is named ~/.Xmodmap, but then XFCE will delay applying its own keyboard shortcuts (super-d for show desktop, super-left for tile-left etc.) for 10 seconds after login/unlock. So I wouldn't recommend using Xmodmap on XFCE.)

unhammer
  • 355
  • 1
    Thank you for the comment about losing Xmodmap settings! setxkbmap had the same problem, and your answer clued me into the fact that I'm using a USB switcher, and Caps would revert after switching. – Johann Mar 25 '24 at 21:53
1

enter image description here

xfce desktop system keyboard has option to do it on mx linux, not sure about other distros.

0

I'd been performing a similar adjustment (/usr/bin/setxkbmap -variant altgr-intl -option 'ctrl:nocaps') by putting it in the application autostart, as mentioned by another answer. However, at some point it stopped working for me, so here's my alternative approach:

From the Settings menu, choose "Removable Drives and Media", then the "Input Devices" tab. Enable the option to "Automatically run a program when a USB keyboard is connected" and enter the setkbmap command of your choice.

0

Add this command into a bash (something.sh) file, then add it to startup applications.

setxkbmap -option caps:escape

And if you wanted to rid of it, just do this:

setxkbmap -option
  • 1
    don_crissti has already posted setxkbmap -option "caps:swapescape" as an answer.  Since the question asks how to *swap* Esc and Caps Lock, I wonder why you believe that this is a better answer (or even a correct one at all).  Can you justify your claim that your answer works?  Do you claim that you answer works better than don’s? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; [edit] your answer to make it clearer and more complete.  Include references, if possible. – G-Man Says 'Reinstate Monica' Apr 17 '22 at 19:27
0

Invoke the command xfconf-query -c keyboard-layout -p /Default/XkbOptions -l -v in a terminal in order to see your current settings. In my case before remapping CAPS LOCK it was /Default/XkbOptions/Group grp:shifts_toggle. In order to swap esc with caps lock I used xfconf-query -c keyboard-layout -p /Default/XkbOptions/Group -s "grp:shifts_toggle,caps:swapescape". NOTE: There is a caveat, I appended ,caps:swapescape string to my current value string, because doing just -s "caps:swapescape" would overwrite my previously grp:shifts_toggle value otherwise. You can also use Settings Editor (frontend GUI for xfconf) for the matter which is provided by XFCE.

daGo
  • 337