Reformat Code in Xcode (8.2.1)

Omolara Adejuwon
Larikraun’s Blog
Published in
2 min readMar 21, 2017

For someone who has been spoilt by IDEs like Android Studio and PHPStorm. Their basic key commands make development so much easier.

Currently, to the best of knowledge, many basic commands and key combinations that I use everyday are missing in Xcode. Speak of Duplicate Lines, Reformat code and many more.

Before now, to reformat code in Xcode, I would Select All, Cut and Paste. It works to a reasonable level. But each time, I find myself using shift + alt + L to still perform the same operation.

Then, I decided to kuku create the Key combinations to save me the headache each time. This is how I did it.

  • Open the /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist file.
  • Add the following lines and be sure not to break the tags. You can study this file more to understand what these tags mean.
<key>Customized</key>
<dict>
<key>Reformat Code</key>
<string>selectAll:, copy:, paste:</string>
</dict>

Let me explain:

<key>Reformat Code</key> means that the name of our key binding will be Reformat Code.

The string tags tells it what to do. So, I told it to Select All, Copy and Paste again. Just the same I would do it before.

  • Restart your Xcode.

In Preferences, select Key Bindings. Search for ‘Reformat Code’ — what we wrote as the key node up there. You can put combinations of keys you want. Just be sure it has no conflict with the existing ones.

By now, you are good to go.

If there are smarter ways of reformatting code, I will like to know.

If you have some other short commands you would like to add to your keybindings, it is just the same simple steps as this one.

Versions/A/Resources/IDETextKeyBindingSet.plist file.

--

--

Omolara Adejuwon
Larikraun’s Blog

Code and everything in between. Android Engineer. Editor @proandroiddev