- Open with text editor
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
If you are using multiple versions of Xcode you have to open this file for each of them. Remember to change /Applications/Xcode.app
to path where your Xcode is located.
- Add thise lines:
<key>Duplication</key>
<dict>
<key>Duplicate Current Line Up</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:, moveUp:, moveToEndOfLine:</string>
<key>Duplicate Current Line Down</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>
-
Open Xcode and
Xcode preferences
⌘ Command + , →Key Bindings
and search forduplication
-
Click on
Duplicate Current Line Up
, add a shortcut for it, eg. (if you want same shortcut as visual studio code) ⌥ Option + ⇧ Shift + ↑ (remove any other bindings for this key) -
Click on
Duplicate Current Line Down
, add a shortcut for it, eg. (if you want same shortcut as visual studio code) ⌥ Option + ⇧ Shift + ↓ (remove any other bindings for this key)
That's great, thank you!
Sadly, this doesn't cover the fact of duplicating whole blocks of code (@mesqueeb)
I started studying the code for such commands (https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding) and then asked AI, and I found out a bit how these works.
Apparently,
deleteToEndOfLine:
actually cuts the content into a "kill buffer", whichyank:
is able to read and paste from.Btw, with some genuine help of Copilot, we came up with this solution, that includes both single lines and blocks.
It seems to be working pretty good like this.