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
Three step to delete current line (see too long, but do very fast :D)
Cmd + → : move to end of line
Cmd + Delete : delete to begin of line
Delete : delete empty line
The whole point is NOT to use the Cmd-C
/Cmd-V
shortcuts. I have the same issue coming from IntelliJ, and being able to just duplicate lines with Cmd-D
and delete them with Cmd-Y
is a big time saver.
It's been bugging me ever since. However, it looks like someone else has found a solution that works.
In short, create a file ~/Library/KeyBindings/PBKeyBinding.dict
with the following content and restart Xcode.
{
"^$K" = (
"selectLine:",
"cut:"
);
"^$D" = (
"selectLine:",
"copy:",
"moveToEndOfLine:",
"insertNewline:",
"paste:",
"deleteBackward:"
);
}
This will create two shortcuts: Ctrl-Shift-K for deleting the current line and Ctrl-Shift-D for duplicating the current line. Please note that this will only work if you are NOT using a custom key binding set in Xcode. Switch to "XCode Default" and things should work. Tested on XCode 3.2 on Snow Leopard.
More information on Mac OS X key bindings: http://funkworks.blogspot.it/2013/03/republishing-of-wwwerasetotheleftcompos.html
Delete a line like eclipse CTRL+D (tested on Xcode 4.5.1) :
First of all, change these rights :
sudo chmod 666 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
sudo chmod 777 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/
Open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
with Xcode himself and add this new entry :
deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:
Restart Xcode and open Xcode > Preferences > KeyBindings. Find your macro and define a shortkey :
There's a solution for XCode4 line duplication over here
I've also added line deletion to the plist:
<key>Remove Line</key>
<string>selectLine:, deleteBackward:</string>