How to remap Super (left) key to Control key

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

6 Answers

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.

5

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

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
1

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

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.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like