Increment values/numbers in Sublime 3

2020-06-29 08:34发布

问题:

I have multiple lines like this <VValue type="int" value="0" /> in files running in Sublime; each where the value increments 0, 1, 2, 3 etc...

I need to change these values, +60. So, 0 would become 60, 1 would be 61 etc.

How do I select the multiple lines and append them with regex in Sublime? I'm not sure of the command to select the number itself... something like \d+ was mentioned in another thread - Sublime Text 2 increment numbers

Note, I skip one number to separate some content in the software the files run in, so it really needs to be a +60 to the value command instead of just a direct replace all and increment (as in the thread above) as that would throw off the one that was skipped, if you follow me. For example, it could be 0, 1, 3, 4, 5 that should equal 60, 61, 63, 64, 65 and not 60, 61, 62, 63, 64.

Do I need something like TextPastry, and to use the Number Sequence Command? If so, I'm not sure how that works and would appreciate comments.

Thanks for any help :)

Edit; I think I can use the Auto Step feature in Text Pastry? Can someone kindly run me through this how to... install and use.

回答1:

Unfortunately, Text pastry is not powerful enough (as far as I know). You need some evaluator package. We'll use Sublime-Evaluate here.

To install it (assuming you have package manager installed) simply

Command+Shift+p -> ip -> Enter -> evaluate -> Enter


Now just select the numbers you want to change (search with regex enabled):

(?<=<VValue type="int" value=")\d+(?=" />)

Alt+Enter. Now they are selected.

Right arrow to go after the selection. Type +60. Now Ctrl+Shift+ 3 times to select

0+60
1+60
...
n+60

on each line. Now Command+Shift+e and you are done (alternatively, you can Command+Shift+p -> evaluate -> Enter.