XCode : How to use cmd + x to either cut the current line (if no text is selected) or cut the selected text 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 :

&lt;key&gt;My Custom Commands&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;Cut Current Line&lt;/key&gt;
    &lt;string&gt;selectLine:, cut:&lt;/string&gt;
    &lt;key&gt;Copy Current Line&lt;/key&gt;
    &lt;string&gt;selectLine:, copy:&lt;/string&gt;
&lt;/dict&gt;


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]
That is correct. (Xcode 10)


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




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

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Cut and Copy&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Cut Current Line&lt;/key&gt;
        &lt;string&gt;selectLine:, cut:&lt;/string&gt;
        &lt;key&gt;Copy Current Line&lt;/key&gt;
        &lt;string&gt;selectLine:, copy:&lt;/string&gt;
    &lt;/dict&gt;
    &lt;key&gt;Duplication&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;Duplicate Current Line&lt;/key&gt;
        &lt;string&gt;moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:&lt;/string&gt;
        &lt;key&gt;Duplicate Lines&lt;/key&gt;
        &lt;string&gt;selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:&lt;/string&gt;
        &lt;key&gt;Delete Line&lt;/key&gt;
        &lt;string&gt;selectLine:, deleteBackward:&lt;/string&gt;
    &lt;/dict&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Xcode keybinding (Cut and Copy):


Xcode conflict resolve (Cut and Copy):