Luca Davanzo
Luca Davanzo

Reputation: 21528

Xcode: indent code in a single shortcut

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!

Upvotes: 5

Views: 2067

Answers (3)

Luca Davanzo
Luca Davanzo

Reputation: 21528

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!

Upvotes: 3

Quang Dam
Quang Dam

Reputation: 325

I think you should try this. It helps you re-indent code each time you Cmd + S

Upvotes: 1

Ian Pilipski
Ian Pilipski

Reputation: 535

"Command + ]" will indent all the highlighted code.

Upvotes: 0

Related Questions