Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
How to output regular numbers in multi-cursor state in vscode?

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?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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}}
about 4 years ago · Juan Pablo Isaza Relatório

0

As of v1.66 it won't be necessary to use an extension at all for simple replacement (0, 1, 2, ... or 1, 2, 3, ...) like this. New snippet variables

$CURSOR_INDEX or ${CURSOR_INDEX}
$CURSOR_NUMBER or ${CURSOR_NUMBER}

are being added (they are in Insiders now). So your snippet could be as simple as (inserted here via a keybinding in keybindings.json):

{
  "key": "alt+i",                       // whatever keybinding you want 
  "command": "editor.action.insertSnippet",
  "args": {
    "snippet": "$CURSOR_NUMBER"
  },
  "when": "editorTextFocus && editorHasMultipleSelections"   // if you want to restrict it
},

increment integer for each cursor position

You can't do any real math on the added numbers other than increment from 0 or 1. To do more interesting math see below extension.


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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda