Coming from Eclipse and having been used to duplicate lines all the time, it\'s pretty strange finding out that Xcode has no such function. Or does it?
I know it\'s
Use user scripts.
There are scripts to move and delete lines yet. You have to define key binds for those scripts (menu Scripts -> Edit User Scripts..., under xCode 3.2).
To duplicate line, you have to make your own script. But it's very simple ! Duplicate the "Move Line Down" script and remove the line which delete selected text :
delete (paragraphs startLine through endLine)
To Delete Line in Xcode 10.1, please follow the steps of below screenshot to add a shortcut key.
OK, so I had this working for a while and then suddenly it broke. Now I have combined from different posts here and found a solution that works for XCode 6.3.1.
Go to /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/
with Finder.
find the folder named Resources. Right Click it, press Get Info, unlock the sharing & permissions setting (By pressing the lock) and set it to Read & Write for all.
Enter the folder and find the file IDETextKeyBindingSet.plist. Right Click it, press Get Info, unlock the sharing & permissions setting (By pressing the lock) and set it to Read & Write for all.
Open the file with XCode (Default)
Find deletions, right click and add a new row. Name it for example Delete Line. In the value field, type: selectLine:, deleteBackward:
. (This can also be done for duplicate line: selectLine:,copy:,moveToEndOfLine:,insertNewline:,paste:,deleteBackward:
)
Triple click to select the whole line, command-c to select and command-v twice to duplicate it. It's not an Xcode function, it's just part of the OS.
For Xcode 6.1 got to Xcode > Preferences > KeyBindings > Text And there is "Delete to End of Line" and assign a key you want.
Still there is no built-in way to duplicate lines, as of Xcode 9. And custom key bindings seem to have problems.
Update: Xcode 10.0 beta 6 (10L232m) is the same.