Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
1  
I put that command in my ~/.bashrc so it persists between system restarts. (ctrl:nocaps for me, though, for tmux) – opyate Dec 19 '14 at 10:11
    
@opyate I would put that command in ~/.profile so that it will run only once after an interactive login. – suzanshakya Oct 21 '15 at 6:01
up vote 58 down vote accepted

Another way to do this is through the dconf-editor. This method has a few extra steps from gnome-tweak-tool, but is useful if you don't want to pull in the dependencies from the teak tool.

This will allow you to use the caps:swapescape syntax and automatically keep the change permanent.

sudo apt-get install dconf-tools

After starting the dconf-editor, navigate to org >> gnome >> desktop >> input-sources

Add 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.

xkb-options in dconf-editor

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 here is terminate:ctrl_alt_bksp to allow ctrl+alt+backspace to end the X-session.

share|improve this answer
3  
+1 for referencing keyboard-config(7), this was what I was looking for. – ulidtko Nov 2 '13 at 21:49
25  
You can also do this from the command line, without installing dconf-editor: dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']" – Piët Delport Jan 18 '14 at 20:30
4  
Don't run the above command using 'sudo' as this setting seems per user specific. – Bohr Apr 20 '14 at 1:14
3  
Note that you need to use 'caps:swapescape' if you need to swap the two keys (instead of just assigning Esc to Caps Lock). – thameera Oct 5 '14 at 9:19
1  
@thameera Thanks for the info. – chaskes Oct 6 '14 at 15:37

Okay, found a way to do this using gnome-tweak-tool.

From a terminal, run

sudo apt-get install gnome-tweak-tool -y && gnome-tweak-tool

You can find an option to swap Caps Lock and Esc in "Typing -> Caps Lock key behavior".

share|improve this answer
4  
On Ubuntu 14 the layout of the window is very screwy, but it still works. – uvasal Jul 20 '14 at 10:57
    
Yes, I think gnome-tweak-tool should not be used for this task because there are default tools to do it. – Masi Dec 31 '15 at 20:44

You can use xmodmap in terminal to swap Caps Lock with Esc:

xmodmap -e "keycode 9 = Caps_Lock NoSymbol Caps_Lock"   #this will make Esc to act as Caps Lock
xmodmap -e "keycode 66 = Escape NoSymbol Escape"        #this will make Caps Lock to act as 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:

xmodmap -pke > ~/.xmodmap

Then, create a file called .xinitrc in your home directory, containing the following line/command:

xmodmap .xmodmap
share|improve this answer
4  
This does not work under Ubuntu 14.04. I also tried a .xsessionrc file, and it also did not work. – miguel.martin Jul 21 '14 at 14:58
    
How do you undo the settings? – hlin117 Feb 2 '15 at 1:17
    
@hlin117 Just clear the content of the ~/.xmodmap file (by running only > ~/.xmodmap in your terminal), then restart your session. – Radu Rădeanu Feb 2 '15 at 9:42
1  
On Ubuntu 14.04, this makes Escape maps to Caps_Lock but Caps_Lock does not map to Escape. – Justin Raymond Aug 30 '15 at 1:41

Similar to @Radu's answer, but compatible with 14.04 (see also this answer).

xmodmap -e "remove Lock = Caps_Lock"
xmodmap -e "keycode 9 = Caps_Lock NoSymbol Caps_Lock"
xmodmap -e "keycode 66 = Escape NoSymbol Escape"
xmodmap -pke > ~/.xmodmap

If it does not work, replace:

xmodmap -e "remove Lock = Caps_Lock"

with:

xmodmap -e "clear Lock"
share|improve this answer
    
Doesn't work in Linux Mint 17.1 (which is based on Ubuntu) :( – Janek Warchoł Nov 20 '15 at 21:02
2  
had to change "remove Lock = Caps_Lock" to "clear Lock" for it to work – sofia Dec 23 '15 at 12:35

Go to the gears icon in the top right corner of the screen and:

  • click System Settings
  • keyboard layout
  • options...(lower right hand corner)
  • caps lock key behaviour (4th down)
  • Scroll down and choose "Swap ESC and Caps Lock".

Done!

share|improve this answer
    
Joe: Welcome to Ask Ubuntu! ;-) Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-) – Fabby Feb 21 '15 at 21:24
    
Thanks. Works in kubuntu 14.04 – AtomHeartFather Mar 15 at 14:53

This can be done from the "Keyboard Layout" system setting. Click on "options" for the layout you are using, then under "Caps Lock key behavior" choose "switch Escape and Capslock".

share|improve this answer
    
That's not available in at least 13.10. – Isaac Dontje Lindell Jan 22 '14 at 0:26

Run this command once in a terminal. dconf should already be installed with gnome 3.

dconf write "/org/gnome/desktop/input-sources/xkb-options" "['caps:swapescape']"
share|improve this answer

I'm late to answer, but the usual way to swap Esc and Ctrl is with the following lines in the ~/.Xmodmap file:

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

This should work with all desktop environments (KDE, Gnome) on most common distros (Ubuntu and Debian family, Fedora and RH family).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.