Custom Key Bindings in XCode for TextMate Users

I’ve recently been getting doing some development in XCode and Interface Builder (learning the iPhone SDK). I found XCode a real pleasure to work with (especially its unique form of “Code Sense”), but I did miss some of TextMate’s default text shortcuts, specifically “delete line” and “duplicate line.” There are some Key Binding options in the Preferences but nothing like those.

I asked a question on StackOverflow, a great new wiki/forum/help site for programmers and was pointed to the Cocoa docs and some useful posts where I figured out how to put together these simple key bindings. Results follow.

Create the file ~/Library/KeyBindings/PBKeyBinding.dict if it doesn’t exist and add the following to the file:

    "^$K" = (
    "^$D" = (

The above snippet creates a key binding for “^$K” (Control-Shift-K – aka TextMate’s “delete line”) and “^$D” (Control-Shift-D – AKA TextMate’s “duplicate line”). You can see there’s loads of different macro’s you can add to this file to make unique key binding snippets. Note that they won’t take effect until you restart XCode.

January 1st, 2009 | Permalink