How to add leading zeros with fixed length and given number set in SublimeText 3

I have multiple integers of different length / width. Example:

490

29

0924

29

1

I'm looking for a convenient way in SublimeText 3 to convert them so that each has a leading zero and a total width of 5. I know Excel has this feature: Select Column> Format Cells> Custom> (enter five zeros)> Viola ! but need a solution in SublimeText.

00490

00029

00924

00029

00001

I tried using Sublime Text plugins Insert Nums

and TextPastry

but couldn't figure out how to do it.

With TextPastry I did: ~05

on the command line, which will have the correct formatting, but will start me at 1, thereby creating 00001

, 00002

etc. I need a way to tell it to work down the list already provided, not create one from the index. I thought I would \i

do this iteration, but apparently it will start the index at 1.

How should I do it?

+3


source to share


1 answer


Insert Nums

can do it.

1 / Select existing data:

490 29 0924 -29 1

2 / Split selection into multiple lines ( cmd+shift+l

or ctrl+shift+l

)

3 / Go to Insert Nums

4 / Use this input: i|~=05::_



5 / Result: 00490 00029 00924 -0029 00001

Explanations:

  • i

    used to say that you are actually reading integers ( f

    for floats)
  • |

    means you are using existing, selected data
  • ~=05

    - zero padding to length 5 ( =

    not actually needed here)
  • ::_

    is an expression, in this case it is _

    used to "use the data as is"

Let me know if you have any problems with this.

- Alexis

+4


source







All Articles