Federico Fuga

Engineering, Tech, Informatics & science

How to switch "\" with "<" keys in linux

28 Nov 2020 10:16 +0000

When using the Apple Magic Keyboard with linux and certain keyboard layout, some key may be exchanged with some other key.

In my case, I have an Italian Magic Keyboard and a Ubuntu 20.10 running on VmWare Fusion and the “" and “<” keys are switched.

The fix is pretty easy, but not easy to find on the net.

This is the recipe: you need to force xmodmap to exchange the two keystrokes. It can be done in the terminal with the following two lines:

<code>xmodmap -e "keycode 49 = less greater guillemotleft \
guillemotright guillemotleft guillemotright"
xmodmap -e "keycode 94 = backslash bar notsign brokenbar \
notsign brokenbar"</code>


This must be launched in each session, but you can also make it automatic by using a proper .Xmodmap file in the home directory.

! For Italian Magic keyboard only
! 49: keystroke for greater-than/lesser-than (right of L-SHIFT)
! 94: keystroke for backslash/pipe (left of 1/exclamation mark)
!
keycode 49 = less greater guillemotleft guillemotright guillemotleft guillemotright
keycode 94 = backslash bar notsign brokenbar notsign brokenbar


Note that this file is for the italian magic keyboard only. For other keyboard layout or other keystrokes, you must find the correct keys and remapping. See xmodmap manual.