I am trying to add a group of custom key-bindings to Xcode 6. I've looked up in the past posts and discovered to do this you need to edit the Default.idekeybindings file located in your Xcode -> UserData -> KeyBindings -> Default.ideakeybindings
I have edited this according to how it was done in the previous versions, but when I go into the preferences -> keybindings within Xcode I am not able to find the custom action I defined. I would ideally like to make a one key "copy line", "cut line", "duplicate line" and some other useful keybindings I've grown to like while using Sublime and Atom. I've included my .ideakeybindings edited file contents below for reference to what I'm trying to do.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>My Custom Actions</key>
<dict>
<key>Delete Current Line/Selection</key>
<string>deleteToEndOfLine:, deleteToBeginningOfParagraph:</string>
<key>Duplicate Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:</string>
</dict>
</dict>
</plist>
You can add shortcuts using Xcode > Preferences > Key Bindings. Search for the command-name using the field at the top-right, then double click in the key field and type the key you want to use.
For Xcode only , you can't change Command + Click to Control + Click. If you want to change your MAC Shortcut Key then you can Change it from Goto System Preference -> Keyboard -> Modify Keys then update your shortcut key according to your preference.
To reassign a keyConnect the keyboard that you want to configure. Select the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.
Efficiency. Using keyboard shortcuts instead of the mouse enables you to work faster, more efficiently and with increased precision, thereby saving you time and improving your productivity. As well, for those with mobility or vision disabilities, keyboard shortcuts are indispensable.
I did this on Xcode 7:
I added this section:
<key>My Custom Commands</key>
<dict>
<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>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
<key>Delete Current Line</key>
<string>selectLine:, delete:</string>
<key>Cut Current Line</key>
<string>selectLine:, cut:</string>
<key>Copy Current Line</key>
<string>setMark:, selectLine:, copy:, moveToEndOfLine:, swapWithMark:</string>
<key>Paste At Beginning Of Line</key>
<string>moveToBeginningOfLine:, paste:</string>
</dict>
As this gets overwritten every time a new version of Xcode is installed, a user settings location for the custom commands would really be appreciated if someone knows where to add them in the user dir.
I've been using the following for years because I came from Eclipse camp and do like "Duplicate Current Line Up" and "Duplicate Current Line Down" very much. Note "Xcode.app" could be "Xcode62.app" or "Xcode63.app" depending on how you renamed it.
sudo vim /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
<key>Customized</key>
<dict>
<key>Duplicate Current Line Up</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:, moveUp:</string>
<key>Duplicate Current Line Down</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
<key>Delete Current Line</key>
<string>deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToBeginningOfLine:</string>
</dict>
Restart Xcode | Preferences | Key Bindings | All
search "Duplicate"
search "Current"
then input your favorite shortcut key bindings.
I learnt this trick from somewhere in SO - thx a lot to the original poster. It works on Xcode 6.3 latest beta, Xcode 6.2, 6.1 and previous Xcode versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With