EN
VS Code - configure shortcut to insert console.log() in JavaScript or TypeScript
10 points
In this short article, I whould like to explain how to create shortcut that inserts console.log()
in VS Code.
The solution uses built in snippet feature.

Simple steps:
1. Go to: File -> Preferences -> Keyboard Shortcuts (or just press Ctrl
+k
Ctrl
+s
),
2. In the top right corner click Open Keyboard Shortcuts (JSON) icon to see JSON editor,
3. Paste the following item:
xxxxxxxxxx
1
{
2
"key": "ctrl+shift+l",
3
"command": "editor.action.insertSnippet",
4
"when": "editorTextFocus",
5
"args": {
6
"snippet": "console.log('${TM_SELECTED_TEXT}$1')$2;"
7
}
8
}
4. Save configuration (you can press Ctrl
+s
),
5. Open some JavaScript file, select some text, and press Ctrl
+Shift
+L
keys.
Hints to JSON "snippet"
field:
$1
tells where carriage should be moved after snippet insert operation completed,$2
tells from whereTab
key pressed, inserts new tabs to source code - before$2
position it just jumps to the new positions,$1
and$2
are called Tabstops - check official documentation here.