13

Up until Xcode 8.0, it was possible to customize IDETextKeyBindingSet.plist file. However, now it seems like modifying this file causes Xcode to stop behaving normally (e.g. arrow keys stop working) and it is no longer seem possible to create your own shortcut keys.

Xcode never had line duplication and insertion shortcuts. Previously it was possible to add them in IDETextKeyBindingSet.plist by adding the following in the right places:

<key>Insert New Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
<key>Insert New Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<string>selectLine:, delete:</string>

Does anybody know how to achieve the same in Xcode 8.0 or above?

I wonder if developers at Apple use Xcode? And if they check StackOverflow? Or are they forbidden to do either by their employment contracts?

EDIT: In Xcode 9.x it seems to be working again.

EDIT: In Xcode 10.0 it is broken again.

EDIT: In Xcode 10.1 it is still broken and also copy/paste is partially broken, meaning it doesn't always work. (I am still on High Sierra)

9
  • Post this in the private Xcode forum and maybe an apple dev will answer it.
    – David H
    Commented Oct 2, 2016 at 11:29
  • 3
    @DavidH This question is not new for Apple developers, and for years I am observing that they simply don't answer this question. To me it seems like Apple has a policy that features which they don't want to add or don't believe in, they simply don't answer them either. Otherwise all other IDEs, at least the major ones, have line duplication and deletion shortcuts, but XCode has intentionally kept them out, and never told their philosophy behind it. I can't imagine life of a developer without these two critical shortcuts, which are needed again and again while writing code.
    – zeeshan
    Commented Oct 2, 2016 at 11:40
  • 1
    My point is that you are more likely to have some knowledgable person post there, or even on the older Xcode listserv, than here. IMHO. It cannot hurt and will only take a few minutes of your time. In fact, I'll post this on the listserv as I've been on it for years - if I get a response I'll update this topic.
    – David H
    Commented Oct 2, 2016 at 15:17
  • 3
    Same problem here. Up until Xcode 8 I've had to do this ridiculous dance of replacing IDETextKeyBindingSet.plist every time I update Xcode, just to get duplicate line functionality that every other IDE in the world has but Apple refuses to add to Xcode. Now with XCode 8 this no longer works. It's unbelievably annoying and slow to copy and paste a line of code when one should just be able to press command-D.
    – soleil
    Commented Oct 5, 2016 at 22:59
  • 1
    you might accept the answer, so that others know it's still working
    – duongel
    Commented Nov 8, 2017 at 14:27

3 Answers 3

34

Confirmed, still working in Xcode 14.3 on macOS Ventura 13.3

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

  2. Add the following lines into the root dictionary

    <key>Sublime 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:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
    </dict>
  1. restart Xcode
  2. go into the Key Bindings settings and assign any shortcut you want to the new three commands. Just search for their keys.

It's a shame that in the 21st century you still have to manually add such basic shortcuts.

Caveat

The steps have to be repeated after every update of Xcode.

13
  • thanks for the update. I'll check it shortly. What OS version you are using. I am on El Capitan.
    – zeeshan
    Commented Jan 11, 2017 at 0:26
  • I'm on macOS Sierra 10.12.2
    – duongel
    Commented Jan 11, 2017 at 10:21
  • 2
    Unfortunately this is not working for me. I have xCode 8.2.1 and Sierra 10.12.3
    – human4
    Commented Feb 4, 2017 at 15:34
  • I confirm that it is working for me in Xcode 8 on Mac ElCapitan
    – gutte
    Commented Mar 7, 2017 at 13:18
  • Updating XCode to version 8.3.1 and macOS to 10.12.4 revertedIDETextKeyBindingSet.plist defaults. Needed to re-add the above lines to file and restart XCode.
    – Doms
    Commented Apr 10, 2017 at 13:19
9

The above answer seems to be broken in Xcode 9.

Here is another solution that I have verified does work in Xcode 9 GM:

<key>Custom Commands</key>
<dict>
    <key>Duplicate Current Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>
3

The previous answer left erroneous whitespace when I tried it. This works for me in Xcode 9:

selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.