visual-studio-code - 在 vscode 中,如何定义一个快捷方式来调用当前活动语言的自定义代码段?
问题描述
假设我有一个Ruby
用户片段来输出字符串ruby 和一个Python
用户片段来输出字符串python。如何在 ruby 模式下Ctrl+b调用上述代码段,并在 python 模式下调用代码段?Ruby
Python
解决方案
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "ruby"
},
"when": "editorLangId == ruby"
},
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "python"
},
"when": "editorLangId == python"
},
langId
此外,您可以使用and参数引用现有的代码段,而不是使用代码段参数值来定义您的代码段内联name
。
https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_assign-keybindings-to-snippets
推荐阅读
- c# - 如何将此 JSON 反序列化为 C# 类
- python - 双击使用 pyinstaller 构建的 OS X 应用程序包不会打开应用程序,但可以从包中运行可执行文件。怎么了?
- spring - Spring从反向代理获取实际方案
- c# - 无法加载文件或程序集“System.Security.Principal.Windows”
- mapbox - 收钱不提供服务是骗局。你的服务有效吗?
- sql - 如何使用 django 获取具有相似标签的对象
- dart - 你能在关闭时收听 ShowBottomSheet 吗?
- c - 将二维数组传递给C混淆中的函数
- android - 如何在 Android 的 Firestore 中自动生成的文档 ID 文档中添加多个子集合?
- php - 文本jquery编辑器如何显示格式?