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

147
Visualizações
How to wrap a line in console.log

I find myself frequetly wanting to enclose statements or lines with a console.log(...). For example if I have the following code:

let myVar = "Hello";
myVar.slice(1,3);|            // '|' means where the cursor is after typing in the last line

And from there I'd like to wrap that line in a console.log so it then becomes:

let myVar = "Hello";
console.log(myVar.slice(1,3));

Is there a short-cut that I can create in VS Code to do this? I have one extension that is supposed to do this but 80% of the time it gets it wrong (for example putting the ) after the ; and so I'd just like to do one short-cut command that always gets it right, without having to install an extension. How could I do this?

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

0

I think you are going to have to use a macro extension to run a couple of commands in a row to do this. If you selected that line first you wouldn't need the macro extension. Using multi-command, put this into your keybindings.json:

{
  "key": "alt+q",
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "cursorHomeSelect",
      {
        "command": "editor.action.insertSnippet",
        "args": {
          "snippet": "${TM_SELECTED_TEXT/(.*)./console.log($1);/}"
        }
      }
    ]
  },
  "when": "editorFocus"
}

cursorHomeSelect first to select from the cursor to beginning of text on line.

(.*). Capture the rest of the line except for the last character ;. That last matched ; will not be in capture group 1 and so will not appear within the console.log...) body.

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