nullstream weblog - Adding custom key bindings to Xcode


« Windows 7 x 7 | Firmware Elves »

Adding custom key bindings to Xcode

Xcode

February 21, 2009 02:34 AM PST

If you don't already have a custom Key Binding Set then this gives good info:
http://www.typeoneerror.com/custom-key-bindings-in-xcode-for-textmate-users/

And this is a reference of commands and keys.
http://www.erasetotheleft.com/post/mac-os-x-key-bindings/#comment-101

If you DO have a customer key binding set already like I do, then you have to use the Property List Editor to load your binding file:
~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys
In the editor, select View > Show Strings as Non-lossy ASCII. Add your key bindings to the "text" dictionary. If you want more than one command bound to a key you need to create an Array with your keystroke. Expand the new key with the triangle on the side, then use the 'add Child' tool bar button to create a new child for each command. Or hit the + on the side for each new entry.

My move line macros (ctrl-shift+up arrow, ctrl-shift+down arrow):
^$\UF700
selectLine:
cut:
moveUp:
paste:
moveUp:

^$\UF701
selectLine:
cut:
moveDown:
paste:
moveUp:

These macros allow you to 'drag' lines up and down with the keyboard. The first link gives a kill line command and a duplicate line (which can also duplicate a multi-line selection).

(By the way I blame the need for these macros on Paul who hooked me on the habit of arranging my local variables by type length.)


Comments (8)
Paul, February 21, 2009 11:50 PM:

I don't arrange variables that way anymore since I use a 'just-in-time-variable-declare' language nowadays.

John, February 22, 2009 12:08 AM:

And that is consistent with your coding standard?

Paul, February 22, 2009 10:14 AM:

Yep.

J, February 22, 2009 07:37 PM:

Meh. You post your key bindings for mine-snark-mine-MG, or crossbow-zoom-fire-MG, then we're talking.

John, February 22, 2009 08:17 PM:

Sorry, trade secret.

Rob, June 3, 2009 08:42 AM:

Cheers for this John! One shortcoming is that if I now go back into XCode and modify my custom key bindings, these changes to the pbxkeys file are overwritten. Do you know of a happier way for custom macros & custom keybindings to coexist? Thanks.

John, June 3, 2009 08:47 AM:

Yeah I noticed the same thing. That is a poor implementation in my opinion. The only work around I know is to make your edits with the property list editor.

Anthony McCormick, February 3, 2010 03:57 PM:

I have create some common eclipse shortcuts at the following post
http://www.betadesigns.co.uk/Blog/2010/02/03/custom-xcode-shortcuts/

Most notably to copy selected text up or down one thing i rely on in Eclipse

^~\U700

copy:
moveUp:
moveToEndOfLine:
insertLineBreak:
insertNewLine:
setMark:
paste:
selectToMark:

^~\U701

copy:
moveDown:
moveToBeginningOfLine:
insertLineBreak:
insertNewLine:
moveUp:
setMark:
paste:
selectToMark:






All links will be marked with the nofollow tag, making them useless for search rankings. Any posts containing spam URLs will then be deleted.