Visual Studio Code 中 console.log 的快捷方式是什么 [英] What is the shortcut in Visual Studio Code for console.log
问题描述
我想知道Visual Studio代码中console.log的快捷方式是什么?
2019 年 2 月更新:
根据 点击它.(将鼠标悬停在它上面时会显示:打开键盘快捷键 (JSON)
<代码>{键":ctrl+shift+l",命令":editor.action.insertSnippet",当":editorTextFocus",参数":{代码片段":console.log('${TM_SELECTED_TEXT}$1')$2;"}}
按 CTRL+SHIFT+L 将输出控制台代码段.此外,如果您已经选择了文本,它将被放入日志语句中.
如果你更想要智能/自动完成:
转到首选项 ->用户片段 ->根据您的需要选择 Typescript(或您想要的任何语言)或全局代码段文件".应该打开一个 json
文件.您可以在那里添加代码片段.
已经注释掉了 console.log
的一个片段:
打印到控制台":{范围":javascript,打字稿,javascriptreact",前缀":日志",身体":[console.log('$1');",$2"],描述":将日志输出到控制台"}
您过去必须为每种语言执行此操作,但现在在全局代码段文件"中您可以设置 scope
属性,该属性允许您显式声明多种语言.
您是否需要语言的确切名称:通过单击 VS Code 底部工具栏右侧的 Select Language Mode
按钮进行检查.它会提示您在顶部选择一种语言,并在此过程中将在括号中显示该语言的 JSON 名称,您可以在上面的示例中将其输入到代码段文件中.
此外,您应该设置 "editor.snippetSuggestions":"top"
,这样您的代码段就会出现在智能感知之上.谢谢@Chris!
您可以在 首选项 -> 中找到片段建议;设置 ->文本编辑器 ->建议
I want to know what is the shortcut for console.log in Visual Studio code?
Update Feb, 2019:
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
- Above the search bar on the right you'll see this icon Click on it. (When hovered over it it says: Open keyboard shortcuts (JSON)
- 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) or a 'Global Snippet File' depending on your need. A json
file should open. You can add code snippets there.
There is already a snippet for console.log
commented out:
"Print to console": {
"scope": "javascript,typescript,javascriptreact",
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
You used to have to do this for every language, but now in the 'Global Snippet File' you can set the scope
property which allows you to explicitly declare multiple languages.
Should you need the exact name of the language: check it by clicking the Select Language Mode
button in the right side of the VS Code bottom toolbar. It will prompt you to select a language at the top and in the process will show the JSON name of the language in parenthesis, which you can enter in the snippet file as in the example above.
Also, you should set "editor.snippetSuggestions": "top"
, so your snippets appear above intellisense. Thanks @Chris!
You can find snippet suggestions in Preferences -> Settings -> Text Editor -> Suggestions
这篇关于Visual Studio Code 中 console.log 的快捷方式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!