How can I permanently switch the Caps Lock and Esc key functions in Saucy? I can use this command to do it temporarily (until reboot):
/usr/bin/setxkbmap -option "caps:swapescape"
I tried adding that command as a Startup Application, but it doesn't seem to do anything.
Another way to do this is through the
dconf-editor
. This method has a few extra steps fromgnome-tweak-tool
, but is useful if you don't want to pull in the dependencies from the tweak tool.This will allow you to use the
caps:swapescape
syntax and automatically make the change permanent.After starting the
dconf-editor
, navigate to org >> gnome >> desktop >> input-sourcesAdd the options that you need in
xkb-options
. The option strings are surrounded by single quotes and separated by commas. Be careful not to delete the brackets on the ends.You can use this method to enter most of the traditional xkb options that are no longer available in System Settings >> Text Entry. The exception are the settings for switching the keyboard layouts, which currently do not work because of a bug.
For a list of the options and the syntax, use
man 7 xkeyboard-config
in a terminal.Another common option that could be used is
terminate:ctrl_alt_bksp
to allow ctrl+alt+backspace to end the X-session.A solution that should work for most linux distros:
Other options are possible:
caps:none
to deactivatecaps:escape
to make it an additional escapecaps:super
to make it an additional super (windows) key.To make this work at startup, you can put it in
~/.profile
as this will only run after the interactive login.If the switch does not persist between logins (e.g. when suspending your machine) you can also create a
.xinitrc
file in your home directory and put it there. Linux mint 20 on a laptop works impeccable with this option.Okay, found a way to do this using gnome-tweak-tool.
From a terminal, run
You can find an option to swap Caps Lock and Esc in "Typing -> Caps Lock key behavior".
Update: In Ubuntu 18.04 and 20.04 it can be found in Keyboard & Mouse > Additional Layout Options > Caps Lock Behavior (Thanks to Adracus's comment below)
You can use xmodmap in terminal to swap Caps Lock with Esc:
To get this change for every session, after you have run the previous commands create a file called
.xmodmap
with the new keymaps, using the following command:Then, create a file called
.xinitrc
in your home directory, containing the following line/command:Similar to @Radu's answer, but compatible with 14.04 (see also this answer).
If it does not work, replace:
with:
Go to the gears icon at the top right corner of the screen and do the following:
Click System Settings → Keyboard layout → Options... (lower right hand corner) → Caps lock key behaviour (4th down).
Then scroll down and select Swap ESC and Caps Lock.
Done!
Run this command once in a terminal.
dconf
should already be installed with gnome 3.The Keyboard Layout with Switch Escape and Capslock answer above is no longer valid on Ubuntu 16.04 and later (was it before? dunno).
In order to avoid the hustle with permissions etc., just switch to root before you start doing the following steps by running
su
in a terminal and entering your root password. Then:Run:
There you will see the line:
Change it to:
Exit Vim with save:
Reboot.
And that will be permanent, I promise. :)
For Ubuntu 18.04 and Gnome 3.30 this works for me:
I've built a tool in C specially for this purpose that overcome many of the issues with the xcape/xmodmap solution:
It does a bit more since it also turn CAPSLOCK as both ESC and CTRL.