这是我的另一个vim
问题(它们似乎成为我的商标。)。我有一个很长的文件,基本上由以下形式的行组成:
;07 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T1_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
;08 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T2_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
09 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T3_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
;10 :ANZ textv S9_1 9_1_K4_2 S9_3 S9_4 9_1_K4_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T1_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V4n E3
;11 :ANZ textv S9_1 9_1_K4_2 S9_3 S9_4 9_1_K4_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T2_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V4n E3
12 :ANZ textv S9_1 9_1_K4_2 S9_3 S9_4 9_1_K4_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T3_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V4n E3
13 :ANZ text S9_1 9_2_K1_2 S9_3 S9_4 9_2_K1_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T1_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10
;14 :ANZ text S9_1 9_2_K1_2 S9_3 S9_4 9_2_K1_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T2_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10
;15 :ANZ text S9_1 9_2_K1_2 S9_3 S9_4 9_2_K1_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T3_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10
正如您所看到的,这些行的列未对齐,例如,行13
相对于行未对齐14
,并且15
由于;
.但还有更困难的错位情况。例如有这样的行:
;14 :ANZ text S9_1 9_2_K1_2 S9_3 S9_4 9_2_K1_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T2_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10
;15 :ANZ text S9_1 9_2_K1_2 S9_3 S9_4 9_2_K1_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T3_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10
或者任何你能想象到的东西。我想要的是对齐所有列,使得每列之间有四个空格距离。例如,我希望线条;07-09
看起来像这样:
;07 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T1_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
;08 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T2_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
09 :ANZ textv S9_1 9_1_K3_2 S9_3 S9_4 9_1_K3_5 S9_T1_1 S9_T1_2 S9_T1_3 S9_T3_4 S9_T1_5 S9_T1_6 S9_T1_7 S9_T1_8 S9_T1_9 S9_T1_10 9_V3n E3
有没有一种方法可以vim
有效地做到这一点?
答案1
在command
模式下,运行:
:%!column -t
但这并没有对齐第一列。你应该使用对齐插件以获得更多高级选项。
或者你可以不使用vim
,来格式化它perl
:
perl -anle 'BEGIN{$"="\t"} $F[0] = sprintf("%3s", $F[0]);print "@{[@F]}"' file
设置$"
为您想要的任何分隔符。