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