0

I'm facing a challenge with SVG attributes results. I need to rename several of the results of the SVG attribute in a sequential form.

xlink:hreef-"#path-1"
xlink:hreef-"#path-2"
xlink:hreef-"#path-3"
...

How can I automatize it? Exist a plugin or extension of VSCode that can help me?

Thanks in advance!

Alves, Luiz.

rioV8
  • 24,506
  • 3
  • 32
  • 49

2 Answers2

0

You can do that with this extension I wrote: Find and Transform and this keybinding:

{
  "key": "shift+alt+s",             whatever keybinding you want
  "command": "findInCurrentFile",
  "args": {
    "find": "(xlink:href-\"#path)",
    "replace": "$1-${matchNumber}",
    "isRegex": true,
  }
}

It will find (xlink:href-\"#path) replace it withitself $1 and append -${matchNumber} to it. So the first match will get a 1, the second match a 2 and so on.

If you wanted those 0-based you could use ${matchIndex} instead.

find-and-transform demo with matchIndex

Mark
  • 143,421
  • 24
  • 428
  • 436
0

You can use the extension Regex Text Generator

Find and select all the items you want to rename

Find xlink:hreef

The Select > Select All Occurrences

Now move the multi cursors and select the part you need to replace.

Then issue command: Generate text based on Regular Expression

For the generator expression use: {{=i+1}} if you want the numbering start at 1.

You get a preview of what the result is.

rioV8
  • 24,506
  • 3
  • 32
  • 49