How to replace less and greater with backtick and tilde?

2022-01-22 CC-BY

If I do not have time, then I execute steps below blindly:

xmodmap -pke | awk '
  BEGIN{FS="=";OFS="=";}
  $2~"less greater"{ k=$1 }
  $2~"grave asciitild"{ b=$2 }
  END{ print k, b }' \
> ~/.Xmodmap
echo "xmodmap ~/.Xmodmap" >> .xinitrc
xmodmap ~/.Xmodmap

Otherwise I read the text below.

When looking at the output of xmodmap -pke, I see two relevant lines:

keycode  49 = grave asciitilde grave asciitilde notsign notsign
keycode  94 = less greater less greater bar brokenbar bar brokenbar

If I run showkey command (as root) and press the key on the right of left shift I get keycode 86 and if I press the key left of 1, then I get keycode 41. I assume these are shifted by +8 in my current keyboard layout. 49 and 94 look right.

Keyboard layout showing mentioned keys

I create a new ~/.Xmodmap file by xmodmap -pke > ~/.Xmodmap and replace the definition of keycode 94 to be the same as keycode 49.

Executing xmodmap ~/.Xmodmap shows me that the remapping worked. Backtick and tilde appear when clicking the key (or shift+key) on the right of left shift.

Luckily, I already have ~/.xinitrc that executes xmodmap ~/.Xmodmap. In case I were not that lucky I would make ~/.xinitrc have content listed below:

#!/bin/sh

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

exec startxfce4

In case my muscle memory fails me, then I would have an empty definition for keycode 49 so that I stop using it for backtick and tilde.