I have several whole numbers of varying lengths/widths. Sample set below:
490
29
0924
29
1
I'm looking for a convenient way in SublimeText 3 to transform them so that each has a leading zero and the total width is 5. I know Excel has this feature: Select column > Format Cells > Custom > (type in five zeros) > Viola!, but need a solution in SublimeText.
00490
00029
00924
00029
00001
I have tried using the the Sublime Text Insert Nums
and TextPastry
plugins but could not figure out how to do it.
With TextPastry, I did:
~05
in the command line, which would get the formatting right but would start me off at 1, thus creating 00001
,00002
etc. I need a way to tell it to work it's way down the list I've already provided, not create one from an index. I thought \i
would do this kind of iteration but apparently it start the index at 1.
How would I do this?
Insert Nums
can do that.
1/ Select your existing data:
490
29
0924
-29
1
2/ Split your selection into multiple lines (cmd+shift+l
or ctrl+shift+l
)
3/ Go into Insert Nums
4/ Use this input: i|~=05::_
5/ Result:
00490 00029 00924 -0029 00001
Explanations:
i
is used to say you're actually reading integers (f
for floats)|
means you are using existing, selected data~=05
is the zero-padding to a length of 5 (=
is actually unnecessary here)::_
is the expression, in this case, _
is for "use the data as it is"Let me know if you have any issue with this.
--Alexis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With