假设我有一个Ruby
用户代码段来输出字符串 ruby 和一个Python
用户代码段来输出字符串 python 。如何在ruby模式下使 Ctrl + b 来调用上述Ruby
代码段,而在python-模式下如何调用Python
代码段模式?
答案 0 :(得分:1)
{
"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
和name
参数来引用现有的代码段,而不是使用snippet参数值来定义代码段内联。
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