44

Could anyone please tell me how to remap my Super (left) key to Ctrl key?

I mean Super (left) should work as Ctrl key.

4
  • Do you want only the left Super key to act as Ctrl? It's easy to remap both at once from the Keyboard Layout settings, but changing only one would have to be done through config files.
    – pconley
    May 15, 2012 at 5:24
  • 1
    Yes, I want only left Super key to act as Ctrl..
    – Sandy
    May 15, 2012 at 8:08
  • Does the super key refer to the key on my keyboard that has an MS Windows logo on it an lies between Left ctrl and left alt / right alt gr and a key with another weird logo? Mar 13, 2016 at 7:38
  • 1
    @RenéNyffenegger The Super key is the Windows key on PC keyboards and Command key on Apple keyboards. I'm no entirly sure what the other key you describe is
    – nhed
    Sep 6, 2016 at 2:46

7 Answers 7

38

To make major changes to your keyboard, including remapping characters and changing modifiers, you need to use the xmodmap utility - see man xmodmap. There are a couple ways to execute the changes:

  • either from the command line

    xmodmap -e "your commands"
    
  • or write the commands to a file like .xmodmaprc, then execute it in your login items or your .bashrc with

    xmodmap .xmodmaprc
    

    If you name the file ~/.xmodmap it will be executed automatically on login.

Now the commands

What you want to do is a two-step process. First you unmap Super from its modifier, then you map it to control.

  1. Run xmodmap -pm in a terminal window to get a list of the bound modifiers. On my machine (and presumably yours) Super is referred to as mod4. Super_L and Super_R are separate keys which output the same modifier.

    Now you can unmap the modifier from it. Run the xmodmap command (using one of the methods above)

    remove mod4 = Super_L
    

    Now the physical key is still referred to internally as Super_L, but it doesn't do anything.

  2. Now just remap it. Run the xmodmap command:

    add control = Super_L
    

If you want to undo this later on, just run the same commands with the appropriate arguments.

No Super_R?

The output of xmodmap -pm might given you several keys named Super_L but none named Super_R). If it did, you now have several extra keys assigned to Control, but none assigned to Super. You'll have to rename one key. (NB: it might give you several Super_L and at least one Super_R. This is fine.)

The key names in the table all have a hex number in parentheses next to them. This number is the physical keycode of the key on your keyboard (it can vary by model). If you need to change one Super_L to Super_R, first find the keycode you want to be associated to Super_R (aren't sure which is the correct one? Run xev then tap the right Super a couple times. Somewhere in the maze of output is "keycode = 133" (with a different number)). Run the xmodmap command

keycode 133 = Super_R

to rename the key, then

add mod4 = Super_R

to assign it to Super.

6
  • First of all thanks for spending time for me. When I typed "remove mod4 = Super_L" in terminal I got this message: remove mod4 = Super_L: command not found. Screenshot: i.imgur.com/fbvEA.png
    – Sandy
    May 16, 2012 at 8:45
  • 1
    That's a command for the xmodmap utility. You have to run it by one of the methods I gave in the first section. I've edited my answer to make that more clear.
    – pconley
    May 16, 2012 at 14:59
  • Could you also please tell me how to run those commands at startup?
    – Sandy
    May 17, 2012 at 17:46
  • 1
    When you log in, or when the system boots? If the former, just put the commands in the file '.xmodmap' in your home directory; the latter would be more appropriate for a separate question along the lines of 'how do I execute a script on startup' (such questions have presumably been asked before).
    – pconley
    May 18, 2012 at 6:43
  • 1
    For me didn't work without keysum. keysym Super_L = Control_L Feb 10, 2018 at 9:25
23

Command line:

xmodmap -e "remove mod4 = Super_L"
xmodmap -e "add control = Super_L"

Or put in ~/.Xmodmap to activate on startup:

remove mod4 = Super_L
add control = Super_L
16

If you want to do with with a GUI:

  1. Install/open Gnome Tweaks
  2. Click Keyboard & Mouse
  3. Click Additional Layout Options
  4. Expand Ctrl position
  5. Select Swap Left Win with Left Ctrl
2
  • This will also make Left Ctrl behave as Win key. Alt/Win key behavior Ctrl is mapped to Win keys (and the usual Ctrl keys) will leave you without both left and right Win key. I haven't found the way to do it through GUI without interfering with other win/ctrl keys.
    – BanAnanas
    May 15, 2020 at 13:12
  • +infinite, this is exactly what I needed, thanks! now i can seamlessly move from my OSX setup to my Ubuntu Desktop! Aug 28, 2023 at 0:38
6

On Ubuntu, you can edit /etc/default/keyboard and set:

XKBOPTIONS="altwin:ctrl_win"

Which:

Ctrl is mapped to Win keys (and the usual Ctrl keys)

Read man 5 keyboard for more information. You can find all possible combinations of options on your system by doing:

grep alt /usr/share/X11/xkb/rules/evdev.lst | grep win
3

Try with this:

clear Control
clear mod4
remove Control = Control_L Control_R
remove mod4 = Super_L Super_R
add Control = Super_L

Put the above lines in your ~/.Xmodmap and execute xmodmap ~/.Xmodmap.

2

There is an app called Input Remapper that has a GUI where you can easily rebind almost any key

https://github.com/sezanzeb/input-remapper

1
  • 1
    mate! so much easier than xmodmap or keyd
    – airtonix
    Mar 21, 2023 at 10:27
1

Simple and clear example of swapping Ctrl and Alt

Create a file at ~/.Xmodmap. The file content should be this:

! -*- coding: utf-8 -*-
! 2013-02-04

! swap Ctrl and Alt keys

! here's the default setting on special keys
!  xmodmap -pke | grep -P '(Control|Super|Alt|Menu)'

! keycode  37 = Control_L NoSymbol Control_L
! keycode  64 = Alt_L Meta_L Alt_L Meta_L
! keycode 105 = Control_R NoSymbol Control_R
! keycode 108 = Alt_R Meta_R Alt_R Meta_R
! keycode 133 = Super_L NoSymbol Super_L
! keycode 134 = Super_R NoSymbol Super_R
! keycode 135 = Menu NoSymbol Menu
! keycode 147 = XF86MenuKB NoSymbol XF86MenuKB
! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
! keycode 206 = NoSymbol Super_L NoSymbol Super_L

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 105 = Alt_R Meta_R
keycode 64 = Control_L
keycode 108 = Control_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L

Now, run this line in terminal:

xmodmap ~/.Xmodmap

Taken from Xah Lee: Linux, Swap Control Alt Keys

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .