Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9.x Line Duplication and Deletion

Tags:

xcode8

Up until Xcode 8.0, it was possible to customize IDETextKeyBindingSet.plist file. However, now it seems like modifying this file causes Xcode to stop behaving normally (e.g. arrow keys stop working) and it is no longer seem possible to create your own shortcut keys.

Xcode never had line duplication and insertion shortcuts. Previously it was possible to add them in IDETextKeyBindingSet.plist by adding the following in the right places:

<key>Insert New Line Below</key>
<string>moveToEndOfLine:, insertNewline:</string>
<key>Insert New Line Above</key>
<string>moveUp:, moveToEndOfLine:, insertNewline:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<string>selectLine:, delete:</string>

Does anybody know how to achieve the same in Xcode 8.0 or above?

I wonder if developers at Apple use Xcode? And if they check StackOverflow? Or are they forbidden to do either by their employment contracts?

EDIT: In Xcode 9.x it seems to be working again.

EDIT: In Xcode 10.0 it is broken again.

EDIT: In Xcode 10.1 it is still broken and also copy/paste is partially broken, meaning it doesn't always work. (I am still on High Sierra)

like image 283
zeeshan Avatar asked Oct 02 '16 11:10

zeeshan


People also ask

How to remove line in Xcode?

Delete Entire Line ( ⌘ + D ) To define custom keybindings, go to Xcode settings (press ⌘ + ,), navigate to the Key Bindings tab, and use the filter field to search for “Delete Line”. Double click into the Key field, then press your preferred key combo. I use ⌘ + D (for Delete Line).


1 Answers

Confirmed, still working in Xcode 12.5.1 on macOS Big Sur 11.5.1

  1. open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist

  2. Add the following lines into the root dictionary

    <key>Sublime Commands</key>
    <dict>
        <key>Cut Current Line</key>
        <string>selectLine:, cut:</string>
        <key>Copy Current Line</key>
        <string>selectLine:, copy:</string>
        <key>Duplicate Current Line</key>
        <string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
    </dict>
  1. restart Xcode
  2. go into the Key Bindings settings and assign any shortcut you want to the new three commands. Just search for their keys.

It's a shame that in the 21st century you still have to manually add such basic shortcuts.

Caveat

The steps have to be repeated after every update of Xcode.

like image 153
duongel Avatar answered Dec 21 '22 22:12

duongel