chouzz / vscode-better-align

Better vertical alignment with/without selection in any language.
https://marketplace.visualstudio.com/items?itemName=Chouzz.vscode-better-align&ssr=false#overview
Apache License 2.0
40 stars 4 forks source link
visual-studio-code vscode vscode-extension

Better Align for Visual Studio Code

The MIT License GitHub Visual Studio Marketplace GithubActions

Better vertical alignment with/without selection in any language for any characters or words.

Features

Usage

Place your cursor at where you want your code to be aligned, and use shortcut alt + A or invoke the Align command via Command Palette.

Screenshots

auto-align-characters.gif

Extension Configuration

betterAlign.surroundSpace

Default value:

betterAlign.surroundSpace : {
  "colon"      : [0, 1], // The first number specify how much space to add to the left, can be negative.
                         // The second number is how much space to the right, can be negative.
  "assignment" : [1, 1], // The same as above.
  "arrow"      : [1, 1], // The same as above.
  "comment"    : 2       // Special how much space to add between the trailing comment and the code.
                         // If this value is negative, it means don't align the trailing comment.
}
// Orignal code
var abc = {
  hello:      1
  ,my :2//comment
  ,friend:   3      // comment
}

// "colon": [0, 1]
// "comment": 2
var abc = {
    hello : 1
  , my    : 2  // comment
  , friend: 3  // comment
}

// "colon": [1, 2]
// "comment": 4
var abc = {
    hello  :  1
  , my     :  2    // comment
  , friend :  3    // comment
}

// "colon": [-1, 3]
// "comment": 2
var abc = {
    hello:    1
  , my:       2  // comment
  , friend:   3  // comment
}

// "colon": [-1, -1]
// "comment": 2
var abc = {
     hello:1
  ,     my:2  //comment
  , friend:3  // comment
}

// Orignal code
$data = array(
    'text' => 'something',
    'here is another' => 'sample'
);

// "arrow": [1, 3]
$data = array(
    'text'            =>   'something',
    'here is another' =>   'sample'
);

Issues/Contribution

If you've found a bug, please file at https://github.com/chouzz/vscode-better-align/issues.

If you'd like to help out, fork the repo and submit pull requests.

License

This work is licensed under Apache License 2.0

Credit

The codebase is based on this repository. Thanks @WarWithinMe.