Custom key bindings in Xcode 8

I hate that Xcode doesn’t include a duplicate line shortcut. I have to keep adding it in every time a new version of Xcode comes out and every time, I have to Google it, so I’m pasting the SO post here that worked most recently. There must be a better way, but until I figure that out, here’s what has worked for me.

Open

/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

And add:

<key>Custom Commands</key>
<dict>
    <key>Cut Current Line</key>
    <string>selectLine:, cut:</string>
    <key>Copy Current Line</key>
    <string>selectLine:, copy:</string>
    <key>Duplicate Current Line</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
</dict>

Then restart Xcode and go to Preferences -> Key Bindings and assign your shortcuts.

This was taken from: https://stackoverflow.com/a/41579618

4 comments

  1. Didn’t work for me in Xcode 9—now seems to be /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

  2. Also I found

    […]
    Duplicate Current Line
    moveToEndOfLine:, moveToBeginningOfLineAndModifySelection:, copy:, moveToEndOfLine:, insertNewline:, paste:, insertNewline:
    […]

    to be better because it doesn’t include this weird newline (on my machine).

    1. The best version of duplicate current line is below, because it doesn’t crush your your current clipboard data:

      moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.