OSDN Git Service

Regular updates
[twpd/master.git] / vim-easyalign.md
1 ---
2 title: Vim Easyalign
3 html_class: key-codes
4 hljs_languages: [vim]
5 category: Vim
6 ---
7
8 ## Command mode
9
10 ### Align by delimiters
11
12 ```vim
13 :EasyAlign :       " preset characters (\=:.,&#|)
14 :EasyAlign |
15 :EasyAlign \       " \ means space
16 ```
17
18 ### Align by regexp
19
20 ```vim
21 :EasyAlign /[:;]+/
22 ```
23
24 ### Specify which
25
26 ```vim
27 :EasyAlign |       " align by 1st `|`
28 :EasyAlign 3 |     " align by 3rd `|`
29 :EasyAlign * |     " align by all `|`s
30 ```
31
32 ### Add options
33
34 ```vim
35 :EasyAlign * | l4r1
36
37   l4     " lN - left_margin
38   r1     " rN - right_margin
39          "    spaces to the left/right of `|`
40   ar     " a[lrc] - align
41          "    align left/right/center
42   dr     " d[lrc] - delimiter_align
43          "    alignment of the delimiter itself
44 ```
45
46 ### Spaces are optional
47
48 ```vim
49 :EasyAlign * /[;:]+/ l3
50 :EasyAlign*/[;:]+/l3
51 ```
52
53 ## Examples
54
55 ### `:EasyAlign = dr` (delimiter_align right)
56
57 ```
58 apple    = 1
59 banana  += apple
60 cake   ||= banana
61 ```
62
63 ### `:EasyAlign :` (for json or yaml)
64
65 ```
66 url:      jdbc:mysql://localhost/test
67 database: test
68 ```
69
70 ### `:EasyAlign *|` (markdown tables)
71
72 ```nohighlight
73 | `<Enter>` | right align                   |
74 | `1`       | on 1st occurrence             |
75 | `2`       | on 2nd occurrence (and so on) |
76 ```
77
78 ## Interactive mode
79
80 | `{Visual}` `⏎` | activate for selection |
81 | `ga` `{motion}` | activate for motion/text object |
82 {:.greycode}
83
84 Then press options (if available), then a delimiter.
85
86 ### Interactive mode options
87
88 | `⏎` | Set `alignment` |
89 | `<ctrl-l>` `4 ⏎` | Set `left_margin` (to the left of the delimiter) |
90 | `<ctrl-r>` `4 ⏎` | Set `right_margin` |
91 | `↓` | no margin |
92 {:.greycode}
93
94 ### Example
95
96 - `gaip` `<ctrl-l>` `8⏎` `=` - puts 8 spaces before the equal sign
97
98 ## Also see
99
100 - [vim-easy-align](https://github.com/junegunn/vim-easy-align)
101 - [Examples](https://github.com/junegunn/vim-easy-align#examples)
102 - [Alignment options](https://github.com/junegunn/vim-easy-align#alignment-options)