2

I have a bunch of data I loaded into VIM to clean up like so:

Dec 19, 2012 Advertising November Adwords 43.00 -Roger
Dec 01, 2012 Rent, Sublease 200.00 -Mary
Nov 01, 2012 Rent, Sublease 200.00
Oct 01, 2012 Rent  Sublease 200.00
Nov 05, 2012 Advertising  42.00
Oct 01, 2012 Advertising September  50.00

I would like to align all the numbers by decimal point. I already installed Tabular.vim but I cannot seem to get the regex to work.

Here is what I think should work:

:'<,'>Tabularize /[0-9]*\.[0-9]+

Ideally, I would like to avoid installing another operating system or plugin to solve the problem.

4

2 に答える 2

2

I don't have Tabular plugin installed, but Align plugin.: http://www.vim.org/scripts/script.php?script_id=294

I don't know what is exactly expected output.

with Align plugin, I just type `

:AlignCtrl p0P0rl

then

:%Align \.

your file content was changed into:

Dec 19, 2012 Advertising November Adwords 43.00 -Roger
             Dec 01, 2012 Rent, Sublease 200.00 -Mary
             Nov 01, 2012 Rent, Sublease 200.00
             Oct 01, 2012 Rent  Sublease 200.00
                Nov 05, 2012 Advertising  42.00
      Oct 01, 2012 Advertising September  50.00

EDIT

JHo, just for your information. I didn't find how to reach your need in one shot, or say, two, first AlignCtrl and then Align. But it is doable.

1st step:

:%Align [0-9]*\.[0-9]

your file will look like:

Dec 19, 2012 Advertising November Adwords 43.00  -Roger
Dec 01, 2012 Rent, Sublease               200.00 -Mary
Nov 01, 2012 Rent, Sublease               200.00 
Oct 01, 2012 Rent  Sublease               200.00 
Nov 05, 2012 Advertising                  42.00  
Oct 01, 2012 Advertising September        50.00  

then set the AlignCtrl

:AlignCtrl p0P0rl

finally press ctrl-v select only the decimal number column, type:

:'<,'>Align \.

text was changed into:

Dec 19, 2012 Advertising November Adwords  43.00 -Roger
Dec 01, 2012 Rent, Sublease               200.00 -Mary
Nov 01, 2012 Rent, Sublease               200.00 
Oct 01, 2012 Rent  Sublease               200.00 
Nov 05, 2012 Advertising                   42.00 
Oct 01, 2012 Advertising September         50.00 
于 2012-12-20T00:43:37.433 に答える
1

My usage of Tabular proceeds by trial-and-error, but this seems to work.

You need to use \zs to specify that the match starts just before the decimal point, and also use the optional alignment specifiers to specify the first column is right aligned and the second column is left aligned. Hence:

:Tabularize /\d*\zs\.\d\+/r0l0
于 2012-12-20T00:36:31.840 に答える