MacOS – DefaultKeyBinding.dict: moveWordBackward: is not overridden on macOS Sierra

emacskeybindingskeyboardmacos

I've recently started using a new computer (actually a Hackintosh) with macOS Sierra. My previous development machine is still on El Capitan. In the process of setting up the new machine I've added ~/Library/KeyBindings/DefaultKeyBinding.dict.

Most keybindings (specifically option+f for moving the cursor a word forward) work fine. However, option+b for moving the cursor a word back simply acts as a dead key and types a ˘ character.

The relevant section of DefaultKeyBindings.dict looks like this:

<key>~b</key>
<string>moveWordBackward:</string>

Adding this specifically to, e.g. TextMate's specific ~/Library/Application Support/TextMate/KeyBindings.dict file results in option+b working in TextMate, but obviously has no effect elsewhere:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>~b</key>
    <string>moveWordBackward:</string>
</dict>
</plist>

How can I avoid having to change my habits with regard to moveWordBackward:?

Best Answer

I finally solved this after realizing that the difference between my El Capitan (10.11) machine and Sierra (10.12) was the new dead key on Option-b. Whether this is a difference between keyboard layouts or OS versions I haven't been able to determine.

It seems that KeyBindings are unable to override dead keys. Using Ukelele I was able to change the output of option-b to some other character. I then installed this keyboard layout and moveWordBackward: began working with no further modifications.

  1. In Ukelele, Choose File->New From Current Input Source
  2. Right click on the Layout Name and choose Set Layout name and Script
    • Rename to something like U.S. No B Dead Key
  3. Double click on the layout name to open the layout editor.
  4. Hold option, then right click the b key; choose Make Output
  5. Enter any other character; it will be overridden by DefaultKeyBinding.dict
  6. Save
  7. Choose File-> Install For Current User
  8. In the Keyboard Preferences, choose your new keyboard layout.