VSCode keyboard shortcut for logging out a selected variable

In an effort to wean off of TurboLog which has become awfully noisy
11 April 2025
Web development

TL; DR

{
  "key": "ctrl+2",
  "command": "runCommands",
  "args": {
    "commands": [
      "editor.action.clipboardCopyAction", // Copy selection
      "editor.action.insertLineAfter", // Move to next line (deselects)
      {
        "command": "editor.action.insertSnippet",
        "args": {
          // Use clipboard content
          "snippet": "console.log('🤖🤖🤖 $CLIPBOARD:', $CLIPBOARD)"
        }
      }
    ]
  },
  "when": "editorHasSelection" // Only run when text is selected
}

If you want to log out a label only, then this goes hand-in-hand with the above

{
  "key": "ctrl+1",
  "command": "runCommands",
  "args": {
    "commands": [
      "editor.action.clipboardCopyAction", // Copy selection
      "editor.action.insertLineAfter", // Move to next line (deselects)
      {
        "command": "editor.action.insertSnippet",
        "args": {
          // Use clipboard content
          "snippet": "console.log('🙃🙃🙃 $CLIPBOARD')"
        }
      }
    ]
  },
  "when": "editorHasSelection" // Only run when text is selected
},