Friday 15 February 2013

Tell vim to add commas to a number, e.g. change 31415926 to 31,415,926 -


I have a very large number (one hundred and one hundred point tall), and I want to use vim to add com I am in a proper way, after each group of three points, goes from right to left. How can I do this efficiently?

derived

The sub-rule that adds the command to the right place

 :% s / \ (\ d \) \ (\ (\ d \ d \ d \) \ + \ d \ @! \) \ @ = / \ 1, / g   

It uses a zero-width shape to match any number that is not followed by a group of three numbers after a number. (Or 3n + 1 number)

The numbers that are in the match are marked with ^ . After this they are replaced with commas after the match.

  31415926 ^ ^   

instead of

  31,415,926    

No comments:

Post a Comment