I find this shortcut extremely useful in Xcode: duplicate one or several lines without losing what you have on the clipboard.
- To add custom key bindings in Xcode, you have to edit this file (su privileges required):
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist
I add the following new key at the bottom:
<key>User</key>
<dict>
<key>Duplicate Lines Down</key>
<string>selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yankAndSelect:</string>
<key>Duplicate Lines Up</key>
<string>selectParagraph:, delete:, yankAndSelect:, moveToBeginningOfText:, yankAndSelect:</string>
<key>Delete Line</key>
<string>selectLine:, deleteBackward:</string>
</dict>
- Open Xcode and go to
Xcode Preferences
->Key Bindings
- filter for
Duplicate Lines Down
, add a shortcut for it. I use the chord shift + alt + ↓, similar to the default from VSCode. - filter for
Duplicate Lines Up
, add a shortcut for it. I use the chord shift + alt + ↑, similar to the default from VSCode. - filter for
Delete line
, add a shortcut for it. I use the chord shift + alt + backspace
NOTE: you will have to do this every time Xcode is updated -- that's why you might as well write a shell script to automate most of it.
NOTE: you will have to do this every time Xcode is updated -- that's why you might as well write a shell script to automate it.
I'm not doing a full automatization yet... I like doing the last step manually.
Save the following in bash shell script (I called it prepareXcodeKeybindingsForEditing.sh
) and then call it from terminal with sudo sh prepareXcodeKeybindingsForEditing.sh
everytime you update Xcode.
It opens an editor (atom in my case, edit to your liking...) and prints the XML you need to copy-paste for you in terminal.
path='/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/'
bindingsFile=$path'IDETextKeyBindingSet.plist'
sudo chmod 755 $path
if [ ! -f $bindingsFile ]; then
echo "Bindings file doen't exist"
fi
sudo chmod 664 $bindingsFile
sudo open -a atom $bindingsFile
echo "Now paste the following:"
echo "<key>User</key>
<dict>
<key>Duplicate Lines Down</key>
<string>selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yankAndSelect:</string>
<key>Duplicate Lines Up</key>
<string>selectParagraph:, delete:, yankAndSelect:, moveToBeginningOfText:, yankAndSelect:</string>
<key>Delete Line</key>
<string>selectLine:, deleteBackward:</string>
</dict>
```"
echo ""