# Sublime Text – Adjust brace style

sublime-text-2

Our codebase has a "cuddled" curly brace style. That is, the { appears on the same line as the function (or if or while) statement that it goes with:

if (condition) {
doThis();
}
else {
doThat();
}


We have a coder who keeps committing stuff with the curly brace on its own blank next line, which drives me bonkers:

if (condition)
{
doThis();
}
else
{
doThat();
}


I don't want to start a debate on the relative merits of the two formats, but I do want to bring this programmer's code in line with our established style. Is there a Sublime Text plugin or macro that will convert between these styles? Doing it manually seems like such a waste of time.

As Daniel Beck suggested in his comments, this can be done with a regex find-and-replace. The regex that ended up working for me in Sublime Text was the following:

Find What: \n(\s)*\{ (that is, look for any newline character, followed by zero or more whitespace characters, followed by a left curly brace character)

Replace With: { (a space and a left curly brace)

I'm doing the replacements one by one, since sometimes my rogue programmer sometimes also stuck code on the "curly brace" line, like this...

if (condition)
{doThis();}


... and I have to double-check them before I do the replacement.

I still think that a plugin might be able to handle this kind of situation very gracefully, but this works for now.