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
  • 7 years ago
  • 3 hours ago
  • 12 years ago

Installs

  • Total 169K
  • Win 100K
  • Mac 43K
  • Linux 27K
Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16 Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6
Windows 1 6 3 7 8 4 0 2 10 5 7 5 2 6 6 3 5 8 8 5 2 1 7 4 0 0 0 0 1 1 12 2 1 2 2 4 5 0 0 3 4 7 4 2 6 4
Mac 2 2 4 2 1 3 3 4 3 2 3 1 1 1 2 3 1 3 5 6 2 2 0 2 0 0 0 0 0 4 3 1 1 6 1 0 3 0 0 4 2 5 2 1 2 5
Linux 0 2 3 0 0 4 2 3 0 1 1 1 0 2 0 1 1 2 1 1 0 0 2 0 0 0 0 1 2 2 1 2 0 1 1 1 1 0 0 0 0 1 1 2 4 3

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.