Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda