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:
- Command-Shift-P to open Command Palette.
- Type
Install
until you seePackage Control: Install Package
. - When the list of packages appears, type
Alignment
until you find it. - Press Enter to install Sublime Alignment.
Configuring Sublime Alignment
Follow these steps:
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
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": [ "=", ":" ] }
Save & close the preference file. By default, Sublime Alignment works with
=
. Now it works with=
and with:
.
Using Sublime Alignment
Simple:
- Select the lines you wish to align.
- Press Ctrl+Alt+A (Windows & Linux) or Command+Ctrl+A (Mac OS X)