This is for visual studio.
As suggested by Adrian Smith and others: If you want to bind a keyboard shortcut to create a console log statement, you can do the following:
- File > Preferences > Keyboard Shortcuts
- Below the search bar you’ll see a message “For advanced customizations open and edit keybindings.json”, click on it
- Add this to the JSON settings:
{
"key": "ctrl+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log('${TM_SELECTED_TEXT}$1')$2;"
}
}
Pressing CTRL+SHIFT+L will output the console snippet. Also, if you already have text selected it will be put inside the log statement.
If you rather want intellisene/autocomplete:
Go to Preferences -> User Snippets -> Choose Typescript (or whatever language you want). A
json
file should open. You can add code snippets there.
There is already a snippet for
console.log
commented out:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
You have to do this for every language you want to use the snippet … is kinda bothering.
Also, you should set
"editor.snippetSuggestions": "top"
, so your snippets appear above intellisense. Thanks @Chris!
You can find snippet suggestions in Preferences -> Text Editor -> Suggestions