How do I create a Delete-Line Keyboard shortcut in Xcode 8? The Xcode 3 solutions do not work anymore

后端 未结 13 1475
故里飘歌
故里飘歌 2020-12-07 10:38

In previous versions of Xcode it was possible to create a key binding to delete the current line. There were different solutions and they are described for exam

13条回答
  •  孤街浪徒
    2020-12-07 10:53

    Got it! This works in XCode 4.3 through 4.5 and requires no extra applications and is XCode specific.

    This solution is basically the same as the Duplicate Line command described here:

    Edit the plist file

    It's at /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

    Note that:

    • the linked answer suggests using XCode for this, but I find that this crashes XCode
    • this path is for Lion - it may vary for other OS versions
    • you may have to sudo or change permissions to edit this file
    • close XCode before editing

    Add a new element

    Add this text just ABOVE the close of the at the bottom of this file

        Custom
        
          Delete Current Line In One Hit
          moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph: 
        
    

    Note that:

    • This is inside the existing so there is a after this
    • This associates the named action "Delete Current Line In One Hit" to the three key actions in the string. I played around with different options here to get the right combination. For instance, if you try moveToBeginningOfLine, deleteToEndOfLine instead of vice versa, then using it on empty lines will delete the line and the entire next line. Which is unpleasant

    Save this and open XCode

    Add a new key binding in XCode

    See the screenshots for this in the linked answer or do this:

    1. Open XCode Preferences
    2. Select Key Bindings
    3. Click on All
    4. In the SEarch box type "Delete" and search for "Delete Current Line in One Hit"
    5. Add your new binding.

    This should do it but for one caveat. I could never get XCode to save the new binding. The same problem is described here though my workaround had a slight variation:

    1. Create a duplicate of the Default bindings (hit the + button at the bottom left of the Bindings window and create a duplicate)
    2. Set the new binding in the duplicate
    3. Close the preference dialog (that's the variation!)
    4. Open preferences again and make a new duplicate of the old duplicate and delete the old duplicate.

    What a rigmarole, eh? But it works. Now I have Ctrl+D mapped to delete the entire current line in XCode 4.3 on Lion.

提交回复
热议问题