To add custom key bindings in Xcode, you have to edit this file (su privileges required):
'/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist
To facilitate this, just add the following code to .bash_profile
/.zshrc
:
# Add custom commands to Xcode.
# Run this every time Xcode updates.
function addCustomCommandsToXcode() {
PLB="/usr/libexec/PlistBuddy"
PLIST="/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist"
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down' string 'selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yank:, moveUp:, moveToEndOfParagraph:, moveToEndOfLine:'" "$PLIST"
$PLB -c "Add :'Custom Commands':'Delete Current Line' string 'deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:'" "$PLIST"
}
Each line is a new custom command of your choice. The code above has commands for deleting the current line and duplicating the current selection.
NOTE: you will have to do this every time Xcode is updated!
- Call
addCustomCommandsToXcode()
from the terminal; - Open Xcode and go to
Xcode Preferences
->Key Bindings
; - Search for your custom commands and add a shortcut to them;
- ?
- Profit.
Thanks for the fix!