DEV Community

Cover image for how to remap broken keys with Xmodmap
Jaeyson Anthony Y.
Jaeyson Anthony Y.

Posted on • Edited on

how to remap broken keys with Xmodmap

We can use Xmodmap instead of installing yet-another-tool for remapping keys, ie your r or v died and you want to use a spare CapsLock + <key> to trigger that dead key.

Create a file ~/.Xmodmap

touch ~/.Xmodmap && vim &_
Enter fullscreen mode Exit fullscreen mode

Here's my example how to remap keys:

! keycode 66 is caps lock
keycode 66 = Mode_switch
keysym h = h H Left
keysym l = l L Right
keysym k = k K Up
keysym j = j J Down
keysym q = q Q z
keysym w = w W x
keysym e = e E c
keysym r = r R v
keysym i = i I Insert
keysym g = g G Home
keysym b = b B End

! ^: asciicircum, |: bar
keysym f = f F asciicircum bar

! u: Page Up, d: Page Down
keysym u = u U Prior
keysym d = d D Next

keysym BackSpace = BackSpace BackSpace Delete
Enter fullscreen mode Exit fullscreen mode

if you want to find a specific key like caps lock:

# press any key to get the key code
# after running this command:
xev
Enter fullscreen mode Exit fullscreen mode

xmodmap

Then add these to ~/.zshrc or ~/.bashrc file:

#you may logout to see changes
xmodmap ~/.Xmodmap
Enter fullscreen mode Exit fullscreen mode

Top comments (0)