Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: indent code in a single shortcut

Tags:

I'm using Xcode 7.3 with Swift 2.2.

The point is that I'm largely tired of "running":

Cmd + A
Ctrl + I

in order to indent the whole code.

So, I think I'm quite close to find the solution, creating my own shortcut on IDETextKeyBindingSet.plist.

<key>My Custom Shortcuts</key>
<dict> 
    <key>Indent Code In One Hit</key>
    <string>selectAll:, ....., moveLeft:</string>
</dict>

I have done a lot of test substituting '.....' with various commands (combining this), but I can't find a solution yet.

Any help is appreciated!

like image 436
Luca Davanzo Avatar asked May 27 '16 11:05

Luca Davanzo


1 Answers

Finally I found a solution by my self, without installing any unverified plugins.
I think that could be other solutions with higher performance.

  1. Close Xcode
  2. Edit IDETextKeyBindingSet

    sudo nano /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
    

    Adding this:

    <key>My Custom Shortcuts</key>
    <dict> 
         <key>Custom - Indent Code In One Hit</key>
         <string>selectAll:, cut:, paste:</string>
    </dict>
    
  3. Open Xcode, Cmd + ; to open preferences
  4. Key Bindings and filter by "Custom"
  5. Assign you favourite key binding.

enter image description here

  1. Exit from preferences, stir your code, try your new shortcut and feel the power!
like image 190
Luca Davanzo Avatar answered Sep 28 '22 01:09

Luca Davanzo