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.
13.10+:
Install and use
gnome-tweak-tool
>Keyboard & Mouse
>Keyboard
>Additional Layout Options
>Caps Lock behavior
.Pre 13.10:
Open the Keyboard Preferences dialog (
System -> Preferences -> Keyboard
). On the layout tab, click theOptions...
button. Expand theCtrl key position
section and selectSwap Ctrl and Caps Lock
.Those settings should be applied each time you log in, and will only affect your user account.
Here's a way to do it without installing extra software:
Source:
One of the best ways to do that graphically if you are using the GNOME shell is to install Gnome Tweak Tool:
sudo apt-get install gnome-tweak-tool
For version 3.30.0 and later:
For older versions:
Enjoy your new Ctrl key!
Open the following for editing:
And edit
XKBOPTIONS="ctrl:swapcaps"
Then, reconfigure:
or
To permanently change the behaviour:
run
dconf-editor
select
org.gnome.desktop.input-sources
Change
xkb-options
to['ctrl:nocaps']
(or add it to any existing options)or on the command line (Warning -- this overwrites your existing settings!):
This is how to do it manually (without additional tools), via XKB, which is the default keys manager for recent Ubuntus. Modify
/usr/share/X11/xkb/symbols/pc
, sectionxkb_symbols "pc105"
:Login/logout or reboot. See here for more details.
Alternatively you can swap at the level of keycodes, that are emitted by those buttons.
Modify /usr/share/X11/xkb/keycodes/evdev
:You'll need to
sudo rm -rf /var/lib/xkb/*
to apply the changes.The accepted answer is confusing because gnome-tweak-tools doesn't show any "typing" section.
Instead, click on "Keyboard & Mouse" section and then choose "Additional Layout Option". There, you will see "Caps Lock behavior" which allows converting caps lock to different keys.
This is an easy task once you know how to do it.
1) Check the keycode of yours key. Run this program at terminal.
At this example, the terminal shows that the keycode for my k is "45".
2) Change them as you like creating this file:
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:
Hope you enjoy ;-)
On KDE-based distributions (like KDE Neon or Kubuntu) this behavior can be configured in the regular system settings. Open the system settings, select "Input Devices" => "Keyboard" => "Advanced". In the category "Ctrl key position" select "Swap Ctrl and Caps Lock".
gnome-tweaks 3.28.1 has no
Typing
section.Thus,
setxkbmap -layout us -option ctrl:nocaps
orsetxkbmap -layout us -option ctrl:swapcaps
would be feasible options.To make it permanent, you can refer to the answer of @name.