I want to add increased number for multi selected caret in visual studio code.
now, When I type it write same words.
But I would like to add increased number by some shortkey so that I don’t need to update each one manually.
Preferred result should be like this.
I want to know if this is possible in vs code.
Thanks
3
Answers
You can do it with Increment Selection or Text Pastry
You can use the extension Regex Text Generator
Define the following key binding
index:
Enter
if you like it,Esc
to abortYou do not need an extension for your use case, although that may make it easier. Here is how to do it without an extension.
(?<=index:s*)d+
: this selects only the digits followingindex:
.Now you can run a simple snippet to replace those digits with an increasing number that could be 0-based or 1-based. Make this keybinding to insert the snippet (in your
keybindings.json
):Here is an extension approach, using an extension I wrote, Find and Transform, that makes this easy. Make this keybinding:
That combines the find and replace in one step.
Here is another method so you do not need to hardcode the starting point.
Put the cursor next to or select the number you want as the starting point. The number could be anywhere in the document actually.