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.
Very cool.
Any idea how I can get Ctrl-X Ctrl-S style bindings?! Preferences won't allow me to set them but I can see a few similar key sequences set.
I need this because XCode keeps throwing invisible
^S
chars into the file I'm editing. As an Emacs user of about 30 years,C-x C-s
is so ingrained into my muscle memory that I can't stop doing it. XCode keeps bugging me with inconvenientinvalid character in source file
messages.