Skip to content

Instantly share code, notes, and snippets.

@ervinb
Last active July 3, 2021 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ervinb/803f1da1a55db0882b7a to your computer and use it in GitHub Desktop.
Save ervinb/803f1da1a55db0882b7a to your computer and use it in GitHub Desktop.
Rebind Ubuntu keyboard

Find the key you want to change

  • run xev which opens a new window
  • when you type the key that you want to rebind, the terminal from which xev is run will display all the info about that key
  • look for the keycode section
  • gather all the keycodes this way

Rebind the key

  • run xmodmap -e "keycode <number> = <expression>" where expression is the value (Escape, Control_L, etc.)

  • the changes made here are temporary, the example below shows how to make them permanent

  • each keysym column in the table corresponds to a particular combination of modifier keys:

    keycode N = <Key> 
                <Shift + Key>
                <mode_switch + Key>
                <mode_switch + Shift + Key>
                <AltGr + Key>
                <AltGr + Shift + Key>
    
    example: keycode  49 = grave asciitilde grave asciitilde
    
  • to assign a blank keysym use NoSymbol as a value

  • to print the current keycode > keysym table run xmodmap -pke

Clear everything to default

  • reset the changes to the default layout: setxkbmap -layout us

Example

  • rebinding CapsLock to Esc
xmodmap -e "clear lock"
xmodmap -e "keycode 66 = Escape"
xmodmap -pke > ~/.xmodmap.conf
xmodmap ~/.xmodmap.conf
  • add the last line as a startup command to make the changes permanent ~/.zshrc
if [ -s ~/.xmodmap.conf ]; then
  xmodmap ~/.xmodmap.conf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment