Home > database >  How can i generate number for same piece of text using VS Code
How can i generate number for same piece of text using VS Code

Time:09-16

i have many pieces of code same for example like this

alt="Greece"
alt="Greece"
alt="Greece"
alt="Greece"

Can i somehow modify it to this? Is there any kind of function like in Excel or something like that please? Imagination write it manualy each is horrible

alt="Greece 1"
alt="Greece 2"
alt="Greece 3"
...
alt="Greece 200"

CodePudding user response:

You can use the extension add a matchIndex to a line


Another option - not quite as easy

Snippets have a variable $CURSOR_NUMBER which is useful here.

Make this keybinding:

{
  "key": "alt n",
  "command": "editor.action.insertSnippet",
  "args": {
    "snippet": "$TM_SELECTED $CURSOR_NUMBER"
  },
  "when": "editorHasSelection"
},
  1. Do a find on your desired text match: alt="Greece"
  2. Ctrl Shift L to select all occurrences of the find match.
  3. Trigger the snippet via its keybinding.

Demo of this method:

demo of using snippet with $CUROSR_NUMBER

So this second method is more steps but doesn't require an extension.

  • Related