EDIT: Aug 16, 2022
After every update to Xcode I have to fix this duplicate line issue. Again did it today. The entry for line duplication from the IDETextKeyBindingSet.plist
file always gets deleted but not the other custom entries. But in the Xcode's key bindings
my shortcut remains. So every time I have to open the IDETextKeyBindingSet.plist
file and add these lines under the <key>Insertions and Indentations</key>
section under <dict>
, and restart Xcode to make line duplication shortcut work.
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
EDIT: Jul 12, 2020
After update to Xcode 11.5 again my duplicate line
key entry from the plist
file was gone. I had to add it again. The key binding was still there though.
EDIT: Sep 17, 2019
After update to Xcode 10.3 again my duplicate line
key entry from the plist
file was gone. I had to add it again. The key binding was still there though.
EDIT: May 28, 2019
After update to Xcode 10.2 again my duplicate line
key entry from the plist
file was gone. I had to add it again. The key binding was still there though.
EDIT: Dec 23, 2018
After update to Xcode 10.1 all my shortcuts broke again. But something different was that after updating the plist file for line duplication, I didn't have to define my key bindings, they were already there. Strange.
EDIT: OCT 14, 2018
Xcode 10: Somebody high up at Apple really loves copy/paste, and makes sure that with every version of Xcode update, the line duplication is removed from everyone's install. We developers have been extremely frustrated by this nonsense going on in Xcode since forever, the only IDE with no line duplication option. I just updated to Xcode 10, and as you guessed it - all my shortcut keys are removed along with my line duplication functionality. However, it is fixable like in the original answer. A slight difference this time is that you will need the following line:
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
EDIT: Xcode 9: I had to redo my shortcuts and line duplication and
deletion, but good thing is that now you can edit IDETextKeyBindingSet.plist again. This high up Apple guy must be on vacation when they released this version.
EDIT: Xcode 8: Buggy, you can't modify the IDETextKeyBindingSet.plist file at all. Xcode resets it on start. This high up guy at Apple is really determined to make us use copy/paste instead of simple line duplication like in all other IDEs out there.
EDIT: Xcode 7.1 and still there are no shortcuts for line duplication and deletion. This is the only IDE I have ever worked with with no such shortcuts. And I can't imagine life of a developer without these two critical shortcuts.
Here is how it can be done:
First we need to modify a plist file that lives inside the Xcode.app bundle (needs sudo to edit)
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
Then look for <key>Insertions and Indentations</key>
and under the <dict>
tag add the following:
<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>
Then find the and these inside the section <key>Deletions</key>
under the <dict>
tag:
<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<string>selectLine:, delete:</string>

Now Open/Restart Xcode, go to Preferences and go to the “Key Bindings” tab. Use the search bar to filter and look for the new shortcuts. Then click in front of the shortcut description to assign it a shortcut of your liking. Make sure your shortcut doesn't conflict with existing shortcuts.
