How to align texts in Sublime Text 3?

cyb3rZ picture cyb3rZ · Apr 10, 2015 · Viewed 35k times · Source

I use Sublime Text 3 Plug-in called AlignTab to align my code like this:

 Version : 1.4.1
 Author  : Ken Wheeler
 Website : http://kenwheeler.github.io
 Docs    : http://kenwheeler.github.io/slick
 Repo    : http://github.com/kenwheeler/slick
 Issues  : http://github.com/kenwheeler/slick/issues

Now, I want to my texts to stay next to the colon like this:

 Version: 1.4.1
  Author: Ken Wheeler
 Website: http://kenwheeler.github.io
    Docs: http://kenwheeler.github.io/slick
    Repo: http://github.com/kenwheeler/slick
  Issues: http://github.com/kenwheeler/slick/issues

How do I accomplish that ?

Answer

Rob Wise picture Rob Wise · Apr 10, 2015

You can do this with AlignTab, no need for a different plugin. You just need to use the more advanced regex functionality as described on the GitHub page.

Bring up the Command Palette (Ctrl+Shift+P on Windows or cmd+shift+P on Mac), type in "AlignTab", press enter, and type this in and hit enter:

:/r0clf1

Props to @Hank for including 0 spaces option, didn't even realize he didn't want the space.

Explanation:

  • the : finds the colon
  • the / says okay now here come some arguments about what I want you to do with the colon
  • the r means right-justify the first column
  • the 0 means 0 spaces after the right column
  • the c means center the middle column (which is just the colon, so it doesn't do anything)
  • the l means left-justify the right column
  • the f1 means only do this for the first match on the line