Remapping F1-F9 as 1-9 using Xmodmap

Written by Niels on

Recently I found myself in the unfortunate position that the 1 2 3 4 5 6 7 8 9 0 keys on my laptop stopped working, which is more cumbersome than you might think. While waiting on a replacement keyboard module I came up with a temporary hack that works just enough to save the day when using only the laptop keyboard.

In the case you'll need this too:

  • touch ~/.Xmodmap
  • vi ~/.Xmodmap
  • Then add the following lines:
!             DIRECT  SHIFT+   MSWITCH+
keycode   9 = Escape  0        parenright  Escape   Escape  Escape
keycode  67 = F1      1        exclam      F1       F1      XF86Switch_VT_1
keycode  68 = F2      2        at          F2       F2      XF86Switch_VT_2
keycode  69 = F3      3        numbersign  F3       F3      XF86Switch_VT_3
keycode  70 = F4      4        dollar      F4       F4      XF86Switch_VT_4
keycode  71 = F5      5        percent     F5       F5      XF86Switch_VT_5
keycode  72 = F6      6        asciicircum F6       F6      XF86Switch_VT_6
keycode  73 = F7      7        ampersand   F7       F7      XF86Switch_VT_7
keycode  74 = F8      8        asterisk    F8       F8      XF86Switch_VT_8
keycode  75 = F9      9        parenleft   F9       F9      XF86Switch_VT_9
keycode  76 = F10     F10      F10         F10      F10     XF86Switch_VT_10

! Making right control ModeSwitch
keycode 105 = Mode_switch NoSymbol Mode_switch NoSymbol Mode_switch
  • Save the file, and test it with xmodmap ~/.Xmodmap.

In case you want this behavior to be applied when you log in:

  • touch ~/.xinitrc
  • vi ~/.xinitrc
  • Add: [[ -f ~/.Xmodmap ]] && xmodmap ~/.Xmodmap

The normal functionality under F1..F9 will work, but once when you combine with right control or right shift you'll get numbers or characters. I do notice issues with common keybindings off course, so in the end getting a new keyboard module is best :-)

Personal