xcodelineduplicate-data

Xcode duplicate/delete line


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 possible to change the system wide keybindings but that's not what I'm after.


Solution

  • 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