Completion Dictionary is a free Xcode plugin that enhances Xcode’s built-in code completion mechanism. You simply type a few letters - either the abbreviation of a macro or the initials of a symbol name - and press the completion shortcut. Completion Dictionary will do the rest.
A set of user defined macros is searched for an entry matching the abbreviation you’ve typed in. The macros may also contain a number of placeholders. The text range of these placeholders will be preselected, ready to be replaced with your further input.
Completion Dictionary integrates the built-in code completion capabilities of Xcode. If there’s no macro found for a given abbreviation, Xcode’s code completion will be performed instead of macro expansion.
For Xcode 3, copy ODCompletionDictionary.xcplugin to one of these locations:
For Xcode 2, copy ODCompletionDictionary.pbplugin to one of these locations:
Finally, quit and restart Xcode. After successful installation Completion Dictionary logs its version number to the Console whenever the plugin gets loaded into Xcode.
Completion Dictionary 4.0 stores its configuration data in a new location. You therefore have to move and rename an existing configuration file from ~/Library/KeyBindings/CompletionKeyBinding.dict to ~/Library/Application Support/Completion Dictionary/Configuration.plist.
Further, the completion method selector has changed from completeUsingDictionary: to completionDictionaryExpandMacro:, so you have to update your key bindings as described in the following section.
By default the Edit > Completion Dictionary > Expand Macro command can be invoked with Control-Escape. You may customize this shortcut in Xcode’s Key Bindings preferences.
Unfortunately, Xcode doesn’t let you bind the Escape key (without any modifiers) to a menu command, which would be a very convenient shortcut though. However, it is possible to establish this binding by editing the appropriate key binding file manually.
If you haven’t yet created a custom “Key Binding Set” in Xcode’s Key Bindings preferences, you can establish the key binding in
This file must contain at least the following lines:
If you are using a custom key binding set, Xcode ignores the settings in PBKeyBinding.dict. Therefore you must edit your custom key bindings file instead, which can be found at
Open this file in Property List Editor, select Edit > Show Strings as Unicode and add a key binding to the “text” dictionary where the key is \U001B and the selector is completionDictionaryExpandMacro:.
Choose Edit > Completion Dictionary > Edit Macros or type Command-Option-Comma to open the macro editor. You will see a set of pre-installed example macros, ready to be used immediately. You can add your own macros by entering several abbreviation-macro pairs, e.g:
Abbreviation | Macro |
---|---|
ls | NSLocalizedString(@"<#string#>", @"<#comment#>") |
oi | objectAtIndex:<#index#> |
span | <span class="<#?class#>"><#text#></span> |
( | (<#%clipboard#>) |
A macro may contain one or more placeholders for variable names, arguments and other program-specific information. A placeholder is delimited by <# and #> and can be inserted conveniently by choosing an item from the Insert Placeholder pull down menu.
Completion Dictionary includes a comprehensive set of default macros, illustrating lots of the plugin’s capabilities. They provide a good starting point for your own macro definitions. If you wish to restore the default configuration at a later point, you just have to remove (or rename) your custom configuration file at
and restart Xcode.
The default configuration includes macros for C, Objective-C and HTML. Here are just a few noteworthy macros:
Once you’ve configured the dictionary you can use it as follows: Type the abbreviation and press the completion shortcut (Control-Escape by default). If the abbreviation is found in the dictionary, the corresponding macro is inserted, otherwise Xcode’s built-in code completion is invoked. If the completion doesn’t deliver the desired results, you can undo this operation with Command-Z.
If the macro contains any placeholder the first placeholder will be selected, so you can replace it with your own code right away. If there’s more than one placeholder you can cycle through the placeholders by either choosing Edit > Select Next Placeholder or typing
If the macro contains any query placeholder, a panel will appear, allowing you to fill out the requested fields. Note that you can navigate through the fields using the up/down arrow keys. Once you’ve completed your input you can confirm with Return or dismiss this panel by pressing Escape.