Xcode 9.x Line Duplication and Deletion

霸气de小男生 提交于 2020-01-11 15:45:53

问题


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)


回答1:


Confirmed, still working in Xcode 10.3 on macOS Mojave 10.14.6

  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.




回答2:


The above answer seems to be broken in Xcode 9.

Here is another solution that I have verified does work in Xcode 9 GM:

<key>Custom Commands</key>
<dict>
    <key>Duplicate Current Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>



回答3:


The previous answer left erroneous whitespace when I tried it. This works for me in Xcode 9:

selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:


来源:https://stackoverflow.com/questions/39816443/xcode-9-x-line-duplication-and-deletion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!