Coming from Eclipse and having been used to duplicate lines all the time, it's pretty strange finding out that Xcode has none such function. Or does it?
I know it's possible to change the system wide keybindings but that's not what I'm after.
TIA
Coming from Eclipse and having been used to duplicate lines all the time, it's pretty strange finding out that Xcode has none such function. Or does it?
I know it's possible to change the system wide keybindings but that's not what I'm after.
TIA
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.
To delete a line: Control-A to go to the beginning of the line, then Control-K to delete it, and another time Control-K to remove the empty line. (I do not use Xcode very often, but I'm used to that in Emacs and other text inputs with Emacs-like bindings, and it seems to work in Xcode too.)
And to duplicate a line: I don't know of many programs that have a command for that, but usually I just use Copy+Paste - in Xcode it's CUA-like: Control+A to go to the beginning of the line, Shift+Down Arrow to select it, Command+C to copy and Command+Y to paste twice (once overriding the line and once appending to it).
(from a person that types and edits text all the time, so often in different programs, and occasionally gets pissed at having to distract himself with a dumb widget while making a little correction in a text input, that he just cannot avoid remembering these sequences and habits)
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: http://flexgraphix.com/blog/?p=62
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://www.erasetotheleft.com/post/mac-os-x-key-bindings/
Correct path (Snow Leopard, Xcode 3.2.1): ~/Library/Application Support/Xcode/Key Bindings/PBKeyBinding.dict
If you already have customised your Xcode key bindings, you'll have to edit the file: ~/Library/Application Support/Xcode/Key Bindings/<user>.pbxkeys
. Just add the two arrays (described above) to the Root/text
dictionary.
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)
The solution by damien.flament works great and you may need set output to "Discard Output" see the pic below
P.S: I don't know how to comment his answer.
I tried the key bindings solution, but it I couldn't get it to work. However editing my XCode key bindings works like a charm. Here's how I made it.
Open the XCode Key Bindings:
In the Key Bindings Dialog: