Skip to content

Instantly share code, notes, and snippets.

@skarol
Created November 22, 2021 12:50
Show Gist options
  • Save skarol/6bec980705243e99995594862fa60855 to your computer and use it in GitHub Desktop.
Save skarol/6bec980705243e99995594862fa60855 to your computer and use it in GitHub Desktop.
Xcode duplicate current line up/down

Xcode duplicate line up/down

Bind keys to duplicate lines in Xcode

  1. Open with text editor
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

If you are using multiple versions of Xcode you have to open this file for each of them. Remember to change /Applications/Xcode.app to path where your Xcode is located.

  1. Add thise lines:
<key>Duplication</key>
<dict>
    <key>Duplicate Current Line Up</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:, moveUp:, moveToEndOfLine:</string>
    <key>Duplicate Current Line Down</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>
  1. Open Xcode and Xcode preferences ⌘ Command + ,Key Bindings and search for duplication

  2. Click on Duplicate Current Line Up, add a shortcut for it, eg. (if you want same shortcut as visual studio code) ⌥ Option + ⇧ Shift + (remove any other bindings for this key)

  3. Click on Duplicate Current Line Down, add a shortcut for it, eg. (if you want same shortcut as visual studio code) ⌥ Option + ⇧ Shift + (remove any other bindings for this key)

@mesqueeb
Copy link

I can't believe this is not built in. 💥😃🔫

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