Use the vim Tabularize plugin to match only the first delimiter detection

Could not find a linux-based SQL beautifier for transferring my mySQL fragments, I agree to simply charge my mySQL code. I want to do 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

in that

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 can I align only the first space after the identifier (or, alternatively, where to find the SQL command line beautifier =)?

+3
source share
1 answer

To avoid repeating the Tabularize pattern to fit the other fields, you have to pin it. In the beginning it makes sense in this case, so you can try something like this:

:Tab /^\s*\w*

. - , , , Tabularize ( ).

+4

All Articles