定义自定义Sublime Text 2代码段的范围 [英] Defining scope for custom Sublime Text 2 snippets

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

问题描述

在尝试编写自己的Sublime Text 2片段时,遇到了以下两个问题:

While trying to write my own snippets for Sublime Text 2, I ran into the following two problems:


  1. 查找范围键。我发现可以逐个浏览我的包并找到对声明的 scope属性的引用。例如,在〜/ Library / Application Support / Sublime Text 2 / Packages / JavaScript / Comments.tmPreferences (我的HTML包中的文件)中,有以下两行:

  1. Finding scope keys. I figured out that I can look through my packages one by one and find references to a declared "scope" property. For example in ~/Library/Application Support/Sublime Text 2/Packages/JavaScript/Comments.tmPreferences (a file in my HTML package) there's these two lines:

<key>scope</key>
<string>source.js</string>

因此,如果我希望当前的代码段可用于javascript文件,则可以定义以下范围:

So if I want my current snippet to work on javascript files, I define my scope like:

<scope>source.js</scope>

我假设所有这些作用域键都是根据我拥有的软件包即时定义的已安装。 Sublime Text是否可以在我更容易引用的任何地方构建列表?仔细阅读一堆软件包文件似乎过于繁琐。

I'm assuming all these scope keys are defined on-the-fly based on what Packages I have installed. Does Sublime Text build a list anywhere that I can more easily reference? Perusing through a bunch of package files seems overly tedious.

定义多个范围属性。我已经弄清楚了,下面的代码行允许我的代码段同时在HTML和JavaScript文件中工作。

Defining multiple scope properties. This I've figured out, and the following line allows my snippet to work in both HTML and JavaScript files.

<scope>text.html, source.js</scope>



推荐答案

查看光标位置的当前范围



View Current Scope of Cursor Position


  1. 将光标放在要了解范围的文件中。

  2. 使用此键盘快捷键:

  1. Place your cursor in the file where you wish to know the scope.
  2. Use this keyboard-shortcut:

Windows ctrl + shift + alt + p

Mac: ctrl + shift + p

Windows: ctrl+shift+alt+p
Mac: ctrl+shift+p

当前作用域将显示在Windows上状态栏的左侧,或者在Mac的弹出窗口中。

The current scope will be displayed in the left side of the status bar on Windows, or in a popup window on Mac.

将它们用作< scope> 键输入 foo.sublime-snippet 文件。

Use these as the <scope> key in your foo.sublime-snippet file.

返回的作用域列出为具体。选择最能将代码段范围到标签触发范围的范围。

The returned scopes are listed generic to specific. Choose the scope(s) which best "scoped" the snippet to where it should be available to tab trigger.

这篇关于定义自定义Sublime Text 2代码段的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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