Having been unable to find a linux based SQL beautifier to pipe my mySQL snippets to, I will settle for simply tabularizing my mySQL code. I want to turn this:
CREATE TABLE IF NOT EXISTS GROUP
(
   ID INT NOT NULL AUTO_INCREMENT,
   GROUPNAME VARCHAR(15) UNIQUE,
   ACTIVE BOOLEAN DEFAULT TRUE,
   PRIMARY KEY(ID)
)ENGINE=InnoDB
into this
CREATE TABLE IF NOT EXISTS GROUP
(
   ID         INT NOT NULL AUTO_INCREMENT,
   GROUPNAME  VARCHAR(15) UNIQUE,
   ACTIVE     BOOLEAN DEFAULT TRUE,
   PRIMARY KEY(ID)
)ENGINE=InnoDB
But if I do :Tabularize /\ I get
CREATE TABLE IF NOT EXISTS GROUP
(
        ID          INT           NOT        NULL         AUTO_INCREMENT,
        USERID      INT           NOT        NULL,
        GROUPNAME   VARCHAR(15)   UNIQUE,
        ACTIVE      BOOLEAN       DEFAULT    TRUE,
        PRIMARY     KEY(ID),
        FOREIGN     KEY           (USERID)   REFERENCES   USER(ID)
)ENGINE=InnoDB
How do I only align on the first space after the identifier (or alternatively, where do I find a command line SQL beautifier = ) ?
To avoid Tabularize repeating your pattern to match other fields, you have to anchor it. At the beginning makes more sense in this case, so you can try something like this:
:Tab /^\s*\w*
There is only one field with this pattern in your line. But be careful — it might not happen in your example, but this matches the big majority of lines, thus it might be a good idea to apply Tabularize only in a range (either explicitly or by selecting the lines in visual mode).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With