我将以下内容保存在 ~/Library/Application Support/Sublime Text 3/Packages/User 中sass_mq.sublime-snippet:
<snippet>
<content><![CDATA[
@include respond-min() {}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>mq</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.sass</scope>
</snippet>
Run Code Online (Sandbox Code Playgroud)
我source.sass通过按 cmd + opt + p 并查看状态栏来获得。
如果我删除范围,它适用于所有其他文件类型,但绝不适用于 .scss 文件。
我的语法错误吗?
我厌倦了编写样板属性代码,例如:
public string Name
{
get { return this.name; }
set { SetProperty(ref name, value); }
}
Run Code Online (Sandbox Code Playgroud)
因此,我决定在 Visual Studio 中制作一个代码片段来自动化该过程:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MVVM Property</Title>
<Shortcut>propm</Shortcut>
<Author>MFeinstein</Author>
<Description>Adds a Property that calls PRISM no Notify any changes</Description>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Replace with the property type</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>PropertyName</ID>
<ToolTip>Replace with the property name</ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>fieldName</ID>
<ToolTip>Replace with the field name</ToolTip>
<Default>fieldName</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private $type$ $fieldName$;
public …Run Code Online (Sandbox Code Playgroud) c# properties code-snippets visual-studio-2012 visual-studio-2013
2013 年的 Express for Web 中有用于添加默认操作和发布操作的 MVC 代码片段 (mvcaction4和mvcpostaction4)。Visual Studio 2015 Community 似乎没有这些。我需要安装特定的工具或下载来恢复这些或获取 MVC5 版本吗?或者我是否需要复制它们并将它们粘贴到我的自定义脚本中?
c# asp.net-mvc visual-studio code-snippets visual-studio-2015
我正在尝试创建一个代码片段,它将打印一些带有当前文件名和当前方法/标签名称的控制台日志,就像我们在systrEclipse 中的方式一样。
虽然我可以在Tools > Options > Text editor > Snippet中添加代码片段,但我找不到任何标签来检索当前文件名。
示例文件(TestMyUI.js):
function doSomething{
console.log("TestMyUI.doSomething()");
}
Run Code Online (Sandbox Code Playgroud)
在这里,我喜欢console.log使用保存在片段中的模板来生成。因此,对于我输入类似内容的每个地方,consLog都必须自动完成填充当前文件和方法名称的日志。这与我们在 eclipse IDE 中的类似systr。
我在以下位置设置了自定义片段javascript.json:
"Node regular import": {
"prefix": "creq",
"body": ["const ${2:module} = require('$1')"],
"description": "Node regular import"
},
Run Code Online (Sandbox Code Playgroud)
当我输入creq然后按时它会起作用tab:
但是,我希望此代码片段自动完成功能也能触发 vscode 的 Intellisense。现在,我需要按ctrl+space才能得到我想要的:
有什么方法可以配置 vscode 这样我就不需要每次都按Ctrl+了?Space
我正在尝试为 python 制作一个 vscode 片段。假设我有这样一行代码:
my_var = call_some_function()
Run Code Online (Sandbox Code Playgroud)
我想双击 my_var 来选择它,按下一个键,它会产生以下结果:
my_var = call_some_function()
LOGGER.debug("my_var: %s", my_var)
<cursor is here>
Run Code Online (Sandbox Code Playgroud)
它也应该适用于表达式,就像我在这一行中选择“x + y + z”并按下键:
call_function(x + y + z)
Run Code Online (Sandbox Code Playgroud)
它应该产生:
call_function(x + y + z)
LOGGER.debug("x + y + z: %s", x + y + z)
<cursor is here>
Run Code Online (Sandbox Code Playgroud)
显然使用调试器更好。但有时您不能使用调试器。
在 Visual Studio Code 中,片段在注释或字符串中不起作用。例如,我为“test”创建片段“t”,然后在注释中输入“t”,如下所示
# t
Run Code Online (Sandbox Code Playgroud)
或者像字符串一样
"this is a string t"
Run Code Online (Sandbox Code Playgroud)
然后没有任何建议,按“tab”不起作用。
如何在 Visual Studio 代码中使用注释和字符串中的片段?
所以我已经使用 VS Code 一段时间了,我注意到由于某种原因它开始出现我没有在选项中出现的额外片段,虽然它们很有用,但我想将它们编辑为我个人的代码格式样式。
我尝试寻找json保存它们的文件,但是我无法在任何地方找到它。我认为它会在我的安装目录中,但是cpp.json那里的文件仅定义了#pragma region代码片段。
作为参考,我查看了这个位置:C:\Users\Rietty\AppData\Local\Programs\VSCode\resources\app\extensions\cpp\snippets
显示两个片段的区别如下:
user snippet我的用户定义了一个,在描述旁边标有。
我还得到了许多新的for循环等等:
在哪里可以找到这些新片段的位置,以便我可以将它们编辑为我的标准/格式样式?
更新:
我花了相当多的时间查找这个,似乎这是由于VSCode CPP 工具扩展造成的。最近的更改表明,发生这种情况是由于将片段从相关json文件移动到硬编码词法分析器,并且这是当前的预期。
不过,问题已经提交,预计将于 2019 年 2 月某个时间得到解决。
我创建了一个代码片段以在编辑 php 文件时使用。但是,当我选择插入代码段时,我的代码段不会出现在代码段列表中。
如果我显示代码片段管理器并选择 PHP 作为语言,则会显示我的片段文件夹。如果我展开该文件夹,我会看到我的代码段(它以 *.snippet 文件扩展名保存在该文件夹中)。我还重新选择了“导入”按钮以重新导入该片段。它导入没有任何错误。
但是,当我在编辑 php 文件时选择 Insert Snippet 时,intellisense 菜单中只显示 ASP.NET、ASP.NET Web Stack 5 和 HTML。它不显示我的代码段文件夹名称或我的代码段。
谢谢!
code-snippets ×10
c# ×2
asp.net-mvc ×1
intellisense ×1
php ×1
properties ×1
qt ×1
qt-creator ×1
qt4 ×1
sass ×1
sublimetext ×1
sublimetext3 ×1