Many posts and solutions add 3 different commands to IDETextKeyBindingSet.plist, but only Duplicate Lines is currently required.
Delete Linealready exists in Xcode 11, just add a keybind to it.Duplicate Current Lineis not necessary because the solution bellow works correctly if the cursor is in a line or if multiple lines are selected. In both cases, it has some benefits over commands found in older posts: the clipboard is not touched, and a single undo reverts the change.
- Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
-
Open
IDETextKeyBindingSet.plistwith a text editor. -
Add this in:
<key>Duplication</key>
<dict>
<key>Duplicate Lines</key>
<string>selectParagraph:, delete:, undo:, moveRight:, yankAndSelect:</string>
</dict>-
Open Xcode and go to
Xcode preferences->Key Bindings->Text tab-> Scroll till you seeDuplication -
Click on
Duplicate Lines, add a shortcut for it, eg.Cmd + D(remove any other bindings for this key)
The code for the solution above was found on this StackOverflow post in the answer proposed by Rychu.