您可以在VSCode代码段中访问类名吗?

时间:2016-01-02 22:09:49

标签: textmate visual-studio-code

例如,如何在VSCode中创建等效的ctor Visual Studio C#片段?我正在查看VSCode片段系统所基于的TextMate文档,我看到很多变量,如TM_SCOPE,但VSCode似乎没有评估这些变量。这在VSCode片段支持的当前状态下是不可能的吗?

3 个答案:

答案 0 :(得分:2)

根据VSCode文档,当您想为C#创建新的代码段文件时:

// Place your snippets for C# here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, ${id} and ${id:label} and ${1:label} for variables. Variables with the same id are connected.

目前似乎(在v0.10.6上),只允许$ n个变量。

答案 1 :(得分:0)

但它支持除Interpolation Templates,RegEx和Transformations之外的所有TextMate变量 - 因此您可以根据文件名进行添加:

"body": [
    "public $TM_FILENAME()",
    "{",
    "$0",
    "}"
]

这很遗憾地得到了文件扩展名,还没弄明白如何剃掉那个

答案 2 :(得分:0)

事实证明,现在可以!

只要要显示文件名,只需添加$ {TM_FILENAME_BASE}。还有很多其他变量,例如TM_CURRENT_LINE用于获取当前行上的文本,甚至是CLIPBOARD。

您可以在以下官方文档中找到所有可用的命令: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables

相关问题