我如何像这样与 VIM 的表格插件对齐?
这是我的代码:
john,betty,wally,beth
walter,george,thomas,john
herbert,bob,petty,mick`
有谁知道如何使用 VIM 的表格插件将其与此对齐:
john, betty, wally, beth
walter, george, thomas, john
herbert, bob, petty, mick
我知道如何在对齐插件中执行此操作,但无法找出它在表格中的工作原理。
This is my code:
john,betty,wally,beth
walter,george,thomas,john
herbert,bob,petty,mick`
Does anyone know how to align it to this with VIM's Tabular Plugin:
john, betty, wally, beth
walter, george, thomas, john
herbert, bob, petty, mick
I know how to do this in Align Plugin but can't find out how it works in Tabular.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一种选择可能是欺骗并将名称也用作分隔符的一部分:
它会查找带有逗号的小写名称。所有内容均左对齐,并且分隔逗号后至少有一个空格。
Another option may be to cheat and use the names also as a part of the delimiter:
Which looks for any name in lowercase with a comma. Everything is aligned left and at least one space follows on the delimited comma.
这个怎么样:
And how about this:
请参阅
:help \zs
由于之前的模式不起作用,请尝试以下操作:
See
:help \zs
Since the previous pattern doesn't work, try with this:
我不是这方面的专家,我在这里所说的一切都是基于我对 Tabularize 的理解。
制表总是将事物分割成字段,由正则表达式描述。例如:
导致它像下面这样划分每一行:
然后每个字段都用空格填充,以便分隔符字段对齐 - 并且默认情况下所有内容都会接收和额外的空格(我认为除了最后一个字段)。
结果是:
通过添加标志,您可以控制每个字段的对齐和填充。如果您提供的标志少于所需的标志,它们将被重复使用。因此,为了使所有内容都以相同的方式对齐,例如向左填充 0,您可以使用一个将为每个字段重复的标志。所以:
我的结论是,零宽度字段(如
:Tab /,\zs
)没有多大意义,可能会导致它在图案并弄乱,切割它。现在,对我来说
:Tab /[^,]\+,
无法正常工作,生成双倍空格:我认为这是因为没有中间字段。这种模式使一个字段分隔符与另一个字段分隔符并排存在,如下所示:
然后,默认情况下,生成的字段的零(分隔符之间)也会用额外的 1 空格填充。
如何解决?
我会为分隔符留出空间,这不会导致分隔符靠近其他分隔符。如何?只需在逗号后添加一个空格即可。
现在您可以在空格和零填充上对齐所有内容:
我希望这有助于理解表格化!
I'm not a master in this, and everything I'll say here is based on my understanding of Tabularize.
Tabularize always splits things in fields, described by the regex. For example:
Causes it to divide each line like the following:
Then each field is padded with spaces so the delimiter field align — and everything receives and extra-space by default (except for the last field, I think).
Resulting in:
By adding flags, you can control alignment and padding for each field. If you provide less flags than needed, they are reused. So, to make everything align the same way, say left with padding 0 you can use a single flag that will be repeated for every field. So:
The conclusion I have I my mind is that there isn't much sense in having a zero width field (like
:Tab /,\zs
), probably causing it to get the first character after the pattern and messing up, cutting it.Now, for me
:Tab /[^,]\+,
didn't worked properly, generating doubled spaces:I think that's because there is no intermediate field. This pattern, makes a field delimiter reside side by side with another one, like this:
Then the zero with field generated (between delimiters) is also padded with the extra 1 space by default.
How to solve it?
I'd open space for a delimiter, that doesn't cause a delimiter to be near others. How? Simply adding a space after the comma.
Now you can align everything on spaces and zero padding:
I hope that helps understanding Tabularize!
以雷蒙迪的答案为基础,
对我来说更有意义,而且它也只用一个命令:-)。
l0r1
表示左对齐,左侧填充 0 个空格,右侧填充 1 个空格。Building on Raimondi's answer,
makes more sense to me and it's also in just one command :-).
The
l0r1
means left-align with 0 space in the left padding and 1 space in the right padding.我正在做类似的事情。我经常需要将逗号分隔的值转换为列:
使用
:s/,\s*/, /g
准备值以在逗号后添加一个空格:运行
:Tab / ,\zs \+/10
将它们变成:现在我只需要弄清楚如何将它们变成有效的
vmap
。I have something similar I'm doing. I regularly need to turn comma-delimited values into columns:
Using
:s/,\s*/, /g
preps the values to add a single space after the commas:Running
:Tab /,\zs \+/10
turns them into:Now I just need to figure out how to turn them into a
vmap
that works.