OSDN Git Service

Regular updates
[twpd/master.git] / tabular.md
1 ---
2 title: Tabular
3 category: Vim
4 layout: 2017/sheet
5 updated: 2017-10-11
6 weight: -1
7 intro: |
8   [Tabular](https://github.com/godlygeek/tabular) is a Vim script for text alignment.
9 ---
10
11 ## Common usage
12 {: .-three-column}
13
14 ### Tables
15
16 ```
17 :Tab /|
18 ```
19 {: .-setup}
20
21 ```
22 | Fruit  | Color  |
23 | -----  | -----  |
24 | Apple  | Red    |
25 | Banana | Yellow |
26 | Kiwi   | Green  |
27 ```
28
29 ### Variables
30
31 ```
32 :Tab /=
33 ```
34 {: .-setup}
35
36 ```
37 title = "Hello"
38 src   = "image.jpg"
39 width = 640
40 ```
41
42 ### Colons
43
44 ```
45 :Tab /:\zs/l0l1
46 ```
47 {: .-setup}
48
49 ```
50 title:       "Hello world"
51 description: "This is a description"
52 src:         "image.jpg"
53 height:      320
54 width:       640
55 ```
56
57 ## Tab command
58 {: .-three-column}
59
60 ### Basic example
61
62 ```
63 :Tab /:
64 ```
65 {: .-setup}
66
67 ```bash
68 title : My picture
69 src   : img.jpg
70 ```
71
72 ### Right align
73
74 ```
75 :Tab /:/r0
76 ```
77 {: .-setup}
78
79 ```bash
80 title:My picture
81   src:   img.jpg
82 ```
83
84 ### The \zs atom
85
86 ```
87 :Tab /:\zs
88 ```
89 {: .-setup}
90
91 ```
92 title:  My picture
93 src:    img.jpg
94 ```
95
96 The `\zs` atom will exclude the `:` from the search match.
97
98 ### Specifier
99
100 ```
101 :Tab /:/r1c1l0
102 ```
103 {: .-setup}
104
105 ```bash
106 title : My picture
107   src : img.jpg
108 ```
109
110 #### Explanation
111
112 - `r1` -- Right align with 1 space
113 - `c1` -- Center align the comma with 1 space
114 - `l0` -- Left align with 0 spaces
115
116 ### Regexp
117
118 ```
119 :Tab /^[^,]*\zs,/r0
120 ```
121 {: .-setup}
122
123 ```bash
124 abc,hello
125   c,hi there
126   a,yo
127 ```
128
129 ### Specifiers
130
131 | Specifier | Description |
132 | --- | --- |
133 | `r1c1l0` |  multiple specifiers, one per column<br>(the separator counts as a column) |
134 | --- | --- |
135 | `lN` | Left-align (with N spaces padding) |
136 | `rN` | Right-align (with N spaces padding) |
137 | `cN` | Center-align (with N spaces padding) |
138
139 ## Also see
140
141 - [godlygeek/tabular](https://github.com/godlygeek/tabular) _(github.com)_
142 - [Aligning text with Tabular.vim](http://vimcasts.org/episodes/aligning-text-with-tabular-vim/) _(vimcasts.org)_