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.
Why not just copy & paste?
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.
I would consider revising the command sequence to:
The added
deleteToBeginningOfLine
maintains the indenting of the duplicated line.I had a big trouble to unlock .plist file on MacOS Sierra and Xcode 9, even @Tim decision didn't work for me. If you have the same problem, go to terminal and do this:
Few other possible ways to do this are also described here.
Then in nano editor click
^W
and type 'insertions' to jump to 'Insertions and Indentations' part. Just under<dict>
tag paste this xml-snippet:Press
control + X
, thenY
, thenEnter
to save the file in nano editor.UPD: I came up with a better decision, which adds an additional line before duplication (useful when you want to duplicate a line which has an another line just below it):
Any sublime text users that would like to match sublime's duplicateLineUp and duplicateLineDown in XCode, please add the following to your IDETextKeyBindingSet.plist file
Today I wrote a very small plugin for Xcode 5 that delete and duplicate lines and selections.
You can download it from my GitHub repo: XcodeKit Plugin - https://github.com/ptfly/XcodeKit
insertLineBreak needed at least for me to make copy on new line, without it i got copy on same line
Duplicate line(s) supported. (This works in Xcode 9.2)