sublimetext2

Add a number to each selection in Sublime Text 2, incremented once per selection


Is there a way to add insert a number that is incremented once per cursor in Sublime Text 2?

Example, with | as the cursor:

Lorem ipsum dolor sit amet, |
vehicula sed, mauris nam eget| 
neque a pede nullam, ducimus adipiscing, 
vestibulum pellentesque pellentesque laoreet faucibus.|

Desired result:

Lorem ipsum dolor sit amet, 1|
vehicula sed, mauris nam eget2| 
neque a pede nullam, ducimus adipiscing, 
vestibulum pellentesque pellentesque laoreet faucibus.3|

Does this functionality exist natively, or is there a plugin providing it?


Solution

  • I recommend the plugin Text Pastry. The Number Sequence command is the one you need.

    I prefer to use the Insert Nums command:

    Text Pastry has a build in support for the Insert Nums syntax by providing three numbers separated by one space:

    N M P

    N: the start index.

    M represents the step size which will be added to the index for each selection.

    P must be > 0 and will be used to pad the index with leading zeroes.