We are going to see how to use the Alignment package into the Sublime Text 3.
Table of Content
Introduction Introduction
While development it is nice to see the code with well-aligned or with good indentation.
Most of the users may use the PHPStrom, VSCode, or something else. They have some extensions which do the same thing.
But, I’m a fan of Sublime Text Editor. So, I’m sharing here how to use the Alignment Package of Sublime Text Editor.
So, Lets check out the below an example of aligning and misaligned code.
Advertisement
Example of Misaligned Code Example of Misaligned Code
$data = array( 'one' => 'One', 'two' => 'two', 'three' => 'Three', 'four' => 'Four', 'five' => 'Five', );
Example of Well Aligned Code Example of Well Aligned Code
$data = array( 'one' => 'One', 'two' => 'two', 'three' => 'Three', 'four' => 'Four', 'five' => 'Five', );
I’m using the Sublime Text 3 (Unregistered). IMO it is best for the development. It has a lot of awesome features.
In this article, I’m explaining the Alignment package (It is in TOP 25 today).
Alignment Git Repo – https://github.com/wbond/sublime_alignment/
Advertisement
How to Install Alignment Package? How to Install Alignment Package?
Just follow below simple steps:
- Press
Command+Shift+P
to open Command Palette. - Type
Install Package
until you seePackage Control: Install Package
. - When the list of packages appears, type Alignment until you find it.
- Press
Enter
to install Sublime Alignment.
Check out below GIF for reference to know How to Install the alignment package.
Now, 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 mid-line characters to align in a multi-line selection, changing // this to an empty array will disable mid-line alignment "alignment_chars": [ "=", ":" ] }
Here, We have added the =
and :
So, When you select the code which include the =
or :
then it aligns with these characters.
Advertisement
Using Alignment Package Using Alignment Package
Select the lines you wish to align. Press Ctrl+Alt+A
(Windows & Linux) or Command+Ctrl+A
(Mac OS X)
Check out below example to align the code.
BEFORE
$data = array( 'one' => 'One', 'two' => 'two', 'three' => 'Three', 'four' => 'Four', 'five' => 'Five', );
AFTER
$data = array( 'one' => 'One', 'two' => 'two', 'three' => 'Three', 'four' => 'Four', 'five' => 'Five', );
Check out the below GIF example for reference.
The sublime text provides a lot of useful keyboard shortcuts. Check out the complete list of Sublime Text 3 Keyboard Shortcuts Cheat Sheet.