
Sublime text auto format code#
Just CMD+K+F and boom, you’re in clean code town. Just select your SQL and hit CMD+K+F on your keyboard ( CTRL+K+F on windows/linux) and that disgusting pile of SQL turns into some pretty decent looking code! If your file contains nothing but SQL (like a fresh file where you just pasted in a query for instance) you don’t even need to select anything. It almost entirely removes the need for me to waste time reformatting SQL code. It’s a Sublime Text plugin that automatically formats any selected SQL in your code. That’s why I was so psyched to find SQL Beautifier by Ziang Song.

Usually I wind up copying the whole statement out of wherever it came from, pasting it into a new file in Sublime and formatting it by hand – like an animal – just so I can read the darn thing. Ever try to read an SQL statement with 3 or more table joins, multiple sub-statements and waaay too much conditional logic where all of the whitespace and line breaks have been stripped away by a server-side language? It’s not fun. Usually it looks like an unholy, hot mess. Unless the query is coming directly out of some Elite Coding Hero’s meticulously clean and well-formatted source code (or at least my own 😁), the query almost never looks “beautiful”.

I don’t work with SQL a whole lot these days but every once in a while I find myself needing to debug a query gone wrong or at least look at somebody else’s query just so I can better understand the code that makes use of it.
