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     apple    = 1
58     banana  += apple
59     cake   ||= banana
60
61 ### `:EasyAlign :` (for json or yaml)
62
63     url:      jdbc:mysql://localhost/test
64     database: test
65
66 ### `:EasyAlign *|` (markdown tables)
67
68 ```nohighlight
69 | `<Enter>` | right align                   |
70 | `1`       | on 1st occurrence             |
71 | `2`       | on 2nd occurrence (and so on) |
72 ```
73
74 Interactive mode
75 ----------------
76
77 | `{Visual}` `⏎`  | activate for selection          |
78 | `ga` `{motion}` | activate for motion/text object |
79 {:.greycode}
80
81 Then press options (if available), then a delimiter.
82
83 ### Interactive mode options
84
85 | `⏎`              | Set `alignment`                                  |
86 | `<ctrl-l>` `4 ⏎` | Set `left_margin` (to the left of the delimiter) |
87 | `<ctrl-r>` `4 ⏎` | Set `right_margin`                               |
88 | `↓`              | no margin                                        |
89 {:.greycode}
90
91 ### Example
92
93  * `gaip` `<ctrl-l>` `8⏎` `=` - puts 8 spaces before the equal sign
94
95 Also see
96 --------
97
98 * [vim-easy-align](https://github.com/junegunn/vim-easy-align)
99 * [Examples](https://github.com/junegunn/vim-easy-align#examples)
100 * [Alignment options](https://github.com/junegunn/vim-easy-align#alignment-options)