Pressing cmd + x without selecting text in other IDEs, cuts the complete line. Same goes for cmd + c which copies, instead of cutting. Otherwise, if some text is selected, only that region is cut.

How do I do this in XCode?

I added the following in the IDETextKeyBindingSet.plist to add cutting line and copying line functionality :

<key>My Custom Commands</key>
    <key>Cut Current Line</key>
    <string>selectLine:, cut:</string>
    <key>Copy Current Line</key>
    <string>selectLine:, copy:</string>

But obviously binding these to cmd + x (or c) doesn't allow cutting/copying selected region. I understand I can set it to some other keybinding. But, as a force of habit, cmd + x (or c) suits better.

Is there any way to do this? Maybe an extension?

[PS I asked the same question on StackOverflow, but realised, this is more apt place]

  • There's an extra </dict> at the end of the plist. You might want to remove that so that people don't accidentally mess up the plist file if they copy the above text. – Peter Schorn May 27 at 8:26
  • @PeterSchorn Done, thanks. – Saurabh Shrivastava May 27 at 9:41

That is correct. (Xcode 10)

  1. Add the entry for cut line and copy line in the IDETextKeyBindingSet.plist file
  2. Save the IDETextKeyBindingSet.plist
  3. Restart Xcode
  4. Set a key for the new command through xcode > preferences > key bindings > My Custom Commands
  5. Resolve conflicts

Example: /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <key>Cut and Copy</key>
        <key>Cut Current Line</key>
        <string>selectLine:, cut:</string>
        <key>Copy Current Line</key>
        <string>selectLine:, copy:</string>
        <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>

Xcode keybinding (Cut and Copy): enter image description here

Xcode conflict resolve (Cut and Copy): enter image description here

| improve this answer | |
  • I've didn't tried but I think it doesn't fit the need of either copy the line or the selected text. Am I wrong? – AnthoPak Jun 10 '19 at 15:26
  • I see what you mean, that's correct, it does not take into consideration if text has been selected or not. If the information is not useful I can remove this post. – Francois Jun 11 '19 at 16:08
  • 2
    What I usually do is I add shift to cut/copy keys to cut/copy a line instead of the selected text eg. | Copy selected text cmd+c | Cut selected text cmd+x | Copy line shift+cmd+c | Cut line shift+cmd+x – Francois Jun 12 '19 at 7:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .