Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to remap my keys such that Ctrl behaves as the Caps Lock key and vice-versa. Also, if possible I'd like the settings to be available only within the currently logged-in user. How can I achieve this?

I'm a vim user, unlike the other people who use this machine, so I'd like those settings only for my account.

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

13.10+:

Install and use gnome-tweak-tool > Typing, as pointed out by @JeremyBicha in the comments to this answer.

Pre 13.10:

Open the Keyboard Preferences dialog (System -> Preferences -> Keyboard). On the layout tab, click the Options... button. Expand the Ctrl key position section and select Swap Ctrl and Caps Lock.

Those settings should be applied each time you log in, and will only affect your user account.

share|improve this answer
1  
This option has disappeared in Ubuntu Saucy. I'm not sure how to explain this but it is simply not there. The Keyboard preferences have no "Layout tab", but there is a "layout settings" button, and when I click it it takes me to the "Input Sources" tab of the "Region & Language" panel, which is mysteriously lacking any kind of 'Options' button. The only button there opens up a virtual on-screen keyboard that displays my broken keyboard layout to me with no way of changing which keys behave which way. –  Robru Sep 6 '13 at 18:34
4  
For Ubuntu 13.10, you'll need to use gnome-tweak-tool. –  Jeremy Bicha Sep 11 '13 at 15:02
add comment

This is an easy task once you know how to do it.

1) Check the keycode of yours key. Run this program at terminal.

xev


At this example, the terminal shows that the keycode for my k is "45".

2) Change them as you like creating this file:

gedit ~/.Xmodmap

It's contents should look like this example:

keycode 37 = Caps_Lock NoSymbol Caps_Lock
keycode 66 = Control_L NoSymbol Control_L

(Change the keycode number as needed - look at step "1")

Ilustration:
(Obs.: if I want to change my k I should use "keycode 45" as showed at step "1").

4) Logout and log back in or reboot or run this:

xmodmap ~/.Xmodmap

Hope you enjoy ;-)

share|improve this answer
    
Note that this solution is likely to cause problems for anything but the simplest keymaps. The xmodmap compatibility in the newer xkb system is not perfect, so you're probably better off sticking to xkb if possible. –  James Henstridge Apr 11 '11 at 7:59
    
@James would you like to explain how can we do that? –  desgua Apr 11 '11 at 10:35
    
See the other answer to this question. The standard keyboard control panel will construct and xkb keymap from the base layout you pick plus the options you enable. –  James Henstridge Apr 11 '11 at 14:47
    
@James Thank you very much. So I guess we should only play with keymaps when 'System -> Preferences -> Keyboard' doesn't have a solution for what we want, right? –  desgua Apr 11 '11 at 19:57
    
Well, you can set up the same keymaps using the command line setxkbmap program. Writing new keymaps is possible, but a bit more involved than Xmodmap keycode mappings. It is a good thing that most of the option variants you'd want are already available. –  James Henstridge Apr 12 '11 at 7:54
show 1 more comment

Open the following for editing:

sudo vi /etc/default/keyboard

And edit XKBOPTIONS="ctrl:swapcaps"

Then, reconfigure:

sudo dpkg-reconfigure keyboard-configuration

or

/usr/bin/setxkbmap -option "ctrl:swapcaps"
share|improve this answer
add comment

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.