I have an Apple Aluminium keyboard. To the left of 1 key I have the less/greater (< >) key, not grave/tilde (` ~).

xmodmap does not work for me: layout switching (done with setxkbmap) resets my xmodmap changes. .Xmodmap file does not help either.

How do I remap the tilde key?

up vote 6 down vote accepted

xmodmap Way

First, check this out.

Here's my version of .xsession:

#! /usr/bin/env sh
GTK_IM_MODULE=xim
QT_IM_MODULE=xim
xmodmap ~/.Xmodmap-Apple

and the corresponding ~/.Xmodmap-Apple (for the Russian version):

keycode 94 = grave asciitilde Cyrillic_io Cyrillic_IO
keycode 191 = Print Sys_Req Print Sys_Req Print Sys_Req
keycode 192 = Scroll_Lock NoSymbol Scroll_Lock NoSymbol Scroll_Lock
keycode 193 = Pause Break Pause Break Pause Break
keycode 49 = less greater less greater
keycode 108 = Multi_key Alt_L Multi_key Alt_L

setxkbmap way

In Linux, setxkbmap is used to switch keyboard layouts. Alas, setxkbmap & xmodmap can't work together: they reset each other's changes :( You'll have to pick one of:

  • Just don't switch layouts
  • Invoke xmodmap after every layout switching (or make a script replacing setxkbmap)
  • modify xkb key mappings for your keyboard.

We'll use the latter. First, check which layout you're using:

$ setxkbmap -print
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete+caps(internal)"       };
        xkb_compat    { include "complete"      };
        xkb_symbols   { include "pc+us+ru:2+inet(evdev)+altwin(meta_win)+group(alt_shift_toggle)+compose(ralt)+eurosign(e)+terminate(ctrl_alt_bksp)+macintosh_vndr/apple(alupckeys)"    };
        xkb_geometry  { include "pc(pc104)"     };
};

Here's your symbols map: xkb_symbols ... macintosh_vndr/apple(alupckeys)

In Ubuntu, we have a mapping for apple keyboards here: '/usr/share/X11/xkb/symbols/macintosh_vndr/apple'. First, backup this file. This file has several sections, each starts like this:

xkb_symbols "extended" {
xkb_symbols "laptop" {
xkb_symbols "laptop_bad_switch" {
xkb_symbols "alukbd" {
xkb_symbols "alupckeys" {

The latter mapping, "alupckeys", replaces F13-F15 with PrintScreen, ScrollLock, Pause. Use it if you lack these keys :)

Choose the section you've got from the command output above, and append the following, before the final } of the section:

    key <LSGT> { [ grave, asciitilde, grave, asciitilde ] };
};

Now, restart X. Yeehaw, enjoy having the tilde key on the correct place :)

This command can also help:

$ setxkbmap -option "apple:alupckeys" -print | xkbcomp - $DISPLAY

On the Official Ubuntu Documentation there is a page dedicated to this topic: Apple Keyboard

Here are listed several fixes according to your Ubuntu version.

  • The solution for "Natty Narwhal" worked great for me. – WhyNotHugo Feb 8 '17 at 7:46

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.