Skip to content

Instantly share code, notes, and snippets.

@bartosjiri
Last active September 1, 2023 17:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartosjiri/da83eb003bc9b1d7aeb8bd6136edbc62 to your computer and use it in GitHub Desktop.
Save bartosjiri/da83eb003bc9b1d7aeb8bd6136edbc62 to your computer and use it in GitHub Desktop.
Xmodmap macOS configuration

Xmodmap macOS configuration

Xmodmap configuration that swaps ctrl and cmd keys to achieve macOS-like behaviour.

Installation

  1. Open or create .Xmodmap file in your ~/ folder.

  2. Paste the following code into that file:

    ! -*- coding: utf-8 -*-
    
    ! macOS-like key mapping
    
    ! default mapping
    ! keycode 37 = Control_L NoSymbol Control_L
    ! keycode 64 = Alt_L Meta_L Alt_L Meta_L
    ! keycode 92 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift
    ! keycode 105 = Control_R NoSymbol Control_R
    ! keycode 108 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift
    ! keycode 133 = Super_L NoSymbol Super_L
    ! keycode 134 = Super_R NoSymbol Super_R
    ! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
    ! keycode 206 = NoSymbol Super_L NoSymbol Super_L
    
    ! moddified mapping
    clear control
    clear mod1
    clear mod4
    clear mod5
    keycode 37 = Super_L NoSymbol Super_L
    keycode 108 = Alt_R NoSymbol Alt_R
    keycode 133 = Control_L NoSymbol Control_L
    keycode 134 = Control_R NoSymbol Control_R
    add control = Control_L Control_R
    add mod1 = Alt_L Meta_L
    add mod4 = Super_L Super_R
    add mod5 = Alt_R Meta_R
    
  3. Run the following command in terminal and compare your values with the default mapping values in provided .Xmodmap config:

    xmodmap -pke | grep -P '(Control|Super|Alt|Level3)'
    
    • If your keycodes values are different, you will need to remap these by yourself. You can run xmodmap -pke to print out all keycodes or use xev utility (help).
  4. Apply the changes:

    xmodmap ~/.Xmodmap
    

Limitations

  • This modification does not replicate the macOS terminal controls (i.e. ctrl+c to cancel). A workaround for this limitation is possible with AutoKey scripts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment