ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Align​Tab

by randy3k ALL

An alignment plugin for Sublime Text using regular expression

Details

  • 2.1.11
    1.2.5
  • github.​com
  • github.​com
  • 6 years ago
  • 16 minutes ago
  • 11 years ago

Installs

  • Total 167K
  • Win 99K
  • Mac 42K
  • Linux 27K
Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5 Mar 4 Mar 3 Mar 2 Mar 1 Feb 29 Feb 28 Feb 27 Feb 26 Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9 Feb 8 Feb 7 Feb 6 Feb 5 Feb 4 Feb 3
Windows 6 7 2 3 4 3 3 5 5 8 2 3 5 6 9 3 3 4 3 10 5 6 5 2 6 11 15 15 6 8 2 2 6 3 7 6 5 6 10 4 7 6 1 9 6 2
Mac 1 1 2 2 5 6 3 5 7 1 1 0 5 5 2 5 3 2 4 3 1 1 4 2 5 2 3 5 8 3 0 2 4 8 2 3 2 3 1 2 3 0 7 5 3 0
Linux 1 0 1 2 2 3 1 3 1 1 0 1 4 1 0 1 0 2 0 1 4 3 1 2 1 6 5 3 2 0 1 1 1 5 2 1 1 1 0 1 4 2 2 1 4 2

Readme

Source
raw.​githubusercontent.​com

AlignTab

test codecov

The most flexible alignment plugin for Sublime Text 3. This plugin is inspired by the excellent VIM plugin, tabular.

ST2 support is deprecated but however, it is still possible to install AlignTab on ST2 via Package Control.

Features

  • Align using regular expression
  • Custom spacing, padding and justification.
  • Smart detection for alignment if no lines are selected
  • Multiple cursors support
  • Table mode and Live preview mode

Getting started

  • If you only want simple and quick alignment, the predefined alignment will help.

More complicated usage

  • Open AlignTab in Command Palette C+Shift+p and enter the input in the form of <regex>/<option>.
  • To learn more about regular expression, visit here and here.
  • The option controls column justification, padding and maximum number of splits. A general syntax of options is ([rlc][0-9]*)*(f[0-9]*)?.
  • The numbers after r, c or l determine how many spaces will be added after columns and the number after f controls how many matches will be made based <regex>.
  • For example, c2r3f1 means
    • first column is centered followed by 2 spaces
    • second column is right-flushed followed by 3 spaces
    • only the first match is used
  • If the number after [rlc] is omitted, 1 space will be added after each column.
  • If the number after f is omitted, only the first match will be used.
  • The entire option could be omitted (i.e., input only the regular expression). In that case, default option, l1f0 will be used. It means:
    • All columns are left-justified.
    • A space is added after each column.
    • All matched delimiters are aligned.

More about regex and options

  • Use non-capturing parenthese (?:regex) instread of capturing parenthese.
  • Delimiter is also treated as a column.
    • For example, =/rcl means the the column before = will be right-justifed and the column after = will be left-justified. And = will be centered (however, it doesn't matter as = is of length 1).
  • The option for alignment cycles through the columns.
    • For example, regex/rl means all odd columns will be right-justified and all even columns will be left-justified.
  • The symbol * repeats the preceeding justification flags.
    • For example r*3 equals rrr, and (cr3)*2 equals cr3cr3.
  • (Experimental) Besides r, c and l, there is a new u flag which stands for “unjustified”.

Live Preview Mode

Table Mode

Hit ESC or use the command AlignTab: Exit Table Mode to exit table mode.

Installation

Package Control

Examples

Some simple examples. You can also contribute your examples there.

Keybinds

If you are interested in getting a keybind for live preview mode, add the following in your user keybinds file.

{
   "keys": ["super+shift+a"], "command": "align_tab",
   "args" : {"live_preview" : true}
 }

For frequent patterns, you can consider the following in your user keybinds file. Change the keybind and the user_input for your purpose.

//align =
  {
    "keys": ["super+shift+a"], "command": "align_tab",
    "args" : {"user_input" : "=/f"}
  }

or syntex specific keybind.

// latex align keybind, to align & and \\, but not \&
    {
        "keys": ["super+shift+a"], "command": "align_tab",
        "args" : {"user_input" : "(?<!\\\\)&|\\\\\\\\"},
        "context":[
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex" }
        ]
    }

Named patterns

To make it easier to remember complex patterns, you can save them in a dictionary in the settings file. To edit the patterns, launch Preferences: AlignTab Settings. Use the name as key and the regex as value. For examples,

"named_patterns": {
    "eq" : "=/f",
    // right hand side could also be an array of inputs
    "ifthen" : ["=/f", "\\?/f", ":/f"]
}

You then just use the name instead of the pattern in the input field.

Custom Context Menu

To define new item in the context menu, launch Preferences: AlignTab Context Menu and add, for example

[
   {"caption" : "-"},
    {
      "id": "aligntab",
      "caption": "AlignTab",
      "children": [
          {
          "caption" : "{",
          "command" : "align_tab",
          "args"    : {"user_input" : "\\{"}
          }
      ]
  }
]

CJK Support

AlignTab supoorts CJK characters, but you have to choose a correct font face and font size. To my knowledge, MinCho works on all Chinese, Japanese and Korean.

License

AlignTab is licensed under the MIT License.