Is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫...

Learn is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫ on mac? with practical examples, diagrams, and best practices. Covers macos, emacs, key-bindi...

Reclaiming Alt-F and Alt-B for Word Navigation on macOS

Hero image for Is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫...

Learn how to remap the Alt-F and Alt-B key combinations on macOS to perform word-by-word navigation, preventing them from printing special characters like 'ƒ' and '∫'.

Many users accustomed to Linux or Windows environments, or those who frequently use Emacs-style keybindings, find the default behavior of Alt-F and Alt-B on macOS frustrating. Instead of moving the cursor forward and backward by a word, these key combinations often produce special characters like 'ƒ' (function) and '∫' (integral). This article will guide you through the process of reconfiguring your macOS keybindings to restore the expected word navigation functionality.

Understanding macOS Keybinding Behavior

macOS handles keybindings differently than other operating systems. The Option (or Alt) key is primarily designed to input special characters and diacritics. This is why Option-F produces 'ƒ' and Option-B produces '∫'. To change this behavior, we need to override the default system-wide keybindings. This is typically done by creating or modifying a DefaultKeyBinding.dict file in your user's Library directory.

flowchart TD
    A[User Presses Alt-F/B] --> B{macOS Keybinding System}
    B -->|Default Behavior| C[Input Special Character (ƒ/∫)]
    B -->|Custom Keybinding Exists| D[Execute Custom Action (Move Word)]
    D --> E[Cursor Moves Word Forward/Backward]

macOS Keybinding Decision Flow

Creating or Modifying DefaultKeyBinding.dict

The DefaultKeyBinding.dict file is a property list (plist) file that allows you to customize keybindings for most Cocoa applications on macOS. If this file doesn't exist, you'll need to create it. If it does, you'll add the necessary entries to it. This file should be located in ~/Library/KeyBindings/.

1. Step 1: Create the KeyBindings Directory

Open Terminal (Applications/Utilities/Terminal.app) and create the KeyBindings directory if it doesn't already exist:

2. Step 2: Create or Edit the DefaultKeyBinding.dict File

Use a text editor (like nano, vim, or VS Code) to create or edit the DefaultKeyBinding.dict file. The file should contain the following XML-like structure:

3. Step 3: Apply the Changes

For the changes to take effect, you typically need to restart the applications you want the new keybindings to apply to. For system-wide changes, a full logout/login or reboot might be necessary, though often restarting individual apps is sufficient.

mkdir -p ~/Library/KeyBindings

Command to create the KeyBindings directory

{
    "~f": "moveWordForward:",
    "~b": "moveWordBackward:"
}

Content for DefaultKeyBinding.dict to remap Alt-F and Alt-B

Verifying the New Keybindings

After restarting your applications, open a text editor (like TextEdit, Safari's address bar, or any other Cocoa application) and test the Alt-F and Alt-B key combinations. Your cursor should now jump forward and backward by words, similar to Emacs or traditional Windows/Linux behavior, instead of printing special characters.