Up until Xcode 8.0, it was possible to customize IDETextKeyBindingSet.plist file. However, now it seems like modifying this file causes Xcode to stop behaving normally (e.g. arrow keys stop working) and it is no longer seem possible to create your own shortcut keys.
Xcode never had line duplication and insertion shortcuts. Previously it was possible to add them in IDETextKeyBindingSet.plist by adding the following in the right places:
<key>Insert New Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
<key>Insert New Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<string>selectLine:, delete:</string>
Does anybody know how to achieve the same in Xcode 8.0 or above?
I wonder if developers at Apple use Xcode? And if they check StackOverflow? Or are they forbidden to do either by their employment contracts?
EDIT: In Xcode 9.x it seems to be working again.
EDIT: In Xcode 10.0 it is broken again.
EDIT: In Xcode 10.1 it is still broken and also copy/paste is partially broken, meaning it doesn't always work. (I am still on High Sierra)
Delete Entire Line ( ⌘ + D ) To define custom keybindings, go to Xcode settings (press ⌘ + ,), navigate to the Key Bindings tab, and use the filter field to search for “Delete Line”. Double click into the Key field, then press your preferred key combo. I use ⌘ + D (for Delete Line).
Confirmed, still working in Xcode 12.5.1 on macOS Big Sur 11.5.1
open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
Add the following lines into the root dictionary
<key>Sublime Commands</key>
<dict>
<key>Cut Current Line</key>
<string>selectLine:, cut:</string>
<key>Copy Current Line</key>
<string>selectLine:, copy:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
</dict>
Key Bindings
settings and assign any shortcut you want to the new three commands. Just search for their key
s.It's a shame that in the 21st century you still have to manually add such basic shortcuts.
The steps have to be repeated after every update of Xcode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With