本文介绍了在 vim 中重新格式化以获得漂亮的列布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 csv 文件中有这个数据集

I have this dataset in a csv file

1.33570301776,3.61194e-06,7.24503e-06,-9.91572e-06,1.25098e-05,0.0102828,0.010352,0.0102677,0.0103789,0.00161604,0.00167978,0.00159998,0.00182596,0.0019804,0.0133687,0.010329, 0.00163437, 0.00191202, 0.01344251.34538754675,3.3689e-06,9.86066e-06,-9.12075e-06,1.18058e-05,0.00334344,0.00342207,0.00332897,0.00345504,0.00165532,0.00170412,0.00164234,0.00441903,0.00459294,0.00449357,0.00339737,0.00166596,0.00451926,0.004551531.34808186291,-1.99011e-06,6.53026e-06,-1.18909e-05,9.52337e-06,0.00158065,0.00166529,0.0015657,0.0017022,0.000740644,0.00078635,0.000730052,0.00219736,0.00238191,0.00212762,0.00163783,0.000750669,0.00230171,0.00217917

如您所见,数字格式不同且未对齐.vim中有没有办法快速正确对齐列,结果是这样的

As you can see, the numbers are formatted differently and misaligned. Is there a way in vim to quickly align the columns properly, so that the result is this

1.33570301776,3.61194e-06,7.24503e-06,-9.91572e-06,1.25098e-05,0.0102828,0.010352,0.0102677,0.0103789,0.00161604,0.00167978,0.00159998,0.00182596,0.0019804,0.0133687,0.010329, 0.00163437, 0.00191202, 0.01344251.34538754675,3.3689e-06,9.86066e-06,-9.12075e-06,1.18058e-05,0.00334344,0.00342207,0.00332897,0.00345504,0.00165532,0.00170412,0.00164234,0.00441903,0.00459294,0.00449357,0.00339737,0.00166596,0.00451926,0.004551531.34808186291,-1.99011e-06,6.53026e-06,-1.18909e-05,9.52337e-06,0.00158065,0.00166529,0.0015657,0.0017022,0.000740644,0.00078635,0.000730052,0.00219736,0.00238191,0.00212762,0.00163783,0.000750669,0.00230171,0.00217917

使用 ctrl-v 复制和粘贴部分会很棒.有什么提示吗?

That would be great to copy and paste sections with ctrl-v. Any hints?

推荐答案

如果您使用的是某种 UNIX(Linux 等),您可以通过 column(1) 命令进行欺骗和过滤.

If you're on some kind of UNIX (Linux, etc), you can cheat and filter it through the column(1) command.

:%!column -t

以上将解析字符串文字中的分隔符,这是错误的,因此您可能需要预处理步骤并为此文件指定分隔符,例如:

The above will parse on delimiters inside string literals which is wrong, so you will likely need pre-processing steps and specifying the delimiter for this file for example:

%!sed 's/","/\&/' | column -t -s '&'

这篇关于在 vim 中重新格式化以获得漂亮的列布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:45