There is a Duplicate
command in the Edit Menu (with a default shortcut of ⌘D), but it is (as Halley pointed out) meant for duplication in the Interface Builder part of Xcode.
So, how do you (easily) duplicate a line in Xcode 4?
Related question (with a working answer) for Xcode 3 ... and which does not work for Xcode 4.
Because it is tedious and entails too much hand-acrobatics:
either (1): moving to line beginning and then pressing ⇧^E, then copying with ⌘C, moving to new line, alligning cursor, and finally pasting with ⌘V;
or (2): ^A (set cursor to line begining), ^SPACE (set mark), ^E (set cursor to line ending), ⇧^W (Select to Mark
; customized), copy, new line, etc.
As Frank Schröder (in the related question) put it:
The whole point is NOT to use the Cmd-C/Cmd-V shortcuts.
Go to this folder which contains dark side of the force:
/Developer/Library/PrivateFrameworks/IDEKit.framework/Resources
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources
.Open IDETextKeyBindingSet.plist
.
Add a new dictionary and a new command item as the screenshot below (name them what you want):
That's: selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:
Restart Xcode and go to Preferences - Key Bindings, search for your command.
Set a key combination for the command:
Finally unleashed the power of key bindings on Xcode... Enjoy it!