Xcode duplicate/delete line

前端 未结 22 1650
不思量自难忘°
不思量自难忘° 2020-12-04 04:59

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

相关标签:
22条回答
  • 2020-12-04 05:39

    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

    0 讨论(0)
  • 2020-12-04 05:40

    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

    0 讨论(0)
  • 2020-12-04 05:40

    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:
    

    enter image description here

    Restart Xcode and open Xcode > Preferences > KeyBindings. Find your macro and define a shortkey :

    enter image description here

    0 讨论(0)
  • 2020-12-04 05:41

    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>

    0 讨论(0)
提交回复
热议问题