Skip to content

Instantly share code, notes, and snippets.

@emotality
Last active March 27, 2026 17:20
Show Gist options
  • Select an option

  • Save emotality/b1bcb2bb8a07921f9c8cad1c969daedf to your computer and use it in GitHub Desktop.

Select an option

Save emotality/b1bcb2bb8a07921f9c8cad1c969daedf to your computer and use it in GitHub Desktop.
Xcode - Duplicate Line key binding

NOTE (2022-07-09): Xcode finally added this functionality in Xcode 14, please see release notes here:

New Features in Xcode 14 Beta 3
When editing code, the Edit > Duplicate menu item and its corresponding keyboard shortcut now duplicate the selected text — or the line that currently contains the insertion point, if no text is selected. (8614499) (FB5618491)


Xcode line duplicate

Bind keys to duplicate lines in Xcode

  1. Close Xcode

  2. 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 Current Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
    <key>Duplicate Lines</key>
    <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
    <key>Delete Line</key>
    <string>selectLine:, deleteBackward:</string>
</dict>
  1. Open Xcode and go to Xcode preferences -> Key Bindings -> Text tab -> Scroll till you see Duplication

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

@xgqfrms

xgqfrms commented Mar 27, 2022

Copy link
Copy Markdown

✅ awesome!

@lifution

Copy link
Copy Markdown

Amazing! 👍🏻

@Kadmiv

Kadmiv commented Apr 23, 2022

Copy link
Copy Markdown
<key>Duplicate Lines</key>
<string>selectLine:, deleteToEndOfLine:, undo:, yank:, moveToBeginningOfLine:, yank:</string>

<key>Duplicate Selection</key>
<string>deleteToEndOfLine:, undo:, yank:, moveToEndOfLine:, insertNewline:, yank:</string>

@nkalvi

nkalvi commented Jul 7, 2022

Copy link
Copy Markdown

As of Xcode 14 beta 3:
Duplicate menu item and its corresponding keyboard shortcut now duplicate the selected text

Xcode 14 Beta 3 Release Notes

@emotality

Copy link
Copy Markdown
Author

As of Xcode 14 beta 3: Duplicate menu item and its corresponding keyboard shortcut now duplicate the selected text

Xcode 14 Beta 3 Release Notes

Thanks! I updated the gist 😊

@purified-water

Copy link
Copy Markdown

Thank you, works great on Xcode 13.2.1

@taehun0933

Copy link
Copy Markdown

Thank you, but in my case, the 'Delete Line' feature often doesn't work with beep codes. In this case, if you search directly for the key to which it is mapped in the key bindings in the settings and then return to the editor, it works fine again, do you know what caused this bug and how to fix it?

@kopyl

kopyl commented Jan 24, 2025

Copy link
Copy Markdown

Is there a way to hold down command + delete and have lines deleted one by one as in VSCode?

@jahirvidrio

jahirvidrio commented Aug 20, 2025

Copy link
Copy Markdown

Using duplicate:, I was also able to recreate VS Code’s “Copy Line Up” with just:

selectLine:, duplicate:, moveUp:

<key>Edit menu (ext)</key>
<dict>
    <key>Copy Line Up</key>
    <string>selectLine:, duplicate:, moveUp:</string>
    <key>Copy Line Down</key>
    <string>selectLine:, duplicate:</string>
</dict>

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