12

By default, no layout on my Macbook Air allows me to print backtick (`) and tilde (~) symbols. Instead, I get backslash, pipe or whatever, depending from the layout.

I changed the behavior of the key that I want to use to print tilde using the following commands:

xev
<press tilde button>
keycode <keycode from xev output> = grave asciitilde >~/.Xmodmap
xmodmap ~/.xmodmaprc 

(instructions are based on these https://stackoverflow.com/questions/17757232/switch-tab-and-backtick-keys-ubuntu-linux)

But unfortunately, after I switch the layout, I get the default behavior again.

How to make these changes permanent?

4
  • This is a problem I'm searching a simple solution for too. Just to add, the issue is that with Ubuntu 14.04 xmodmap is no longer functional. Its changes gets overwritten periodically (after a few minutes in my case) by xkb. I'm not an expert on this and still searching for a solution as well. This is just to inform you of the reason for this problem. Nov 23, 2014 at 7:39
  • @BoazRymland I solved the problem myself, just forgot to report. You may find the solution below, hope it helps you as well.
    – Timofey
    Nov 24, 2014 at 11:27
  • thanks! I'll try it later. I don't like the idea of editing system file (or files that are suspected as such, with lack of knowing better) but I'm curious and want to resolve this. Thanks again! Nov 24, 2014 at 13:57
  • I don't even have tilde button on my Macbook Finnish keyboard.
    – jarno
    Jan 22, 2018 at 8:36

4 Answers 4

22

The solution that worked for Timofey did not work for me for some reason. However, a solution which did work was to put the line

echo 0 > /sys/module/hid_apple/parameters/iso_layout

into /etc/rc.local.

This suggestion comes from here:

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1245081

via

https://stdio.sangwhan.com/backtick-tilde-problem-macbook-air/

4
  • 3
    also works in 16.04 Apr 25, 2016 at 12:58
  • Also works on MacBook Pro
    – Lambart
    Aug 20, 2016 at 0:06
  • Works on Macbook Pro 12,1 w/ debian
    – jeremy
    Aug 20, 2016 at 17:24
  • 1
    This long-established solution inexplicably stopped working for me. I'm no longer able to edit this file, and so placing the code into the rc.local has no effect. Has anyone else run into this issue?
    – Csteele5
    Feb 14, 2017 at 1:40
7

Okay, I solved the problem.

First off, xmodmaprc doesn't work in Ubuntu 14.04. The solution is to edit xkb (X KeyBoard extension) config files.

Find the file /usr/share/X11/xkb/symbols/pc, backup it, then open and comment out the line:

key <LSGT> {    [ less, greater, bar, brokenbar ] };

And on the next line, add the following:

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

If you need to change configuration for another locale, check the folder /usr/share/X11/xkb/symbols/ and find the file corresponding to the locale you want to change.

To apply the changes, you have to remove all xkb cache files:

rm -rf /var/lib/xkb/*
2
  • works after a reboot. Works on ubuntu 16.04LTS as well as on elementaryOS Sep 17, 2016 at 19:22
  • 1
    This is a more correct answer than @yasmar's as it corrects the system cofiguration rather than overriding it after it's applied.
    – bschlueter
    May 22, 2017 at 3:08
2

Another solution which works as an unpriviledged user is:

setxkbmap -option apple:badmap

As a priviledged user this can also be used to fix the issue in the X config of the keyboard device with something like:

# /etc/X11/xorg.conf.d/90-custom-kbd.conf
Section "InputClass"
    Identifier "keyboard defaults"
    MatchIsKeyboard "on"

    Option "XKbOptions" "apple:badmap"
EndSection
1
  • None of the other solutions worked for me. This one did. I'm on a MBP late 2015 with US keyboard fixing Ubuntu 20.04 LTS running with Parallels Desktop 17. Feb 24 at 0:59
1

On Ubuntu 16.04 with a Mac keyboard you should be able to get a tilde symbol by pressing Right Alt + ] key.

1
  • Wow, I found it on a French Apple keyboard where you normally press Alt + N on OSX. I don't have any ], but it worked with Right Alt + N (but not Left Alt + N!)
    – hsandt
    Aug 10, 2020 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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