Skip to content

Instantly share code, notes, and snippets.

@nahonen
Created February 28, 2019 10:25
Show Gist options
  • Save nahonen/40d2492a4724288f0fac085da57a81fb to your computer and use it in GitHub Desktop.
Save nahonen/40d2492a4724288f0fac085da57a81fb to your computer and use it in GitHub Desktop.
Copy the current line in Xcode

Copy the current line in Xcode

Based on: https://gist.github.com/emotality/b1bcb2bb8a07921f9c8cad1c969daedf

This key binding copies the current line that the marker sits on, and moves the marker to the end of the line.

Bind keys to copy the line in Xcode

  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. You might have to copy the file to a different location since it might be locked. Remember to save an copy of the original file.

  2. Add this in:

<key>Copy Line</key>
<dict>
    <key>Copy Current Line</key>
    <string>moveToEndOfLine:, moveToBeginningOfTextAndModifySelection:, copy:, yank:, paste:</string>
</dict>
  1. Open Xcode and go to Xcode preferences -> Key Bindings -> Text tab -> Scroll until you see Copy Line

  2. Click on Copy Current Line, add a shortcut for it, eg. Shift + Cmd + C (remove or move any other bindings for this key, or choose another one altogether)

You probably need to restart Xcode in order for the new binding to show up inside preferences.

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