VS Code 自定义快捷键快速插入 console.log 并自动添加剪贴板内容
VS Code 自定义快捷键快速插入 console.log 并自动添加剪贴板内容
本文将带您学习如何自定义 VS Code 快捷键,快速插入 console.log() 语句,并将剪贴板中的内容自动添加到语句中,方便您进行代码调试。
操作步骤
- 打开 VS Code,并打开用户设置(通过快捷键
Ctrl + ,或从菜单栏中选择File > Preferences > Settings)。 - 在搜索栏中输入 'keybindings',点击 'Edit in settings.json'。
- 在
keybindings.json文件中添加以下代码:
{
"key": "ctrl+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log('${TM_SELECTED_TEXT}$1');$0"
}
}
- 保存文件并关闭设置页面。
现在,当您在编辑器中选择一个文本片段并按下 Ctrl + Shift + L 时,将自动插入 console.log() 语句,其中包含剪贴板中的文本片段。
原文地址: https://www.cveoy.top/t/topic/mNGp 著作权归作者所有。请勿转载和采集!