mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-12 11:53:49 -05:00
503c8c860fbb3f52d813332a9f2564d63ba9a8b1
vim-easy-align
Yet another Vim alignment plugin without too much ambition.
This plugin clearly has less features than the other pre-existing ones with the similar goals, but it is simpler, easier to use, and just good enough for the most of the cases.
Usage
Vim-easy-align defines :EasyAlign command in the visual mode.
For convenience, it is advised that you define a mapping for triggering it in your .vimrc.
vnoremap <silent> <Enter> :EasyAlign<cr>
With the mapping, you can align selected lines with a few keystrokes.
<Enter>key to start EasyAlign command- Optional field number (default: 1)
1Alignment around 1st delimiter2Alignment around 2nd delimiter- ...
*Alignment around all delimiters (recursive)
- Delimiter (
<space>,=,:,.,|,,)
Alignment rules for the following delimiters have been crafted to meet the most needs.
| Delimiter | Description/Use cases |
|---|---|
<space> |
General alignment around spaces |
= |
Operators containing equals sign (=, ==, !=, +=, &&=, ...) |
: |
Suitable for formatting JSON or YAML |
. |
Multi-line method chaining |
, |
Multi-line method arguments |
| ` | ` |
Example command sequences
| With visual map | Description | Equivalent command |
|---|---|---|
<Enter>= |
Alignment around 1st equals sign (and the likes) | :'<,'>EasyAlign = |
<Enter>2= |
Alignment around 2nd equals sign (and the likes) | :'<,'>EasyAlign 2= |
<Enter>3= |
Alignment around 3rd equals sign (and the likes) | :'<,'>EasyAlign 3= |
<Enter>*= |
Alignment around all equals signs (and the likes) | :'<,'>EasyAlign *= |
<Enter><space> |
Alignment around 1st space | :'<,'>EasyAlign \ |
<Enter>2<space> |
Alignment around 2nd space | :'<,'>EasyAlign 2\ |
<Enter>: |
Alignment around 1st colon | :'<,'>EasyAlign : |
| ... | ... |
Defining custom alignment rules
let g:easy_align_delimiters = {
\ '/': { 'pattern': '//*' },
\ 'x': {
\ 'pattern': '[xX]',
\ 'margin_left': ' <<<',
\ 'margin_right': '>>> ',
\ 'stick_to_left': 0
\ }
\ }
Demo
Author
Languages
Vim Script
99.4%
Shell
0.6%