6

I set my Caps Lock to be a Ctrl in Ubuntu 16.04 using: setxkbmap -option 'caps:ctrl_modifier' But when I change my keyboard from En to Cs, the Caps Lock becomes a Caps Lock again, not a Ctrl.

To fix it, I have to execute the above setxkbmap command again from a terminal.

How can I make the setting permanent, even if I switch keyboard layouts?

Ondřej Čertík
  • 780
  • 8
  • 18

3 Answers3

9

In order to make the options set by setxkbmap permanent, add them to /etc/default/keyboard as follows:

--- a/etc/default/keyboard
+++ b/etc/default/keyboard
@@ -5,6 +5,6 @@
 XKBMODEL="pc105"
 XKBLAYOUT="us"
 XKBVARIANT=""
-XKBOPTIONS=""
+XKBOPTIONS="caps:ctrl_modifier"

 BACKSPACE="guess"

Then the option caps:ctrl_modifier will be set even when the keyboard layout is switched from En to any other language.

Ondřej Čertík
  • 780
  • 8
  • 18
  • Thanks for your answer. Do you have any clue why the `setxkbmap` settings are constantly overridden when added to `.bashrc`? I don't have this problem with any other program, just `setxkbmap` misbehaves randomly. – timgeb Jul 08 '18 at 13:36
  • 1
    @timgeb, unfortunately I have no idea. I am glad I at least figured out a solution that works, but why it works, that I don't know. – Ondřej Čertík Aug 02 '18 at 16:52
0

You could also try setting this in the Xorg config as well. See https://wiki.archlinux.org/index.php/Keyboard_configuration_in_Xorg#Using_X_configuration_files for the proper syntax and where to define the options. This also has other good information around using setxkbmap and it's options.

dragon788
  • 3,583
  • 1
  • 40
  • 49
-2

I just solved this. After trying a bunch of different things, in Ubuntu 16.04: - Go to /.bashrc (you can open up the terminal and type vim .bashrc (or use your favorite editor). - Add the command at the end! in my case I did: setxkbmap -option ctrl:swapcaps

Alo
  • 974
  • 2
  • 8
  • 24
  • Unfortunately this does not solve it. Your approach is equivalent to what I do (I actually have the `setxkbmap -option 'caps:ctrl_modifier'` in my `~/.bashrc`). So try your approach, and then change the keyboard layout from `En` to any other language by first adding it in System Settings -> Text Entry, and then changing it in the keyboard layout icon in your tray. When you do that, the `setxkbmap` setting is lost. – Ondřej Čertík Oct 06 '16 at 22:19