visual-studio-code - 在Visual Studio代码(vscode)上包装选择代码段

标签 visual-studio-code

我想在触发时创建一个代码段,它将围绕给定的文本。目前,我的代码段是:

{ 
  "Function Creator Helper": {
    "prefix": "_w",
    "body": [
      "public function $TM_SELECTED_TEXT () {",
      "  $1",
      "}",
    ],
    "description": "Creates a function given the text selection"
  }
}


结果是:

Wrapping snippet

我要做的是:


选择文字。
写前缀(_w
按Tab


结果是:

public function  () {

}


但我期待

public function person () {

}


关于如何制作此代码段或如何正确触发它的任何想法?

最佳答案

如果使用热键触发$TM_SELECTED_TEXT,则可以使用它:

{
  "key": "cmd+k 1",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus",
  "args": {
    //  "langId": "csharp",
    "name": "Function Creator Helper"
  }
}

关于visual-studio-code - 在Visual Studio代码(vscode)上包装选择代码段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41253038/

相关文章:

angular - 即使安装了Typescript 3+版本,Typescript 3+功能也不起作用

visual-studio-code - 完全卸载 WSL 中的 VS Code 扩展

visual-studio-code - vscode中扩展相关信息存放在哪里

amazon-web-services - VS Code 远程 SSH 到 AWS 实例

typescript - 在 Visual Studio Code 中使用 TypeScript 时,如何将 TS 警告配置为显示为错误?

visual-studio-code - 如何在 vs 代码中编辑现有的 azure 函数

javascript - VS 代码在使用 Angular async 和 elvis 运算符与 observable 时出现 "identifier not defined"错误

python - 如何让 VS code 与 Pybuilder python 项目一起使用?

F#、VSCode 和 OSX : The namespace or module 'Expecto' is not defined

flutter - VS 代码不会在调试控制台中显示 Flutter 错误