Update 2020
Works on Xcode versions: 11.3.1 too
Works in Xcode versions: 7.1, 7.3, 7.3.1, 8.0, 8.1, 8.2, 8.3, 9.0, 9.1, 9.2, 10.0, 10.1, 10.2.1
Instruction
- Give permissions to edit the following files. Most of the time OS will not allow you to edit the files.
for 11.3.1 version
sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources//IDETextKeyBindingSet.plist
sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
below 11.3 versions
sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/
- Edit the the file, by writing the following command: (Open it in sublime or text editor if you can)
for 11.3.1
open
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
for below versions
open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
- Append the following xml snippets:
<key>custom</key>
<dict>
<key>Duplicate Current Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
<key>Duplicate Lines</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Delete Line</key>
<string>selectLine:, deleteBackward:</string>
</dict>
Screenshots
and Restart Xcode and go to Preferences - Key Bindings
, search for the command we typed (Duplicate Lines&Duplicate Current Line).
Thats it.