How do I remap the Caps Lock and Ctrl keys?

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.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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

Solution 2

Here’s a way to do it without installing extra software:

setxkbmap -layout us -option ctrl:swapcaps

Source:

Solution 3

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:

  • Open tweak-tool and click on the Keyboard & Mouse section in the left menu bar.
  • Click on the Additional Layout Options button on the left.
  • Under Caps Lock behavior select Caps Lock is also a Ctrl.

For older versions:

  • Open tweak-tool and click on the typing section in the left column.
  • You should now see the line Caps Lock key behavior on the left.
  • Choose Make Caps Lock an additional Ctrl key instead of Disabled in the drop-down list and you should be good.

Enjoy your new Ctrl key!

Solution 4

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"

Solution 5

To permanently change the behaviour:

  1. run dconf-editor

  2. select org.gnome.desktop.input-sources

  3. Change xkb-options to ['ctrl:nocaps'] (or add it to any existing options)

or on the command line (Warning — this overwrites your existing settings!):

gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']"

Solution 6

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 , section xkb_symbols "pc105":

//key <CAPS> {  [ Caps_Lock     ]   };
//key <LCTL> {  [ Control_L     ]   };
key <CAPS> {    [ Control_L ]   };
key <LCTL> {    [ Caps_Lock     ]   };

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 :

<CAPS> = 64; //66;
<LCTL> = 66; //64

You’ll need to sudo rm -rf /var/lib/xkb/* to apply the changes.

Solution 7

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.

How do I remap the Caps Lock and Ctrl keys?

Solution 8

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 😉

Solution 9

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

Screenshot of KDE's System Setting's Keyboard module

Solution 10

gnome-tweaks 3.28.1 has no Typing section.
Thus, setxkbmap -layout us -option ctrl:nocaps or setxkbmap -layout us -option ctrl:swapcaps would be feasible options.

To make it permanent, you can refer to the answer of @name.

Solution 11

If you are using i3, you can add this to your i3 config:

exec_always "setxkbmap -layout au -option ctrl:swapcaps"

This will make it that the keys are always swapped on i3 load.

Solution 12

trough tweaks don’t work together

  • swap Ctrl and Caps Lock
  • switch to another layout by Caps Lock

find solution:

  • Caps Lock as Ctrl
  • switch to another layout by Left Ctrl
  • both Shift together enable Caps Lock

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply