Vim Easyalign
A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

Align by delimiters

Align by delimiters

:EasyAlign :       " preset characters (\=:.,&#|)
:EasyAlign |
:EasyAlign \       " \ means space

Align by regexp

Align by regexp

:EasyAlign /[:;]+/

Specify which

Specify which

:EasyAlign |       " align by 1st `|`
:EasyAlign 3 |     " align by 3rd `|`
:EasyAlign * |     " align by all `|`s

Add options

Add options

:EasyAlign * | l4r1

  l4     " lN - left_margin
  r1     " rN - right_margin
         "    spaces to the left/right of `|`
  ar     " a[lrc] - align
         "    align left/right/center
  dr     " d[lrc] - delimiter_align
         "    alignment of the delimiter itself

Spaces are optional

Spaces are optional

:EasyAlign * /[;:]+/ l3
:EasyAlign*/[;:]+/l3

:EasyAlign : (for json or yaml)

:EasyAlign : (for json or yaml)

url:      jdbc:mysql://localhost/test
database: test

:EasyAlign *| (markdown tables)

:EasyAlign *| (markdown tables)

| `<Enter>` | right align                   |
| `1`       | on 1st occurrence             |
| `2`       | on 2nd occurrence (and so on) |
{Visual} activate for selection
ga {motion} activate for motion/text object

Then press options (if available), then a delimiter.

Interactive mode options

Interactive mode options

Set alignment
<ctrl-l> 4 ⏎ Set left_margin (to the left of the delimiter)
<ctrl-r> 4 ⏎ Set right_margin
no margin

Example

Example

  • gaip <ctrl-l> 8⏎ = - puts 8 spaces before the equal sign