Sublime Text 2代码片段不能在适当的范围内工作 [英] Sublime Text 2 code snippet not working in proper scope

查看:98
本文介绍了Sublime Text 2代码片段不能在适当的范围内工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚写了下面的代码片段,并将其作为add-script-source.sublime-snippet保存在文件夹Packages / User / HTML中。

I have just written the following snippet, and saved it in the folder Packages/User/HTML as "add-script-source.sublime-snippet."

<snippet>
    <content><![CDATA[
<script type="text/javascript" src="${1:script.js}">${2}</script>
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>scriptsrc</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html</scope>
</snippet>

现在,我只希望这个代码段能够在HTML文件中工作,但事实并非如此。如果我注释掉范围标签,它将在JavaScript中工作,但仍不在HTML中。我的印象是,用户文件夹下的文件夹名称也给了Sublime Text适当的范围(如本视频所述 https://tutsplus.com/lesson/your-first-snippet/ ),这似乎没有做任何事情。每当我将范围标签设置为ANYING时,该代码段都不会触发。

Now, I only want this snippet to work in HTML files, but it does not. If I comment out the "scope" tag, it will work in JavaScript, but still not in HTML. I was under the impression that the name of the folder beneath your User folder also gave Sublime Text the appropriate scope (as stated in this video https://tutsplus.com/lesson/your-first-snippet/), this does not appear to do anything. Whenever I set the scope tag to ANYTHING, the snippet does not trigger.

这可能是什么问题?

What might the problem be?

推荐答案


只有有用的sublime文本autocomplete不会出现,因为它在其他语言中是
。有人知道为什么会这样吗?

您需要将它添加到 Packages / User / Preferences.sublime-settings

You need to add this to your Packages/User/Preferences.sublime-settings file.

 "auto_complete_selector": "source, text"

然后在代码片段文件中给它一个描述:

Then give it a description in the snippet file:

<snippet>
    <content><![CDATA[
<script type="text/javascript" src="${1:script.js}">${2}</script>
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>scriptsrc</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html</scope>
    <description>scriptsrc</description>
</snippet>

这篇关于Sublime Text 2代码片段不能在适当的范围内工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆