andio
andio

Reputation: 1778

How to replace multiple selection with incremental number in sublime text 3?

For example :

xx
test1
xx 
xx
test1 
xx
test1 
test1

i use the regex search : test\d to grab those text1 and want to replace it with ok# . Sot make it to be like this :

xx
ok1
xx
xx
ok2
xx
ok3
ok4

How to generate that increment number ?

Upvotes: 1

Views: 1252

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

The built in Arithmetic command can do this sort of thing for you. The full specifics of how that command works can be found in "how to add different number at end of multi line edit?" if you'd like to know the various things you can do with the command and how it works.

For your case, the steps would be:

  1. Do a regex Find and use the Find All button to select all of the items that you would like to replace; you end up with multiple cursors in the buffer
  2. Type the part you want before the prefix (in this case ok) which will replace all of the matches with that text
  3. Open the command palette and select the Arithmetic command and run it.

The default expression for the command is i + 1, which will do you want, so you can just hit enter to select it and run the command. The preview under the command name shows you what is going to be inserted.

Upvotes: 3

Related Questions