问题
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
open
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
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>
- restart Xcode
- go into the
Key Bindings
settings and assign any shortcut you want to the new three commands. Just search for theirkey
s.
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