Home > database >  How to output regular numbers in multi-cursor state in vscode?
How to output regular numbers in multi-cursor state in vscode?

Time:11-13

Let's say I want to call a function 10 times quickly:

step1: Write ten fn(1)

step2: Use the multi-cursor to select the parameters 1 of these ten functions

enter image description here

But then I don't know what to do, because I can't make the first one be 1, the second one be 2, the third one be 3...

Or is there a syntax like Emmet(div{$}*3) in js file?

CodePudding user response:

You can use the extension Regex Text Generator

Use the command Generate text based on Regular Expression

  • for match regex use: .*
  • for generator expression use: {{=i 1}}

CodePudding user response:

Using an extension that I wrote this is very easy: Find and Transform.

Create this keybinding (in your keybindings.json):

{
  "key": "alt y",                   // whatever keybinding you want
  "command": "findInCurrentFile",
  "args": {
    // "find": "1",            // actually not necessary
    "replace": "${matchNumber}",
    "matchCase": true              // match only APPLE, not Apple
  }
}

That will replace whatever word your cursor is on with the matchNumber starting at 1. If you wanted to start at 0, use ${matchIndex}.

If you need to specify a more complicated regex find, you can do that too.

  • Related