How to install & use Sublime Alignment

On this page…

    What is Sublime Alignment & why do you want it?

    According to its website:

    Dead-simple alignment of multi-line selections and multiple selections for Sublime Text 2.

    What's that mean? Start with this CSS:

    .test {
      font-family: Georgia, serif;
      font-size: 16px;
      font-style: normal;
    }
    

    Run this through Sublime Alignment, & you end up with this:

    .test {
      font-family : Georgia, serif;
      font-size   : 16px;
      font-style  : normal;
    }
    

    Nice & readable & clean.

    Another example, this one in a configuration file. Instead of : as the field delimiter, this file uses the good ol' fashioned =:

    short_open_tag = Off
    asp_tags = Off
    precision = 14
    y2k_compliance = On
    

    After Sublime Alignment, we have this:

    short_open_tag = Off
    asp_tags       = Off
    precision      = 14
    y2k_compliance = On
    

    Of course, one crazy long directive can put everything off:

    short_open_tag                = Off
    asp_tags                      = Off
    precision                     = 14
    y2k_compliance                = On
    zlib.output_compression_level = -1
    

    Fortunately, Sublime Alignment let's you choose which lines to line up & which to skip, giving us this far more sane result:

    short_open_tag = Off
    asp_tags       = Off
    precision      = 14
    y2k_compliance = On
    zlib.output_compression_level = -1
    

    Cool? Let's dig in!

    Install the Sublime Alignment package in Sublime Text

    Follow these steps:

    1. Command-Shift-P to open Command Palette.
    2. Type Install until you see Package Control: Install Package.
    3. When the list of packages appears, type Alignment until you find it.
    4. Press Enter to install Sublime Alignment.

    Configuring Sublime Alignment

    Follow these steps:

    1. Open the preferences file for Sublime Alignment:

      • Windows: Preferences > Package Settings > Alignment > Settings - User
      • Linux: Preferences > Package Settings > Alignment > Settings - User
      • Mac OS X: Sublime Text 2 > Preferences > Package Settings > Alignment > Settings - User
    2. The file should be empty. Put the following in it:

      {
          // The mid-line characters to align in a multi-line selection, changing
          // this to an empty array will disable mid-line alignment
          "alignment_chars": [
              "=", ":"
          ]
      }
      
    3. Save & close the preference file. By default, Sublime Alignment works with =. Now it works with = and with :.

    Using Sublime Alignment

    Simple:

    1. Select the lines you wish to align.
    2. Press Ctrl+Alt+A (Windows & Linux) or Command+Ctrl+A (Mac OS X)
    WebSanity Top Secret