Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marcolabreu/0053e7286467e079ef706dbd3d4c46b9 to your computer and use it in GitHub Desktop.
Save marcolabreu/0053e7286467e079ef706dbd3d4c46b9 to your computer and use it in GitHub Desktop.
Xcode - Duplicate Line key binding

Key binding to duplicate lines in Xcode 11

Many posts and solutions add 3 different commands to IDETextKeyBindingSet.plist, but only Duplicate Lines is currently required.

  1. Delete Line already exists in Xcode 11, just add a keybind to it.
  2. Duplicate Current Line is not necessary because the solution bellow works correctly if the cursor is in a line or if multiple lines are selected. In both cases, it has some benefits over commands found in older posts: the clipboard is not touched, and a single undo reverts the change.

Steps

  1. Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
  1. Open IDETextKeyBindingSet.plist with a text editor.

  2. Add this in:

<key>Duplication</key>
<dict>
    <key>Duplicate Lines</key>
    <string>selectParagraph:, delete:, undo:, moveRight:, yankAndSelect:</string>
</dict>
  1. Open Xcode and go to Xcode preferences -> Key Bindings -> Text tab -> Scroll till you see Duplication

  2. Click on Duplicate Lines, add a shortcut for it, eg. Cmd + D (remove any other bindings for this key)

Credit

The code for the solution above was found on this StackOverflow post in the answer proposed by Rychu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment