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

后端 未结 13 1423
故里飘歌
故里飘歌 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:46

    An easy solution for XCode 5 and 6:

    Install alcatraz: http://alcatraz.io/ then use it to install the "XCodePlus delete line" plugin:

    Window > Package manager

    There are lots of other awesome plugins as well.

    0 讨论(0)
  • 2020-12-07 10:49

    Rhubarb's answer is correct and works but one thing, there is more simple command in plist file. Follow all instructions of Rhubarb's but

    instead of

    <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
    

    use below

    <string>selectLine:, delete:</string>
    

    This is more clear and throw away any possibility of malfunction.

    I want to write this as a comment, but my "reputation" doesn't allow me to do that.

    0 讨论(0)
  • 2020-12-07 10:50

    try this:

    1. First open Xcode->Preferences

    2. Select Key Bindigs

    3. search Delete Paragraph

    4. Change Delete Paragraph to your shortcut

    0 讨论(0)
  • 2020-12-07 10:50

    First open Xcode->Preferences

    Select Key Bindigs

    Then search Delete

    Change the Delete The End Of Line to your shortcut(I prefer CMD + D)

    Thats All

    0 讨论(0)
  • 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 <dict> element

    Add this text just ABOVE the close of the <dict> at the bottom of this file

        <key>Custom</key>
        <dict>
          <key>Delete Current Line In One Hit</key>
          <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string> 
        </dict>
    

    Note that:

    • This is inside the existing <dict> so there is a </dict></plist> 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.

    0 讨论(0)
  • 2020-12-07 10:53

    It looks as though XCode now uses a plist file versus a dict file, and the new format doesn't support adding multiple commands to a key binding. There also doesn't appear to be a way to add custom commands to bind to either. The only way I've found to get something working is by setting a key binding for the separate actions, such as ^D for deleteToEndOfLine:, then ^L for moveToBeginningOfLine:, giving you ^L+^D to give you the combined effect.

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