检测vscode中的文件扩展名

时间:2018-01-06 04:05:12

标签: visual-studio-code vscode-settings

我同时执行python和节点编码。我在Visual Studio Code中有一个用于console.log()的键绑定。

  {
    "key": "ctrl+shift+l",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
        "snippet": "console.log('$0',)"
    }
  }

我想要同样的快捷方式来检测.py扩展名并打印print('',)并检测.js, .ts文件扩展名并打印console.log('',)

1 个答案:

答案 0 :(得分:0)

{
    "key": "ctrl+shift+l",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus && editorLangId == javascript",
    "args": {
        "snippet": "console.log('$0',)"
    }
},
{
    "key": "ctrl+shift+l",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus && editorLangId == typescript",
    "args": {
        "snippet": "console.log('$0',)"
    }
},
{
    "key": "ctrl+shift+l",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus && editorLangId == python",
    "args": {
        "snippet": "print('$0',)"
    }
},