Sublime Text非官方文档(中文翻译版)¶
关于本文档¶
这是由ST党拥护者们维护的Sublime Text编辑器的非官方文档。希望能对您有所帮助!
sublime是什么?你在说什么东西啊?
Sublime Text 是一款为编写代码和文稿而准备的多功能编辑器。它能为你做很多重复性的工作, 从而让你的精力更专注在编写的内容上面。更重要的是,它会给你带来愉悦感!
在你继续阅读之前,我们鼓励你通读一下 基本概念 章节。
学的开心哦!
安装¶
在不同平台上有不同的Sublime Text安装过程。
Sublime Text并不是免费的,使用前请务必阅读官方网站上的 使用条约 。
32位还是64位?¶
请根据操作系统的不同,做出对应选择。如果你正在使用64位的系统,就请下载64位的版本,否则就下载32位的版本。
在 Windows 平台,如果你不知道如何查看操作系统的版本,就请下载32位版。现在的64位Windows 操作系统可以正常运行32位的软件。
在 Linux 平台,请在终端中输入下面的命令来查看操作系统的类型:
uname -m
对于 OS X 的用户,你不必关心此部分内容,因为Sublime Text在OS X平台上只有一个版本。
Windows¶
选择便携版还是非便携版?¶
Sublime Text在Windows平台提供了两种安装类型:一种是标准安装,另外一种则是便携安装。只有 当你确信自己要使用便携版的时候才选择便携安装,否则就请选择标准安装。
标准安装 会将数据分散到两个文件夹:正确的安装目录,以及 数据目录 。这些概念将在稍后 的文档中进行解释。标准安装也会将Sublime Text的选项与Windows的快捷菜单进行整合。
便携安装 会将所有Sublime Text需要的文件放到一个目录中。这样你就可以通过介质随身携带 这个目录,而编辑器仍然可以正常工作。
如何安装标准版的Sublime Text¶
很简单,下载安装器,双击运行,然后跟着屏幕上的指令一步一步操作就可以了。
如何安装便携版的Sublime Text¶
Download the package and uncompress it to a folder of your choice. You will find the sublime_text.exe executable inside that folder. 下载压缩包,并将其中的内容解压到你选择的路径。你能在解压的路径中找到 sublime_text.exe 的可执行文件。
OS X¶
下载并打开 .dmg 文件,将其中的Sublime Text 2拖拽到 应用程序 文件夹即可。
Linux¶
你可以手动下载并解压包文件。或者,你可以使用下面的几行命令:
cd /path/to/your/apps
wget http://url/to/sublime.tar.bz2
tar vxjf sublime.tar.bz2
如果你愿意的话,也可以使用下面的命令来创建一个可以方便使用的符号连接:
sudo ln -s /path/to/sublime_text /usr/bin/subl
尝试冒险或选择稳定的版本¶
Sublime Text有三个发布 通道 :
如果你正在为NASA(译者注:或者中国航天部)的项目工作,或者正在赶一个截止日期紧迫的项目。请使用稳定发行版,并且没必要继续 阅读了。稳定发行版 受过更加完整的测试,而且比其他版本更可信赖,更适宜日常的工作。稳定 发行版基本是每月更新一次。 大部分的用户都只需要使用稳定版。
开发 或者 日更新 通道都不是稳定通道,这意味着通过这些通道发布的版本可能包含更多的bug, 或者可能无法可靠的运行。但是它们的更新速度比稳定版要快得多。
每个人都能用免费使用 开发发行版。 总的看来,开发版每月发布两次。尽管它们可能还不能完美承担 每天的工作,但是这些发行版的确较为稳定的展示了接下来要发放的新版本特性。
最后,使用 日更新版 真是站在悬崖峭壁旁,这些发行版发布频率很高,同时也包含大量严重程度 不一的问题。试用这些版本很好玩,但是风险请自负。需要注意的是日更新版 只对注册用户开放 。
基本概念¶
这里我们将解释一些基本概念,只有在熟悉这些概念后,你才能彻底理解这份文档的所有内容。
文档命名规范¶
这份文档是从Windows用户的角度撰写的,但是文档中提到的大部分内容只需要很小的变化就能在其他 平台正常工作。
除非特别说明,否则文档中所有的相对路径(例如 Packages/User)都是相对于*数据目录*的。 后文将解释*数据目录*的含义。
在介绍快捷键的时候,我们假定你正在使用系统默认的按键设定。由于Submline Text按键与命令映射 的工作方式,有些按键组合可能与你正在使用键盘的布局不同。
能力越大,需要处理的问题也就越多¶
Sublime Text是一款高度可扩展、可定制的文本编辑器。它已经为你提供了许多直接使用的功能, 尽管如此,如果你愿意花时间根据自己的需求进行配置,ST将为你提供超高的生产力。本文档将介绍你 所需要知道的配置Sublime Text的一切内容。
我们将在接下来的几段中,简单说明一些有关Sublime Text的内容,这些内容只有在使用 这个编辑器一段时间后才能被真正理解。请不断地探索这个编辑器,同时也经常来翻翻这个文档,总有一天 文档中的所有内容你都会烂熟于心。
不可否认,Sublime Text是码农的神器(译者注:据说是网页前端神器),尽管如此你没必要一定要是程序员才能使用它,即使你不做 任何配置,你也会发现这是你写作工作的一个完美工具。当然了,如果你是一名黑客,那么你很有可能 会把今天剩下的时间都用在探索这个编辑器上了。
Data(数据) 目录¶
Sublime Text 2把几乎所有用户感兴趣的内容都存放在所谓的数据目录下。这个目录的位置是平台相 关的:
- Windows平台: %APPDATA%\Sublime Text 2
- OS X平台: ~/Library/Application Support/Sublime Text 2
- Linux平台: ~/.config/sublime-text-2
对于使用 portable installations(便携安装版) 的用户,数据目录的位置则是 Sublime Text 2/Data 。这里 Sublime Text 2 部分指的是你把包含Sublime Text 2的压缩包 解压的位置。
需要注意的是,虽然被称作 数据 目录,但只有便携安装版的用户,才能真正找到一个叫 Data 的目录。 对于其他类型的安装方式,数据目录的位置请参考上面的说明。
Packages(包组) 目录¶
这是一个 关键目录 :编辑器所支持的编程或标记语言的所有资源都被存放在这里。一个存放对 Sublime Text而言有意义文件的文件夹就被叫做一个 包 。
你可以通过Sublime Text 2的菜单来访问这个目录(Preferences | Browse Packages...), 也可以通过调用``sublime.packages_path()``这个api来访问。在本文档中,我们使用 包组、 包组路径 、包组文件夹 以及 包组目录 来指代这个文档。
User(用户)
包¶
Packages/User 这个目录是一个存放所有用户自定义的插件、代码片段、宏等等的大杂烩。请把这个 目录看成是你在包组目录中的私人领地。Sublime Text 2在升级的过程中永远不会覆盖*Packages/User* 这个目录中的内容。
Python控制台以及Python API¶
这部分信息对码农来说格外有趣。而对于其他的Sublime Text 2用户来说,你只需要知道Sublime Text 允许会编程的人为这个编辑器添加他们自己需要的功能。(所以赶紧去学学编程吧,真的很有趣!)
( 译者注:小伙子,干什么不好非要当码农,此间慎入! ;) )
Sublime Text 2自带了一个内嵌的Python解释器。这对于检视Sublime Text 2的各种设置项,以及 在开发插件过程中快速简单测试API调用的效果来说都是非常有用的!
只需按下组合件 Ctrl+`
或者从菜单中选择 View | Show Console,就能呼出Python控制台。
有点听迷糊了?咱们再说一些背景知识吧:
Python 是一门对初学者而言非常容易上手,同时又具有强大能力的编程语言。 而 API 则是对 ‘Application Programming Interface(应用程序编程接口)’的缩写,这实际指的是Sublime Text 2为用户准备的可以配置它的方式。换句话说,Sublime Text通过Python这门语言为用户提供了访 问其内部的方式。最后需要说明的是 控制台,它是Sublime Text内部的一个可以输入并运行Python 代码片段的小窗口。控制台同时也负责显示由Sublime Text以及相关插件输出的文本信息。
操作系统中的Python vs Sublime Text 2内嵌的Python¶
在 Windows 以及 Linux 平台,Sublime Text 2的Python解释器是完全与系统的Python 解释器分离的。
而在 OS X 平台上,Sublime Text使用的则是系统的Python解释器。这就导致对系统Python解释 器版本所做的修改,可能会对Sublime Text造成影响。比如使用MacPorts提供的解释器替换系统默认的 解释器,就可能造成一些问题。
这个内嵌的解释器只是为了与插件API作交互,并不应该用来进行通用Python应用的开发。
包组,插件,资源以及其他你现在可能并不理解的东西¶
就目前而言,你只需要记住Sublime Text中几乎所有的东西都能根据你的需求作调整。这种巨大的灵活性 解释了你为什么要学如此多种类型的设置文件——从得有个地方记录你的设置吧!
Sublime Text中的配置文件允许你调整编辑器的表现,添加宏和代码片段,以及创造更多新的特性,注意 这里的 特性 指的是 ‘你能想到的一切’。好吧,也许 一切 说的有点夸张了,但是Sublime Text绝对 为你提供了巨大的控制权。
这些配置文件就是一些遵循特定结构或 格式 的文本文件:在配置文件中,JSON文件占主导地位,有时 你也会发现一些XML文件。
在本文档中,我们把这些完全不同的配置文件总体的称为 资源 。Sublime Text会在包组路径中寻找这 些资源。为了让文件夹结构不显得那么杂乱,编辑器把包含为同一功能服务的各种资源的文件夹称为一个 包 (举例来说,也许某个包中的资源都是为更快的编写email服务的,亦或都是为某个编程语言服务的)。
Textmate兼容性¶
This information is mainly useful for Textmate users who are now using Sublime Text. Textmate was an editor for the Mac. 这部分信息主要是为从Textmate转型使用Sublime Text的用户准备的。Textmate,它是Mac平台的 一个编辑器。
(译者注:Textmate是Mac平台很成功的一款编辑器)
除了命令有些差距之外,Sublime Text 2与Textmate的bundles(包)能较好的兼容。更进一步的说, 为了识别为TM编写的bundles,Sublime Text要求所有的语法定义文件都包含 .tmLanguage 扩展名, 并且所有的配置文件都有 .tmPreferences*扩展名。这意味着即使 *.plist 文件保存在 Syntaxes 或者 Preferences 目录下,它们也会被忽略。
编辑¶
概览¶
Sublime Text具有多种多样的编辑特性。本主题只简单展示其中的几种。
多重选择¶
多重选择特性让你可以高效的在文档中进行批量修改。任何对这个特性的赞誉都不为过。接下来我们就展示 这么说的原因:
首先选中一些文本,然后按 Ctrl + D
的组合键来 添加更多 实例。如果你想 跳过当前实例,
可以按 Ctrl + K, Ctrl + D
。
如果你按键太快,导致误添加了一个实例,可以用 Ctrl + U
来 取消 对当前实例的选择。
把多重选择的内容扩展到行¶
使用 Ctrl + L
可以把多重选择的内容从单词扩展到整行。使用 Ctrl + Shift + L
可以把
选中的多行文本分成多个独立的行。
(译者注:这里多个独立的行指的是每行末尾都有单独的光标。平时选中多行文字之后只会有一个光标,这
时按 Ctrl + Shift + L
后,每一行末尾都有一个光标,可以按左方向键查看效果。这种选择适用
于在 每行 都添加/删除相同的内容)
你可以复制多重选择的行到一个单独的缓冲区,在那里编辑他们,并将编辑后的结果贴回到第一个缓冲区。
文本选择的其他方法¶
文本选择的方法很多,可以在 Selection 菜单下找到所有可能的选项。下面举几个例子:
- 选择子单词 (
Alt + Shift + <arrow>
) - 添加对选中文字周围括号的选择 (
Ctrl + Shift + M
) - 添加对选中文字缩进空格的选择 (
Ctrl + Shift + J
) - 添加对选中文字当前域的选择 (
Ctrl + Shift + Space
)
交换位置¶
需要调换两个字母甚至两个单词的位置?试试 Ctrl + T
吧。
其他内容¶
在 Edit, Selection, Find 和 Goto 菜单中可以找到很多好用的编辑工具。平常 你可能只需要其中的部分功能,当你遇到问题的是后看看这些菜单项,也许其他功能能够帮助你解决问题。
构建系统(批处理)¶
Build systems let you run your files through external programs like make, tidy, interpreters, etc. 通过构建系统,你能够使用像 make, tidy 这样的外部程序以及各种解释器 来运行你的文件。
Executables called from build systems must be in your PATH
. For more
information about making sure the PATH
seen by Sublime Text is set
correctly, see troubleshooting-build-systems.
在构建系统中调用的外部可执行程序一定要能够通过 PATH
环境变量找到。请参考 构建系统常见问题
章节来了解有关如何正确设置 PATH
环境变量的更多信息。
File Format 文件格式 ===========
Build systems are JSON files and have the extension .sublime-build. 构建系统是以 .sublime-build 作为文件扩展名的JSON文件。
Example 示例 ——-
Here’s an example of a build system: 下面是构建系统的一个小例子:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
cmd
Required. This option contains the actual command line to be executed:: 必填内容。这个选项的内容是实际执行的命令行语句:
python -u /path/to/current/file.ext
file_regex
- A Perl-style regular expression to capture error information out of the
external program’s output. This information is then used to help you
navigate through error instances with
F4
. 存放一段用于捕获外部程序输出的错误信息的Perl风格的正则表达式。这部分信息用于帮助你在不同 的错误实例之间使用F4
快捷键进行跳转。 selector
- If the Tools | Build System | Automatic option is set, Sublime Text
will automatically find the corresponding build system for the active file
by matching
selector
to the file’s scope. 如果你勾选了 Tools | Build System | Automatic 选项,Sublime Text会自动从构建 系统中通过selector
选项找到适合当前文件的构建方式。
In addition to options, you can also use some variables in build systems, like
we have done above with $file
, which expands to the the active buffer’s
file name.
除了这些选项,在构建系统中还可以使用一些变量,例如在前面使用的 $file
变量,就能自动扩充为
当前缓冲区对应的文件名。
Where to Store Build Systems 构建系统存储在哪里 ============================
Build systems must be located somewhere under the Packages folder (e. g. Packages/User). Many packages include their own build systems. 构建系统必须被放在 包组 文件夹下面的某个位置(例如 Packages/User)。许多包都含有它们自己 的构建系统。
Running Build Systems 运行构建系统 =====================
Build systems can be run by pressing F7
or from Tools | Build.
可以使用 F7
快捷键来运行构建系统,也可以从 Tools | Build 菜单中运行。
See also
- Reference for build systems
- Complete documentation on all available options, variables, etc.
更多信息请参考
- 构建系统参考文档
- 记录所有可用选项、变量的完整文档。
文件导航与文件管理¶
随意跳转¶
Goto Anything lets you navigate files swiftly. Open it with Ctrl+P
.
As you type into the input area, names of open files and files in open
directories will be searched, and a preview of the best match will be shown.
This preview is transient, that is, it won’t become the actual active buffer
until you perform some operation on it. Transient views go away when you press
Esc
. You will find transient views in other situations. They are like
ghosts or something.
“随意跳转” 可以让你方便的在文件之间切换,使用 Ctrl+P
启动该功能。你在输入栏输入,ST则会
对已经打开的文件或者目录进行搜索,并给出匹配最佳的搜索结果的预览。如果你不进行任何操作,将不会
真正加载这些文件。可以按:kbd:`Esc`取消预览界面。快捷预览界面形似鬼魅,你在使用ST的其他功能时也会遇到哦。
Goto Anything lives up to its name –there’s more to it than locating files: “随意跳转”正如其名,其功能不仅限于查找文件:
To perform a fuzzy search, append #
and then keep typing, like this:
island#treasure
还可以在输入一些内容后接上 #
再接着输入来进行 模糊搜索 ,,比如说:
island#treasure
This instructs Sublime Text to perform a fuzzy search for treasure in the
file whose name matches island. Pressing Ctrl+;
will open Goto
Anything and type #
for you.
Sublime Text会进行在所有文件名匹配 island 的文件中搜索 treasure 关键字。使用组合键
Ctrl+;
可以打开“随意跳转” 功能并输入 #
And there’s more:
To search symbols in the active buffer, press Ctrl+R
. The operator
@
can be used as explained above too.
可以通过按下组合键 Ctrl+R
在活动缓冲区中进行**符号搜索** 。操作符 @
与之前提到的用法相同。
To go to a line number, press Ctrl+G
. The operator :
can be
used as explained above too.
可以通过按下组合键 Ctrl+G`来跳转到指定的行号。操作符 `
:`` 与之前提到的用法相同。
Searching for symbols will only work for file types that have symbols defined for them.
符号搜索的功能只能在那些已经定义了符号的文件类型中使用。
侧边栏¶
The sidebar gives you an overview of your project. Files and folders added to the sidebar will be available in Goto Anything and project-wide actions. Projects and the sidebar are closely related. There’s always an open project, whether it’s implicit or explicit.
侧边栏可以提供一个项目的概览视图。添加到侧边栏的文件和目录均可以通过“随意跳转”功能访问,并且响应 项目范围内的指令。项目与侧边栏是密切相关的。不管以显式或是隐式的方式,总是有一个项目存在于侧边栏中。
To open or close the sidebar, press Ctrl+K, Ctrl+B
.
可以通过组合键:kbd:`Ctrl+K, Ctrl+B`来打开或关闭侧边栏。
The sidebar can be navigated with the arrow keys, but first you need to give
it the input focus by pressing Ctrl+0
. To return input focus to the
buffer, press Esc
. Alternatively, you can use the mouse to the same
effect, but why would you?
在侧边栏可以使用方向键来在文件间切换,但是首先需要通过按组合键:kbd:Ctrl+0 使其获得**输入焦点**。 如果希望缓冲区重新获得输入焦点,则需要按 :kbd:`Esc`键。同样,你也可以使用鼠标达到同样的效果,但是 你有必要这么做吗?
The sidebar also provides basic file management operations through the context menu.
侧边栏可以通过菜单的方式提供基本的文件管理操作。
项目¶
Projects group sets of files and directories you need to work on as a unit. Once you’ve set up your project the way that suits you by adding folders, save it and give it a name.
项目可以将你需要的文件和目录组织成一个单元。当你将项目需要的目录均添加进来以后,你可以这些保存 成一个项目并命名该项目。
To save a project, go to Project | Save Project As....
保存项目可以使用菜单中的 项目 | 项目另存为....
To quickly switch between projects, press Ctrl+Alt+P
.
可以使用组合键 Ctrl+Alt+P
在项目间快速的切换。
Project data are stored in JSON files with a .sublime-project extension. Wherever there’s a .sublime-project file, you will find an ancillary .sublime-workspace file too. The second one is used by Sublime Text and you shouldn’t edit it yourself.
项目数据保存在一些以 .sublime-project 为扩展名的JSON文件中。只要有 .sublime-project 文件,相应的都会有一个`.sublime-workspace` 文件。后者是Sublime Text使用,用户请不要进行修改。
Project files can define settings specific to that project only. More on that in the `official documentation`_.
项目文件可以根据项目进行特殊的设定。更多细节可以参考 官方文档。
You can open a project from the command line by passing the .sublime- project file as an argument.
在命令行模式下,可以通过将 .sublime-project 文件做为参数来打开整个项目。
定制Sublime Text¶
Sublime Text is highly customizable. In the topics below, we’ll explain you how you can adapt it to your needs and preferences. Sublime Text是高度可定制的。在接下来的几节中,我们将向你介绍如何根据自己的需要和偏好来定制它。
Sublime Text stores configuration data in .sublime-settings files. Flexibility comes at the price of a slightly complex system for applying settings. However, here’s a rule of thumb: Sublime Text把配置信息保存在 .sublime-settings 文件中。为了拥有较好的灵活性,作为代价, 需要一个略显繁琐的系统来管理设置项。我们先来说一条基本原则吧:
Always place your personal settings files under Packages/User to guarantee that they will take precedence over any other conflicting settings files. 个人定义的设置项文件一定要保存到 Packages/User 目录下,这样就能保证在发生冲突的时候,你定 义的文件拥有较高的优先级。
With that out of the way, let’s unveil the mysteries of how settings work to please masochistic readers. 这一点解释清楚之后,咱们就可以揭开设置项工作的具体原理了,从而满足部分喜欢受虐读者的需求。
(译者注:作者原文是masochistic,可以翻译成受虐狂,这里感觉也可以理解成求知若渴的人,求指正)
Format 文件格式 ==========
Settings files use JSON and have the .sublime-settings extension. 设置项文件是以 .sublime-settings 作为扩展名的的JSON文件。
Types of Settings 设置项文件类型 =================
The purpose of each .sublime-settings file is determined by its name. These names can be descriptive (like Preferences (Windows).sublime-settings or Minimap.sublime-settings), or they can be related to what the settings file is controlling. For example, file type settings need to carry the name of the .tmLanguage syntax definition for the file type. Thus, for the .py file type, whose syntax definition is contained in Python.tmLanguage, the corresponding settings files would be called Python.sublime-settings. 可以通过 .sublime-settings 文件的名字看出它的用途。这些文件的名字可能具有一定的描述性(例如 Preferences (Windows).sublime-settings 或者 Minimap.sublime-settings),亦或是跟 它所控制的内容有关联。以控制文件类型的设置项文件为例,命名时要求必须有与之对应的 .tmLanguage 语法定义文件。因此,对于 .py 文件类型,它的语法定义信息存放在 Python.tmLanguage 文件中, 那么对应的文件类型设置项文件就该被叫做 Python.sublime-settings 。
Also, some settings files only apply for specific platforms. This can be inferred from the file names: Preferences (Windows).sublime-settings, Preferences (Linux).sublime-settings, etc. 除此之外,某些设置文件只能作用于某个特定的平台。可以通过文件名进行推断,例如: Preferences (Windows).sublime-settings 和 Preferences (Linux).sublime-settings 。
This is important: Platform-specific settings files in the Packages/User folder are ignored. This way, you can be sure a single settings file overrides all the others. 有一点特别 重要 :存放在 Packages/User 目录中的平台相关的设置文件将被忽略。通过这种方式, 就可以保证单个设置文件内容可以覆盖其他所有设置文件的内容了。
How to Access and Edit Common Settings Files 如何访问并修改公共的设置项文件 ============================================
Unless you need very fine-grained control over settings, you can access the main configuration files through the Preferences | Settings - User and Preferences | Settings - More menu items. Editing Preferences - Settings Default isn’t a smart thing to do, because changes will be reverted with every update to the software. However, you can use that file for reference: it contains comments explaining the purpose of all available global and file type settings. 除非你对设置项有非常精确的掌控力,否则,你只需要通过 Preferences | Settings - User 和 Preferences | Settings - More 菜单项来访问主要的配置文件。编辑 Preferences - Settings Default 这个文件并不是一件明智的事情,因为每次版本升级这些修改都 将被重置。不过,你确实可以把这些文件当作一个不错的参考资料:默认设置项文件里面包含了解释所有能 为你所用的全局设置项和文件类型设置项的说明注释。
Order of Precedence of .sublime-settings Files .sublime-settings 文件的优先级顺序 ==================================================
The same settings file (such as Python.sublime-settings) can appear in multiple places. All settings defined in identically named files will be merged together and overwritten according to predefined rules. See Merging and Order of Precedence for more information. 名字相同的设置项文件(例如,都叫 Python.sublime-settings 的文件)可以在多个位置出现。以相同 名称命名的设置项文件中的内容都将按预定义的规则进行合并或者覆盖。请参考 排序与优先级顺序 这一小节以了解更多信息。
Let us remember again that any given settings file in Packages/User ultimately overrides every other settings file of the same name. 再说明一次,在 Packages/User 目录下的设置项文件拥有最高优先级,并且最终会覆盖其他同名设置项 文件中的相同内容。
In addition to settings files, Sublime Text maintains session data –settings for the particular set of files being currently edited. Session data is updated as you work on files, so if you adjust settings for a particular file in any way (mainly through API calls), they will be recorded in the session and will take precedence over any applicable .sublime-settings files. 除了设置项文件以外,Sublime Text还维护 会话 数据 —— 一些针对正在编辑的文件集所应用的设置项。 会话数据是在你编辑文件的过程中发生变化的,所以,无论你通过何种方式调整了一个特定文件的设置项 (主要是通过API调用的方式),这些设置项的变更将被记录在当前的会话中,并且将拥有比所有符合条件的 .sublime-settings 文件更高的优先级。
To check the value of a setting in effect for a particular file, use view.settings().get(<setting_name>) from the console. 如果想要检查针对特定文件当前正在发挥作用的设置项的值,可以在控制台中输入 view.settings().get(<设置项名称>) 命令。
Lastly, it’s also worth noting that some settings may be adjusted automatically
for you. Keep this is mind if you’re puzzled about some setting’s value. For
instance, this is the case for certain whitespace-related settings and the
syntax
setting.
最后需要注意的是,某些设置项的值可能会被系统自动进行调整。请记住这一点,这样一来你就能够解释某
些令你困惑的设置项内容了。举例来说,在查看某些与空格相关的设置项的值,以及某些 语法
设置项
内容的时候,就有可能遇到这种问题。
Below, you can see the order in which Sublime Text would process a hypothetical hierarchy of settings for Python files on Windows: 接下来你将看到Sublime Text是如何处理Windows平台上Python相关的设置项文件的,这里的设置项文件 目录结构是虚构的:
- Packages/Default/Preferences.sublime-settings
- Packages/Default/Preferences (Windows).sublime-settings
- Packages/User/Preferences.sublime-settings
- Packages/Python/Python.sublime-settings
- Packages/User/Python.sublime-settings
- Session data for the current file
- 当前文件的会话数据
- Auto adjusted settings
- 由系统自动调整的设置项内容
(译者注:分析下优先级,可以得到结论:全局默认项 < 平台默认项 < 用户设置项 < 语言相关的设置 < 由用户指定的语言相关的设置 < 会话数据 < 系统调整的数据)
Global Editor Settings and Global File Settings 全局编辑器设置以及全局文件设置 ===============================================
These settings are stored in Preferences.sublime-settings and Preferences (<platform>).sublime-settings files. The defaults can be found in Packages/Default. 这类全局设置项内容一般被保存在名为 Preferences.sublime-settings 和 Preferences (<平台名称>).sublime-settings 的文件中。默认的全局设置项存放在 Packages/Default 目录中。
Valid names for <platform> are Windows
, Linux
, OSX
.
上面所说的 <平台名称> 可能是 Windows
, Linux
或者 OSX
。
File Type Settings 文件类型设置项 ==================
If you want to target a specific file type, name the .sublime-settings file after the file type’s syntax definition. For example, if our syntax definition was called Python.tmLanguage, we’d need to call our settings file Python.sublime-settings. 如果你想针对某个特定的文件类型进行一些配置,那请根据这个文件类型的语法定义文件名称来对应的命名 .sublime-settings 文件。举例来说,如果我们的语法定义文件叫 Python.tmLanguage ,那么 设置项文件的名称就应该叫 Python.sublime-settings 。
Settings files for specific file types usually live in packages, like Packages/Python, but there can be multiple settings files for the same file type in separate locations. 通常情况下,某个特定文件类型的设置项信息一般存放在包组文件夹的一个目录中,例如 Packages/Python, 但是,与同一个文件类型相关的多个设置项文件也有可能被存放在不同的位置。
Similarly to global settings, one can establish platform-specific settings for file types. For example, Python (Linux).sublime-settings would only be consulted under Linux. 与全局设置项类似,也可以为文件类型设置项信息创建平台相关的内容。例如只有在Linux平台下,保存在 Python (Linux).sublime-settings 中的设置项内容才会被系统考虑。
Also, let us emphasize that under Pakages/User only Python.sublime-settings would be read, but not any Python (<platform>).sublime-settings variant. 需要特别指出的一点是,在 Packages/User 目录下,只有 Python.sublime-settings 文件会被 加载,所有以 Python (<平台名称>).sublime-settings 命名的平台相关的变种都不会被考虑。
Regardless of its location, any file-type-specific settings file has precedence over every global settings file affecting file types. 不管文件类型设置项信息保存在哪里,它拥有比保存在全局设置项文件中的、影响文件类型的设置项都高的 优先级。
Where to Store User Settings (Once Again) (再说一次)用户指定的设置项信息应该保存到哪里 ============================================
Whenever you want to save settings, especially if they should be preserved between software updates, place the corresponding .sublime-settings file in Packages/User. 无论何时,当你想要保存一些设置的时候,尤其是那些在软件升级前后应该被保留的设置,就把它们保存在 Packages/User 目录下的对应 .sublime-settings 文件中吧。
更多信息请参考
- Reference for key bindings
- Complete documentation on key bindings.
- 键位绑定参考文档
- 有关键位绑定的完整文档。
Key bindings let you map sequences of key presses to actions. 键位绑定使得你能够将按键与动作进行映射。
File Format 文件格式 ===========
Key bindings are defined in JSON and stored in .sublime-keymap
files. In
order to integrate better with each platform, there are separate key map files
for Linux, OSX and Windows. Only key maps for the corresponding platform will
be loaded.
键位绑定是以 .sublime-keymap
作为扩展名的JSON文件。为了让键位能够更好的与各平台融合,系统为
Linux,OSX以及Windows平台分别提供了不同的文件。只有与当前系统相符的键位映射文件才会生效。
Example 示例 ***
Here’s an excerpt from the default key map for Windows:: 下面这段代码是从Windows平台默认的按键映射文件中截取出来的:
[
{ "keys": ["ctrl+shift+n"], "command": "new_window" },
{ "keys": ["ctrl+o"], "command": "prompt_open_file" }
]
Defining and Overriding Key Bindings 定义与重载键位绑定 ====================================
Sublime Text ships with a default key map (e. g.
Packages/Default/Default (Windows).sublime-keymap)
. In order to
override key bindings defined there or add new ones, you can store them in aseparate
key map with a higher precedence, for example
Packages/User/Default (Windows).sublime-keymap
.
Sublime Text自带一套默认的键位绑定(一般对应这个文件:
Packages/Default/Default (Windows).sublime-keymap)
)。如果你想重载其中的部分键位
或者添加新的键位绑定,你可以在具有更高文件优先级的位置重新存储一个文件,例如
Packages/User/Default (Windows).sublime-keymap
。
See Merging and Order of Precedence for more information about how Sublime Text sorts files for merging. 请参考 排序与优先级顺序 来了解Sublime Text中关于文件优先级以及文件合并的更多信息。
Advanced Key Bindings 高级键位绑定 =====================
Simple key bindings consist of a key combination and a command to be executed. However, there are more complex syntaxes to pass arguments and provide contextual awareness. 对于简单的键位绑定,就是一个键位组合对应一个命令。除此之外,还有一些传递参数和上下文信息的复杂语法。
Passing Arguments 参数传递 *************
Arguments are specified in the args
key::
通过 args
键可以指定需要的参数:
{ "keys": ["shift+enter"], "command": "insert", "args": {"characters": "\n"} }
Here, \n
is passed to the insert
command when you press Shift+Enter
.
在这个例子中当你按下 Shift+Enter
的时候, \n
将会作为参数传递给 insert
命令。
Contexts 上下文 ****
Contexts determine when a given key binding will be enabled based on the caret’s position or some other state. 利用上下文,可以通过插入符的位置及其他状态信息来决定某种键位组合是否可以发挥作用。
{ "keys": ["escape"], "command": "clear_fields", "context":
[
{ "key": "has_next_field", "operator": "equal", "operand": true }
]
}
This key binding translates to clear snippet fields and resume normal editing
if there is a next field available. Thus, pressing ESC
when you are not
cycling through snippet fields will not trigger this key binding (however,
something else might occur instead if ESC
happens to be bound to a
different context too —and that’s likely to be the case for ESC
).
这段代码的作用是 当有下一个可用域的时候就清空当前代码片段,并返回正常编辑模式 。因此,当你
没有在代码域中循环切换的时候,按下 ESC
键就 不会 触发这个按键绑定(然而,如果 ESC
恰巧与另外的上下文进行了绑定,那么那个动作仍然会被触发——事实上,对于 ESC
来说,这种情况
并不少见)。
菜单项¶
No documenation available about this topic. 关于这个主题没有任何可用文档。
But here’s Bruce Lee screaming. 但是,可以参考 李小龙的嘶吼。
Extending Sublime Text¶
As it can be seen from the long list of topics below, Sublime Text is a very extensible editor.
Commands¶
Commands are ubiquitous in Sublime Text: key bindings, menu items and macros all work through the command system. They are found in other places too.
命令在Sublime Text中无处不在:按键绑定,菜单项包括宏等它们都是工作在命令系统里的。因此,命令随处可见。
Some commands are implemented in the editor’s core, but many of them are provided as python plugins. Every command can be called from a python plugin.
一些命令可以通过编辑器内核接口来实现,但是更多的是作为python的插件来提供。任何命令都可以通过python插件来调用。
Command Dispatching¶
Normally, commands are bound to the application object, a window object or a view object. Window objects, however, will dispatch commands based on input focus, so you can issue a view command from a window object and the correct view instance will be found for you.
通常,命令都绑定在应用对象,窗口对象或者视图对象里。不过,窗口对象根据输入焦点来分发命令,因此你可以通过窗口对象发起一个 命令并且会为你返回一个正确的视图实例。
Anatomy of a Command¶
Commands have a name separated by underscores, like hot_exit
and can take
a dictionary of arguments whose keys must be strings and whose values must
be JSON types. Here’s a few examples of commands run from the Python console:
命令名通常被下划线所分割,就像``hot_exit``,而且是一个以字符串为关键字JSON类型为值的字典。下面是一些运行在python控制台下 的命令例子:
view.run_command("goto_line", {"line": 10})
view.run_command('insert_snippet', {"contents": "<$SELECTION>"})
view.window().run_command("prompt_select_project")
See also
- Reference for commands
- Command reference.
Macros¶
Macros are a basic automation facility consisting in sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation.
Macro files are JSON files with the extension .sublime-macro
. Sublime Text
ships with a few macros providing core functionality, such as line and word
deletion. You can find these under Tools | Macros.
How to Record Macros¶
To start recording a macro, press Ctrl+q
and subsequently execute the
desired steps one by one. When you’re done, press Ctrl+q
again to stop
the macro recorder. Your new macro won’t be saved to a file, but kept in the
macro buffer instead. You will now be able to run the recorded macro by
pressing Ctrl+Shift+q
or save it to a file by selecting
Tools | Save macro….
Note that the macro buffer will only remember the macro recorded latest. Also, recorded macros only capture commands sent to the buffer: window level commands, such as creating a new file, will be ignored.
How to Edit Macros¶
Alternatively to recording a macro, you can edit it by hand. Save a new file
with the extension .sublime-macro
under PackagesUser
and add
commands to it. This is how a macro file looks like:
[
{"command": "move_to", "args": {"to": "hardeol"}},
{"command": "insert", "args": {"characters": "\n"}}
]
See the ../core/commands
section for more information on commands.
If you’re editing a macro by hand, you need to escape quotation marks,
blank spaces and backslashes by preceding them with \
.
Where to Store Macros¶
Macro files can be stored in any package folder, and they will show up under Tools | Macros | <PackageName>.
Snippets 代码片段 ========
Whether you are coding or writing the next vampire best-seller, you’re likely to need certain short fragments of text again and again. Use snippets to save yourself tedious typing. Snippets are smart templates that will insert text for you and adapt it to their context. 无论你是在敲代码还是撰写你的大作,你都会一遍一遍地写到一些小的重复片段。使用代码片段 保存这些冗长的部分。是一种很聪明的模板,它会根据你输入的上下文帮助你添加文本。
To create a new snippet, select Tools | New Snippet…. Sublime Text will present you with an skeleton for a new snippet. 要新建一个代码片段,选择目录 Tools | New Snippet…。Sublime Text会介绍给你一个 框架来新建一个代码片段。
Snippets can be stored under any package’s folder, but to keep it simple while
you’re learning, you can save them to your Packages/User
folder.
代码片段可以存储在任何一个包文件下,为了在你学习时方便,你可以将其保存在你的
目录``Packages/User``下。
Snippets File Format 代码片段文件格式 ****************
Snippets typically live in a Sublime Text package. They are simplified XML files
with the extension sublime-snippet
. For instance, you could have a
greeting.sublime-snippet
inside an Email
package.
代码片段一般保存在Sublime Text的包里。这里使用了扩展``sublime-snippet``简化XML的
文件。比如,你可以在包``Email``里保存``greeting.sublime-snippet``。
The structure of a typical snippet is as follows (including the default hints Sublime Text inserts for your convenience): 典型的代码片段的结构如下(包括Sublime Text为方便你使用添加的默认提示):
<snippet>
<content><![CDATA[Type your snippet here]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>xyzzy</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.python</scope>
<!-- Optional: Description to show in the menu -->
<description>My Fancy Snippet</description>
</snippet>
The snippet
element contains all the information Sublime Text needs in order
to know what to insert, whether to insert it and when. Let’s see all of
these parts in turn.
元素``snippet``包括Sublime Text需要的所有信息,以获取需要添加什么,是否添加以及
什么情况下。接下来我们看一下每一个部分。
content
The actual snippet. Snippets can range from simple to fairly complex templates. We’ll look at examples of both later. 实际的代码片段。代码片段可以包括从最简单到相当复杂的模板。接下来,我们会看到 它们的例子。
Keep the following in mind when writing your own snippets: 在编写你自己的代码片段时,你要记住以下内容:
- If you want the get a literal
$
, you have to escape it like this:\$
. - 如果你想输入``$``,你需要按照方式如下转义:
\$
。 - When writing a snippet that contains indentation, always use tabs. The
tabs will be transformed into spaces when the snippet is inserted if the
option
translateTabsToSpaces
is set totrue
. - 如果代码片段包括缩进,一般使用tab。选项``translateTabsToSpaces``为真时, 代码片段添加的tab会自动转换成空格。
The
content
must be included in a<![CDATA[…]]>
section. Snippets won’t work if you don’t do this! 标签``content``必须包含在块``<![CDATA[…]]>``中。如果不这么写,代码片段 可不好用哦~- If you want the get a literal
tabTrigger
Defines the sequence of keys you will press to insert this snippet. The snippet will kick in as soon as you hit the
Tab
key after typing this sequence. 定义你在需要添加代码片段时按下的按键序列。在你按下按键序列后,再按下键盘上的`Tab` 键,代码片段才会生效。A tab trigger is an implicit key binding. tab触发器是一个隐式的按键绑定。
scope
- Scope selector determining the context where the snippet will be active. See Scopes for more information. 作用域选择子决定了代码片段在哪个范围内生效。 详情请看:ref:scopes-and-scope-selectors。
description
- Used when showing the snippet in the Snippets menu. If not present, Sublime Text defaults to the name of the snippet. 在代码片段目录显示代码片段时使用。如果没显示,Sublime Text默认使用代码片段名。
With this information, you can start writing your own snippets as described in the next sections. 根据之前的信息,现在可以开始按照下面的章节写自己的代码片段了。
- 注释:
- In the interest of brevity, we’re only including the
content
element’s text in examples unless otherwise noted. 为了简洁,除非另外说明,这里的例子中只包含``content``元素。
Snippet Features 代码片段特性 ************
Environment Variables 环境变量 ———————
Snippets have access to contextual information in the form of environment variables. Sublime Text sets the values of the variables listed below automatically. 代码片段根据环境变量获得上下文信息。Sublime Text会自动设定下面所述的变量值。
You can also add your own variables to provide extra information. These custom
variables are defined in .sublime-options
files.
你也可以加上自己的变量来提供额外的信息。这些自定义变量都在文件``.sublime-options``
中定义。
$PARAM1, $PARAM2… | Arguments passed to the insert_snippet command. (Not covered here.) |
$PARAM1, $PARAM2… | 传递给 insert_snippet 命令的各个参数。 |
$SELECTION | The text that was selected when the snippet was triggered. |
$SELECTION | 代码片段被触发的时候选中的文本内容。 |
$TM_CURRENT_LINE | Content of the line the cursor was in when the snippet was triggered. |
$TM_CURRENT_LINE | 代码片段被触发的时候光标所在行的内容。 |
$TM_CURRENT_WORD | Current word under the cursor when the snippet was triggered. |
$TM_CURRENT_WORD | 代码片段被触发的时候光标所在的单词。 |
$TM_FILENAME | File name of the file being edited including extension. |
$TM_FILENAME | 正在编辑的文件名称,包含文件扩展名。 |
$TM_FILEPATH | File path to the file being edited. |
$TM_FILEPATH | 正在编辑的文件的文件路径。 |
$TM_FULLNAME | User’s user name. |
$TM_FULLNAME | 用户的用户名。 |
$TM_LINE_INDEX | Column the snippet is being inserted at, 0 based. |
$TM_LINE_INDEX | 插入代码片段的列的位置,位置是从0开始计数的。 |
$TM_LINE_NUMBER | Row the snippet is being inserted at, 1 based. |
$TM_LINE_NUMBER | 插入代码片段的行的位置,位置是从1开始计数的。 |
$TM_SELECTED_TEXT | An alias for $SELECTION. |
$TM_SELECTED_TEXT | 与 $SELECTION 是等价的。 |
$TM_SOFT_TABS | YES if translate_tabs_to_spaces is true, otherwise NO . |
$TM_SOFT_TABS | 当 translateTabsToSpaces 选项是真的时候,值是 YES ,否则为 NO 。 |
$TM_TAB_SIZE | Spaces per-tab (controlled by the tab_size option). |
$TM_TAB_SIZE | tab对应的空格数(受 tabSize 选项的控制)。 |
Let’s see a simple example of a snippet using variables: 接下来,我们看一个使用变量的简单的例子:
====================================
USER NAME: $TM_FULLNAME
FILE NAME: $TM_FILENAME
TAB SIZE: $TM_TAB_SIZE
SOFT TABS: $TM_SOFT_TABS
====================================
# Output:
====================================
USER NAME: guillermo
FILE NAME: test.txt
TAB SIZE: 4
SOFT TABS: YES
====================================
Fields 字域 ——
With the help of field markers, you can cycle through positions within the
snippet by pressing the Tab
key. Fields are used to walk you through the
customization of a snippet once it’s been inserted.
有了字域标记,你可以通过在代码片段中的某一位置按下键盘的`Tab`键来循环。一旦添加
了代码片段,字域可以通过自定义的信息帮助你走查。
First Name: $1
Second Name: $2
Address: $3
In the example above, the cursor will jump to $1
if you press Tab
once.
If you press Tab
a second time, it will advance to $2
, etc. You can also
move backwards in the series with Shift+Tab
. If you press Tab
after the
highest tab stop, Sublime Text will place the cursor at the end of the snippet’s
content so that you can resume normal editing.
上面的例子中,当你按下一次键盘`Tab`键时,光标会跳转到``$1``。当你连续按下`Tab`两次是,会跳转
到``$2``等等。你也可以按下键盘的`Shift+Tab`键后退。如果你在最高制表位按下`Tab`键,Sublime Text
会将光标停留在代码片段内容的末尾,以便你可以重新开始编辑。
If you want to control where the exit point should be, use the $0
mark.
如果你想控制退出点的位置,你可以使用``$0``标记。
You can break out of the field cycle any time by pressing Esc
.
你可以通过按下键盘的`Esc`键跳出字域循环。
Mirrored Fields 镜像字域 —————
Identical field markers mirror each other: when you edit the first one, the rest will be populated with the same value in real time. 相同的字域标记会相互映射:当你输入了第一个,剩下的立刻填充相同的值。
First Name: $1
Second Name: $2
Address: $3
User name: $1
In this example, “User name” will be filled out with the same value as “First Name”. 这个例子中,”User name”会填充”First Name”的值。
Place Holders 占位符 ————-
By expanding the field syntax a little bit, you can define default values for a field. Place holders are useful when there’s a general case for your snippet but you still want to keep its customization convenient. 通过扩展一些字域的语法,你可以为每一个域设定默认值。如果在你的代码片段里需要设定 一个一般的情况,你又希望不失去自定义的便捷,占位符是非常有用的。
First Name: ${1:Guillermo}
Second Name: ${2:López}
Address: ${3:Main Street 1234}
User name: $1
Variables can be used as place holders: 变量也可以用作占位符:
First Name: ${1:Guillermo}
Second Name: ${2:López}
Address: ${3:Main Street 1234}
User name: ${4:$TM_FULLNAME}
And you can nest place holders within other place holders too: 你也可以在其他的占位符里嵌套占位符:
Test: ${1:Nested ${2:Placeholder}}
Substitutions 替换 ————-
In addition to the place holder syntax, tab stops can specify more complex operations with substitutions. Use substitutions to dynamically generate text based on a mirrored tab stop. 除了占位符语法,制表符的设置可以使用替换设定更多复杂的操作。使用替换可以根据映射的制表符 设置动态地生成文本。
The substitution syntax has the following syntaxes: 替换的语法如下:
${var_name/regex/format_string/}
${var_name/regex/format_string/options}
- var_name
- The variable name: 1, 2, 3… 变量名:1, 2, 3…
- regex
- Perl-style regular expression: See the Boost library reference for regular expressions. Perl风格的正则表达式:关于`正则表达式 <http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html>`_ ,请参考Boost库的文档。
- format_string
- See the Boost library reference for format strings. 参考Boost库文档的 格式字符串 内容。
- options
Optional. May be any of the following: 可选的。可以选择下面的任何一个:
- i
- Case-insensitive regex. 忽略大小写敏感的正则。
- g
- Replace all occurrences of
regex
. 替换所有匹配regex
的内容。 - m
- Don’t ignore newlines in the string. 在字符串中不要忽略换行符。
With substitutions you can, for instance, underline text effortlessly: 有了替换,比如,你可以如此简单地添加文本下划线:
Original: ${1:Hey, Joe!}
Transformation: ${1/./=/g}
# Output:
Original: Hey, Joe!
Transformation: =========
Completions¶
See also
- Reference for completions
- Complete documentation on all available options.
- Sublime Text Documentation
- Official documentation on this topic.
Completions provide functionality in the spirit of IDEs to suggest terms and
insert snippets. Completions work through the completions list or, optionally,
by pressing Tab
.
Note that completions in the broader sense of words that Sublime Text will look up and insert for you are not limited to completions files, because other sources contribute to the list of words to be completed, namely:
- Snippets
- API-injected completions
- Buffer contents
However, .sublime-completions
files are the most explicit way Sublime Text
provides you to feed it completions. This topic deals with the creation of
.sublime-completions
files as well as with the interaction between all
sources for completions.
File Format¶
Completions are JSON files with the .sublime-completions
extension.
Entries in completions files can contain either snippets or plain strings.
Example¶
Here’s an excerpt from the HTML completions:
{
"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
"completions":
[
{ "trigger": "a", "contents": "<a href=\"$1\">$0</a>" },
{ "trigger": "abbr", "contents": "<abbr>$0</abbr>" },
{ "trigger": "acronym", "contents": "<acronym>$0</acronym>" }
]
}
scope
- Determines when the completions list will be populated with this list of completions. See Scopes for more information.
In the example above, we’ve used trigger-based completions only, but completions files support simple completions too. Simple completions are just plain strings. Expanding our example with a few simple completions, we’d end up with a list like so:
{
"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
"completions":
[
{ "trigger": "a", "contents": "<a href=\"$1\">$0</a>" },
{ "trigger": "abbr", "contents": "<abbr>$0</abbr>" },
{ "trigger": "acronym", "contents": "<acronym>$0</acronym>" },
"ninja",
"robot",
"pizza"
]
}
Sources for Completions¶
Completions not only originate in .sublime-completions
files. This is the
exhaustive list of sources for completions:
- Snippets
- API-injected completions
.sublime-completions
files- Words in buffer
Priority of Sources for Completions¶
This is the order in which completions are prioritized:
- Snippets
- API-injected completions
.sublime-completions
files- Words in buffer
Snippets will always win if the current prefix matches their tab trigger exactly. For the rest of the completions sources, a fuzzy match is performed. Also, snippets will always lose against a fuzzy match. Note that this is only relevant if the completion is going to be inserted automatically. When the completions list is shown, snippets will be listed along the other items, even if the prefix only partially matches the snippets’ tab triggers.
How to Use Completions¶
There are two methods to use completions, and although the priority given to completions when screening them is always the same, there is a difference in the result that will be explained below.
Completions can be inserted in two ways:
- through the completions list (
Ctrl+spacebar
);- by pressing
Tab
.
The Completions List¶
The completions list (Ctrl+spacebar
) may work in two ways: by bringing
up a list of suggested words to be completed, or by inserting the best match
directly.
If the choice of best completion is ambiguous, an interactive list will be
presented to the user, who will have to select an item himself. Unlike other
items, snippets in this list are displayed in this format:
<tab_trigger> : <name>
, where <tab_trigger>
and <name>
are
variable.
The completion with Ctrl+spacebar
will only be automatic if the list of
completion candidates can be narrowed down to one unambiguous choice given the
current prefix.
Tab
-completed Completions¶
If you want to be able to tab-complete completions, the setting
tab_completion
must be set to true
. By default, tab_completion
is
set to true
. Snippet tab-completion is unaffected by this setting: they
will always be completed according to their tab trigger.
With tab_completion
enabled, completion of items is always automatic, which
means that, unlike in the case of the completions list, Sublime Text will
always make a decision for you. The rules to select the best completion are the
same as above, but in case of ambiguity, Sublime Text will still insert the
item deemed most suitable.
Inserting a Literal Tab Character¶
When tab_completion
is enabled, you can press Shift+Tab
to insert a
literal tab character.
??????Ϣ??ο???
- Reference for Command Palette
- Complete documentation on the command palette options.
- ???????ο??ĵ?
- ?й????????ѡ????????ĵ???
Overview¶
The command palette is an interactive list bound to Ctrl+Shift+P
whose
purpose is to execute commands. The command palette is fed entries with
commands files. Usually, commands that don’t warrant creating a key binding of
their own are good candidates for inclusion in a .sublime-commands
file.
?????????һ???????? Ctrl+Shift+P ?Ľ????б??Ŀ??????ִ????????????
???????ļ????ϵ??ͨ?????????֤????һ?????????????? .sublime-commands
????ΪһЩ?ܺõĺ?ѡ??
File Format (Commands Files) ?ļ???ʽ???????ļ??? ============================
Commands files use JSON and have the .sublime-commands
extension.
?????ļ?ʹ??JSON????????һ?? .sublime-commands
????չ??
Here’s an excerpt from Packages/Default/Default.sublime-commands
::
?????????? Packages/Default/Default.sublime-commands
??ʵ??:
[
{ "caption": "Project: Save As", "command": "save_project_as" },
{ "caption": "Project: Close", "command": "close_project" },
{ "caption": "Project: Add Folder", "command": "prompt_add_folder" },
{ "caption": "Preferences: Default File Settings", "command": "open_file", "args": {"file": "${packages}/Default/Base File.sublime-settings"} },
{ "caption": "Preferences: User File Settings", "command": "open_file", "args": {"file": "${packages}/User/Base File.sublime-settings"} },
{ "caption": "Preferences: Default Global Settings", "command": "open_file", "args": {"file": "${packages}/Default/Global.sublime-settings"} },
{ "caption": "Preferences: User Global Settings", "command": "open_file", "args": {"file": "${packages}/User/Global.sublime-settings"} },
{ "caption": "Preferences: Browse Packages", "command": "open_dir", "args": {"dir": "$packages"} }
]
caption
- Text for display in the command palette. ??ʾ??????????еı???.
command
- Command to be executed. ??ִ?е?????.
args
- Arguments to pass to
command
. ????command
?IJ?????
How to Use the Command Palette ???ʹ????????? ==============================
- Press
Ctrl+Shift+P
- ???¼??̵?`Ctrl+Shift+P`
- Select command
- ѡ??????
The command palette filters entries by context, so whenever you open it, you
won’t always see all the commands defined in every .sublime-commands
file.
???????ͨ???ı?????ѡ?????????ʲôʱ????㶼???ῴ??ÿһ?? .sublime-commands
?ļ??????????
Syntax Definitions¶
Syntax definitions make Sublime Text aware of programming and markup languages. Most noticeably, they work together with colors to provide syntax highlighting. Syntax definitions define scopes in a buffer that divide the text in named regions. Several editing features in Sublime Text make extensive use of this fine-grained contextual information.
Essentially, syntax definitions consist of regular expressions used to find text, and more or less arbitrary, dot-separated strings called scopes or scope names. For every occurrence of a given regular expression, Sublime Text gives the matching text its corresponding scope name.
Prerequisites¶
In order to follow this tutorial, you will need to install AAAPackageDev, a package intended to ease the creation of new syntax definitions for Sublime Text. AAAPackageDev lives on a public Mercurial repository at Bitbucket.
Download the latest .sublime-package
file and install it as described in
Installation of .sublime-package Files.
File format¶
Sublime uses property list files (Plist) to store syntax definitions. Because editing XML files is a cumbersome task, though, we’ll be using JSON instead and converting it to Plist afterwards. This is where the AAAPackageDev package mentioned above comes in.
Note
If you experience unexpected errors during this tutorial, chances are AAAPackageDev is to blame. Don’t immediately think your problem is due to a bug in Sublime Text.
By all means, do edit the Plist files by hand if you prefer to work in XML, but keep always in mind the differing needs with regards to escape sequences, etc.
Scopes¶
Scopes are a key concept in Sublime Text. Essentially, they are named text regions in a buffer. They don’t do anything by themselves, but Sublime Text peeks at them when it needs contextual information.
For instance, when you trigger a snippet, Sublime Text checks the scope the snippet’s bound to and looks at the caret’s position in the file. If the caret’s current scope matches the snippet’s scope selector, Sublime Text fires the snippet off. Otherwise, nothing happens.
Scopes can be nested to allow for a high degree of granularity. You can drill down the hierarchy very much like with CSS selectors. For instance, thanks to scope selectors, you could have a key binding activated only within single quoted strings in python source code, but not inside single quoted strings in any other language.
Sublime Text implements the idea of scopes from Texmate, a text editor for Mac. Textmate’s online manual contains further information about scope selectors that’s useful for Sublime Text users too.
How Syntax Definitions Work¶
At their core, syntax definitions are arrays of regular expressions paired with scope names. Sublime Text will try to match these patterns against a buffer’s text and attach the corresponding scope name to all occurrences. These pairs of regular expressions and scope names are known as rules.
Rules are applied in order, one line at a time. Each rule consumes the matched text region, which will therefore be excluded from the next rule’s matching attempt (save for a few exceptions). In practical terms, this means that you should take care to go from more specific rules to more general ones when you create a new syntax definition. Otherwise, a greedy regular expression might swallow parts you’d like to have styled differently.
Syntax definitions from separate files can be combined, and they can be recursively applied too.
Your First Syntax Definition¶
By way of example, let’s create a syntax definition for Sublime Text snippets.
We’ll be styling the actual snippet content, not the .sublime-snippet
file.
Note
Since syntax definitions are primarily used to enable syntax highlighting, we’ll use to style as in to break down a source code file into scopes. Keep in mind, however, that colors are a different thing to syntax definitions and that scopes have many more uses besides syntax highlighting.
These are the elements we want to style in a snippet:
- Variables (
$PARAM1
,$USER_NAME
…)- Simple fields (
$0
,$1
…)- Complex fields with place holders (
${1:Hello}
)- Nested fields (
${1:Hello ${2:World}!}
)- Escape sequences (
\\$
,\\<
…)- Illegal sequences (
$
,<
…)
Note
Before continuing, make sure you’ve installed the AAAPackageDev package as explained further above.
Creating A New Syntax Definition¶
To create a new syntax definition, follow these steps:
- Go to Tools | Packages | Package Development | New Syntax Definition
- Save the new file to your
Packages/User
folder as a.JSON-tmLanguage
file.
You should now see a file like this:
{ "name": "Syntax Name",
"scopeName": "source.syntax_name",
"fileTypes": [""],
"patterns": [
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
Let’s examine now the key elements.
uuid
- Located at the end, this is a unique identifier for this syntax definition. Each new syntax definition gets its own uuid. Don’t modify them.
name
- The name that Sublime Text will display in the syntax definition drop-down list Use a short, descriptive name. Typically, you will be using the programming language’s name you are creating the syntax definition for.
scopeName
- The top level scope for this syntax definition. It takes the form
source.<lang_name>
ortext.<lang_name>
. For programming languages, usesource
. For markup and everything else,text
. fileTypes
- This is a list of file extensions. When opening files of these types, Sublime Text will automatically activate this syntax definition for them.
patterns
- Container for your patterns.
For our example, fill in the template with the following information:
{ "name": "Sublime Snippet (Raw)",
"scopeName": "source.ssraw",
"fileTypes": ["ssraw"],
"patterns": [
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
Note
JSON is a very strict format, so make sure to get all the commas and quotes right. If the conversion to Plist fails, take a look at the output panel for more information on the error. We’ll explain later how to convert a syntax definition in JSON to Plist.
Analyzing Patterns¶
The patterns
array can contain several types of elements. We’ll look at some
of them in the following sections. If you want to learn more about patterns,
refer to Textmate’s online manual.
Matches¶
They take this form:
{ "match": "[Mm]y \s+[Rr]egex",
"name": "string.ssraw",
"comment": "This comment is optional."
}
match
- A regular expression Sublime Text will use to try and find matches.
name
- Name of the scope that should be applied to the occurrences of
match
. comment
- An optional comment about this pattern.
Let’s go back to our example. Make it look like this:
{ "name": "Sublime Snippet (Raw)",
"scopeName": "source.ssraw",
"fileTypes": ["ssraw"],
"patterns": [
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
That is, make sure the patterns
array is empty.
Now we can begin to add our rules for Sublime snippets. Let’s start with simple fields. These could be matched with a regex like so:
\$[0-9]+
# or...
\$\d+
However, because we’re writing our regex in JSON, we need to factor in JSON’s own escaping rules. Thus, our previous example becomes:
\\$\\d+
With escaping out of the way, we can build our pattern like this:
{ "match": "\\$\\d+",
"name": "keyword.source.ssraw",
"comment": "Tab stops like $1, $2..."
}
And we can add it to our syntax definition too:
{ "name": "Sublime Snippet (Raw)",
"scopeName": "source.ssraw",
"fileTypes": ["ssraw"],
"patterns": [
{ "match": "\\$\\d+",
"name": "keyword.source.ssraw",
"comment": "Tab stops like $1, $2..."
}
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
We’re now ready to convert our file to .tmLanguage
. Syntax definitions use
Textmate’s .tmLanguage
extension for compatibility reasons. As explained further
above, they are simply XML files in the Plist format.
Follow these steps to perform the conversion:
- Select
Json to tmLanguage
in Tools | Build System- Press
F7
- A
.tmLanguage
file will be generated for you in the same folder as your.JSON-tmLanguage
file- Sublime Text will reload the changes to the syntax definition
You have now created your first syntax definition. Next, open a new file and save
it with the extension .ssraw
. The buffer’s syntax name should switch to
“Sublime Snippet (Raw)” automatically, and you should get syntax highlighting if
you type $1
or any other simple snippet field.
Let’s proceed to creating another rule for environment variables.
{ "match": "\\$[A-Za-z][A-Za-z0-9_]+",
"name": "keyword.source.ssraw",
"comment": "Variables like $PARAM1, $TM_SELECTION..."
}
Repeat the steps above to update the .tmLanguage
file and restart Sublime Text.
Fine Tuning Matches¶
You might have noticed that the entire text in $PARAM1
, for instance, is styled
the same way. Depending on your needs or your personal preferences, you may want
the $
to stand out. That’s where captures
come in. Using captures,
you can break a pattern down into components to target them individually.
Let’s rewrite one of our previous patterns to use captures
:
{ "match": "\\$([A-Za-z][A-Za-z0-9_]+)",
"name": "keyword.ssraw",
"captures": {
"1": { "name": "constant.numeric.ssraw" }
},
"comment": "Variables like $PARAM1, $TM_SELECTION..."
}
Captures introduce complexity to your rule, but they are pretty straightforward. Notice how numbers refer to parenthesized groups left to right. Of course, you can have as many capture groups as you want.
Arguably, you’d want the other scope to be visually consistent with this one. Go ahead and change it too.
Begin-End Rules¶
Up to now we’ve been using a simple rule. Although we’ve seen how to dissect patterns into smaller components, sometimes you’ll want to target a larger portion of your source code clearly delimited by start and end marks.
Literal strings enclosed in quotation marks and other delimited constructs are better dealt with with begin-end rules. This is a skeleton for one of these rules:
{ "name": "",
"begin": "",
"end": ""
}
Well, at least in their simplest version. Let’s take a look at one including all available options:
{ "name": "",
"begin": "",
"beginCaptures": {
"0": { "name": "" }
},
"end": "",
"endCaptures": {
"0": { "name": "" }
},
"patterns": [
{ "name": "",
"match": ""
}
],
"contentName": ""
}
Some elements may look familiar, but their combination might be daunting. Let’s see them individually.
begin
- Regex for the opening mark for this scope.
end
- Regex for the end mark for this scope.
beginCaptures
- Captures for the
begin
marker. They work like captures for simple matches. Optional. endCaptures
- Same as
beginCaptures
but for theend
marker. Optional. contentName
- Scope for the whole matched region, from the begin marker to the end marker,
inclusive. This will effectively create nested scopes for
beginCaptures
,endCaptures
andpatterns
defined within this rule. Optional. patterns
- An array of patterns to match against the begin-end content only —they are not
matched against the text consumed by
begin
orend
.
We’ll use this rule to style nested complex fields in snippets:
{ "name": "variable.complex.ssraw",
"begin": "(\\$)(\\{)([0-9]+):",
"beginCaptures": {
"1": { "name": "keyword.ssraw" },
"3": { "name": "constant.numeric.ssraw" }
},
"patterns": [
{ "include": "$self" },
{ "name": "string.ssraw",
"match": "."
}
],
"end": "\\}"
}
This is the most complex pattern we’ll see in this tutorial. The begin
and end
keys are self-explanatory: they define a region enclosed between ${<NUMBER>:
and }
.
beginCaptures
further divides the begin mark into smaller scopes.
The most interesting part, however, is patterns
. Recursion and the
importance of ordering have finally made an appearance here.
We’ve seen further above that fields can be nested. In order to account for
this, we need to recursively style nested fields. That’s what the include
rule does when furnished the $self
value: it recursively applies our entire
syntax definition to the portion of text contained in our begin-end rule, excluding
the text consumed by both begin
and end
.
Remember that matched text is consumed and is excluded from the next match attempt.
To finish off complex fields, we’ll style place holders as strings. Since
we’ve already matched all possible tokens inside a complex field, we can
safely tell Sublime Text to give any remaining text (.
) a literal string scope.
Final Touches¶
Lastly, let’s style escape sequences and illegal sequences, and wrap up.
{ "name": "constant.character.escape.ssraw",
"match": "\\\\(\\$|\\>|\\<)"
},
{ "name": "invalid.ssraw",
"match": "(\\$|\\<|\\>)"
}
The only hard thing here is getting the number of escape characters right. Other than that, the rules are pretty straightforward if you’re familiar with regular expressions.
However, you must take care to put the second rule after any others matching
the $
character, since otherwise you may not get the desired result.
Also, note that after adding these two additional rules, our recursive begin-end rule above keeps working as expected.
At long last, here’s the final syntax definition:
{ "name": "Sublime Snippet (Raw)",
"scopeName": "source.ssraw",
"fileTypes": ["ssraw"],
"patterns": [
{ "match": "\\$(\\d+)",
"name": "keyword.ssraw",
"captures": {
"1": { "name": "constant.numeric.ssraw" }
},
"comment": "Tab stops like $1, $2..."
},
{ "match": "\\$([A-Za-z][A-Za-z0-9_]+)",
"name": "keyword.ssraw",
"captures": {
"1": { "name": "constant.numeric.ssraw" }
},
"comment": "Variables like $PARAM1, $TM_SELECTION..."
},
{ "name": "variable.complex.ssraw",
"begin": "(\\$)(\\{)([0-9]+):",
"beginCaptures": {
"1": { "name": "keyword.ssraw" },
"3": { "name": "constant.numeric.ssraw" }
},
"patterns": [
{ "include": "$self" },
{ "name": "string.ssraw",
"match": "."
}
],
"end": "\\}"
},
{ "name": "constant.character.escape.ssraw",
"match": "\\\\(\\$|\\>|\\<)"
},
{ "name": "invalid.ssraw",
"match": "(\\$|\\>|\\<)"
}
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
There are more available constructs and code reuse techniques, but the above explanations should get you started with the creation of syntax definitions.
Plugins 插件 =======
更多信息请参考:
- API Reference
- More information on the Python API.
- API参考文档
- 有关Python API的更详细的信息。
- Plugins Reference
- More information about plugins.
- 插件参考文档
- 有关插件的更详细的信息。
Sublime Text 2 is programmable with Python scripts. Plugins reuse existing commands or create new ones to build a feature. Plugins are rather a logical entity than a physical one. Sublime Text 2可以使用Python脚本进行编程。插件可以重用已有的命令或者新建新的特性。 插件是指逻辑上的,而不是屋里存在的。
Prerequisites 预备知识 *********
In order to write plugins, you must be able to program in Python. 要写一个插件,你必须要会用Python编程。
Where to Store Plugins 插件放到哪里 ******************
Sublime Text 2 will look for plugins in these places: Sublime Text 2会在以下目录中寻找可用的插件:
Packages
Packages/<pkg_name>/
Packages/<包名称>
Consequently, any plugin nested deeper in Packages
won’t be loaded.
所以,存放在 Packages
更深层次的目录结构中的插件不会被加载。
Keeping plugins right under Packages
is discouraged, because Sublime Text
sorts packages in a predefined way before loading them. Thus, you might get
confusing results if your plugins live outside of a package.
让插件都存放在 ``Packages``会有些让人失望,因为Sublime Text会在加载插件之前
通过预先设定的方式排序包组。因此,如果你的插件在一个包的外面,可能会有意想不到的结果。
Your First Plugin 编写第一个插件 *************
Let’s write a “Hello, World!” plugin for Sublime Text 2: 下面,我们给Sublime Text 2写一个”Hello, World!”插件吧:
- Select Tools | New Plugin… in the menu.
- 选择目录**Tools | New Plugin…**。
- Save to
Packages/User/hello_world.py
. - 保存到``Packages/User/hello_world.py``。
You’ve just written your first plugin. Let’s put it to use: 你现在完成了你的第一个插件,下面将其投入使用:
- Create a new buffer (
Ctrl+n
). - 新建一个缓冲区(
Ctrl+n
)。 - Open the python console (
Ctrl+`
). - 打开python命令行(
Ctrl+`
)。 - Type:
view.run_command("example")
and press enter. - 输入:
view.run_command("example")
,然后按下回车。
You should see the text “Hello, World!” in your new buffer. 你会看到你的新缓冲区内显示”Hello, World!”。
Analyzing Your First Plugin 分析你的第一个插件 ***********************
The plugin created in the previous section should look roughly like this:: 前面我们编写插件大致如此:
import sublime, sublime_plugin
- class ExampleCommand(sublime_plugin.TextCommand):
- def run(self, edit):
- self.view.insert(edit, 0, “Hello, World!”)
The sublime
and sublime_plugin
modules are both provided by
Sublime Text 2.
``sublime``和``sublime_plugin``是Sublime Text 2提供的。
New commands derive from the *Command
classes defined in sublime_plugin
(more on this later).
新命令继承定义在``sublime_plugin``的``*Command``类(后面会进行详细的描述)。
The rest of the code is concerned with particulars of the TextCommand
or
the API that we’ll discuss in the next sections.
剩下的代码是来自于``TextCommand``的细节以及我们后面要讨论的API。
Before moving on, though, we’ll look at how we called the new command: We first
opened the python console, and then issued a call to view.run_command()
. This
is a rather inconvenient way of using plugins, but it’s often useful when
you’re in the development phase. For now, keep in mind that your commands
can be accessed through key bindings or other means, just as other commands are.
在向下继续之前,嗯。。我们会看到如何调用新命令:首先,我们打开python命令行,然后
调用``view.run_command()``。这样使用插件显然是很不方便的,但是在开发阶段还是比较
有用的。目前为止,你要记住,自定义的命令可以通过按键绑定或者其他方式使用,就像其
他命令一样。
Conventions for Command Names 命令名称的命名规则 —————————–
You might have noticed that our command is defined with the name ExampleCommand
,
but we pass the string example
to the API call instead. This is necessary because
Sublime Text 2 normalizes command names by stripping the Command
suffix and
separating CamelCasedPhrases
with underscores, like this: camel_cased_phrases
.
你可能已经注意到了我们的命令是以``ExampleCommand``命名的,但是我们向API传入的参数却是
example
。Sublime Text 2是通过截断``Command``的后缀,在``CamelCasedPhrases``中加入
下弧线的方式,比如``camel_cased_phrases``,来统一命令名称的。
New commands should follow the pattern mentioned above for class names. 新的命令必须要按照上面的方式命名类的名称。
Types of Commands 命令类型 *************
You can create the following types of commands: 你可以新建以下类型的命令:
- Application commands (
ApplicationCommand
) - 应用程序命令(
ApplicationCommand
) - Window commands (
WindowCommand
) - 窗口命令(
WindowCommand
) - Text commands (
TextCommand
) - 文本命令(
TextCommand
)
When writing plugins, consider your goal and choose the appropriate type of commands for your plugin. 当你编写插件时,请根据你的目的选择合适的命令类型。
Shared Traits of Commands 命令之间的共享特性 ————————-
All commands need to implement a .run()
method in order to work. Additionally,
they can receive and arbitrarily long number of keyword parameters.
所有的命令都必须实现一个``.run()``方法才能运行。另外,所有命令都可以接受任意长度的
关键字参数。
Application Commands 应用程序命令 ——————–
Application commands derive from sublime_plugin.ApplicationCommand
and
can be executed with sublime.run_command()
.
应用程序命令继承于``sublime_plugin.ApplicationCommand``,可以通过``sublime.run_command()``
执行。
Window Commands 窗口命令 —————
Window commands operate at the window level. This doesn’t mean that you cannot
manipulate views from window commands, but rather that you don’t need views to
exist in order for window commands to be available. For instance, the built-in
command new_file
is defined as a WindowCommand
so it works too when no
view is open. Requiring a view to exist in that case wouldn’t make sense.
串口命令是在窗口级生效的。这并不意味着你不能通过窗口命令控制视图,但是这也并不
是不需要你开启一些视图来让窗口命令生效。比如,内置命令 new_file
是一个
窗口命令
,然而没有视图一样可以生效。因为此时要求打开一个视图并没有意义。
Window command instances have a .window
attribute pointing to the window
instance that created them.
窗口命令实例有一个 .window
属性,指向创建它们的那个窗口实例。
The .run()
method of a window command does not need to take any required
arguments.
窗口命令的``.run()``方法不需要传入参数。
Text Commands 文本命令 ————-
Text commands operate at the buffer level and they require a buffer to exist in order to be available. 文本命令是在缓冲区级生效的,并且需要存在一个缓冲区使之生效。
View command instances have a .view
attribute pointing to the view instance
that created them.
视图命令实例有一个 .view
属性,指向创建它们的那个窗口实例。
The .run()
method of a text command needs to take an edit
instance as
a first positional argument.
窗口命令的 .run()
方法需要一个 edit
实例作为第一个入参。
Text Commands and the edit
Object
文本命令和 edit
对象
————————————-
The edit object groups modifications to the view so undo and macros work in a
sensible way. You are responsible for creating and closing edit objects. To do
so, you can call view.begin_edit()
and edit.end_edit()
. Text commands get
passed an open edit
object in their run
method for convenience.
Additionally, many View
methods require an edit object.
编辑``edit``对象组修改视图,以便撤销和宏命令是以合理的方式运行。你有责任新建和
关闭edit对象。为此,你需要调用 view.begin_edit()
和 edit.end_edit()
。
文本命令为了方便,在其 run
方法中获取传入的 edit
对象。另外,许多 View
方法都需要一个edit对象。
Responding to Events 事件响应 ——————–
Any command deriving from EventListener
will be able to respond to events.
任何继承自``EventListener``的命令都可以响应事件。
Another Plugin Example: Feeding the Completions List 其他插件的例子:添加补全列表 —————————————————-
Let’s create a plugin that fetches data from Google Autocomplete service and feeds it to Sublime Text 2 completions list. Please note that as ideas for plugins go, this a very bad one. 接下来,我们做一个从Google自动完成服务获取数据的插件,然后添加到Sublime Text 2 的补全列表。请注意对于将其作为一个插件,这并不是什么好主意。
import sublime, sublime_plugin
from xml.etree import ElementTree as ET
from urllib import urlopen
GOOGLE_AC = r"http://google.com/complete/search?output=toolbar&q=%s"
class GoogleAutocomplete(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
elements = ET.parse(
urlopen(GOOGLE_AC % prefix)
).getroot().findall("./CompleteSuggestion/suggestion")
sugs = [(x.attrib["data"],) * 2 for x in elements]
return sugs
Learning the API 学习API ************
In order to create plugins, you need to get acquainted with the Sublime Text
API and the available commands. Documentation on both is scarce at the time of
this writing, but you can read existing code and learn from it too. In
particular, the Packages/Default
folder contains many examples of
undocumented commands and API calls.
为了编写插件,你需要熟悉Sublime Text API和内置命令。在写这篇文档时,这些文档还是
比较匮乏的,但是你还是可以从现有的代码中学习的。尤其是在 Packages/Default
文
件中包含了许多非正式的例子和API调用。
Packages¶
Packages are simply directories under Packages
. They exist mainly for
organizational purposes, but Sublime Text follows a few rules when dealing with
them. More on this later.
Here’s a list of typical resources living inside packages:
- build systems (
.sublime-build
)- key maps (
.sublime-keymap
)- macros (
.sublime-macro
)- menus (
.sublime-menu
)- plugins (
.py
)- preferences (
.tmPreferences
)- settings (
.sublime-settings
)- syntax definitions (
.tmLanguage
)- snippets (
.sublime-snippet
)- themes (
.sublime-theme
)
Some packages may include support files for other packages or core
features. For example, the spell checker uses PackagesLanguage - English
as a data store for English dictionaries.
Types of Packages¶
In order to talk about packages in this guide, we’ll divide them in groups. This division is artificial and for the sake of clarity in this topic. Sublime Text doesn’t use it in any way.
- core packages
- Sublime Text requires these packages in order to work.
- shipped packages
- Sublime Text includes these packages in every installation, although they are not technically required. Shipped packages enhance Sublime Text out of the box. They may have been contributed by users or third parties.
- user packages
- These packages are installed by the user to further extend Sublime Text. They are not part of any Sublime Text installation and are always contributed by users or third parties.
- installed packages
- Any package that Sublime Text can restore if deleted.
Let’s emphasize again that you don’t need to memorize this classification. Also, it’s worth noting that by third party we mainly refer to other editors’ users, like Textmate’s.
Installation of Packages¶
There are two main ways to install packages:
.sublime-package
files- version control systems
Ultimately, installing a package consists simply in placing a directory
containing Sublime Text resources under Packages
. The only thing that
changes from one system to another is how you copy these files.
Installation of .sublime-package
Files¶
Copy the .sublime-package
file to the Installed Packages
directory
and restart Sublime Text. If the Installed Packages
doesn’t exist, you can
create it.
Note that .sublime-package
files are simply .zip
archives with a custom
file extension.
Installation of Packages from a Version Control System¶
Explaining how to use version control systems (VCSs) is outside the scope of this guide, but there are many user packages available for free on public repositories like Google Code, GitHub and Bitbucket.
Also, there is a Sublime Text organization at GitHub open to contributors.
Packages and Magic¶
There’s little invisible magic involved in the way Sublime Text deals with packages. Two notable exceptions are that macros defined in any package appear under Tools | Macros | <Your Package>, and snippets from any package appear under Tools | Snippets | <Your Package>.
As mentioned at the beginning, however, there are some rules for packages.
For instance, Package/User
will never be clobbered during updates of the
software.
Merging and Order of Precedence¶
Packages/Default
and Packages/User
also receive a special treatment when
merging files (e. g. .sublime-keymap
and .sublime-settings
files). Before
the merging can take place, the files have to be arranged in an order. To that end,
Sublime Text sorts them alphabetically by name with the exception of files
contained in Default
and User
: Default
will always go to the front
of the list, and User
to the end.
Restoring Packages¶
Sublime Text keeps a copy of all installed packages so it can recreate them when
needed. This means it will be able to reinstall core packages, shipped packages
and user packages alike. However, only user packages installed as a sublime-package
are added to the registry of installed packages. Packages installed in alternative
ways will be completely lost if you delete them.
Reverting Sublime Text to Its Default Configuration¶
To revert Sublime Text to its default configuration, delete the data directory
and restart the editor. Keep in mind, though, that the Installed Packages
directory will be deleted too, so you will lose all installed packages.
Always make sure to back up your data before taking an extreme measure like this one.
The Installed Packages
Directory¶
You will find this directory in the data directory. It contains a copy of every
sublime-package
installed. Used to restore Packages
.
The Pristine Packages
Directory¶
You will find this directoy in the data directory. It contains a copy of every
shipped and core package. Used to restore Packages
.
命令行用法¶
Reference 参考内容 =========
In this section you will find concise information about many aspects of Sublime Text. 在这一部分中,你可以找到Sublime Text中许多内容的详细信息。
If you’re looking for a slow-paced introduction to any of these topics, try the general index. 如果你只是想找找关于这些主题的介绍性质的内容,可以去文档的主页看看。
Snippets 代码片段 ========
Compatibility with Textmate 与Textmate的兼容性 ***********************
Sublime Text snippets are generally compatible with Textmate snippets. Sublime Text的代码片段与Textmate的代码片段基本兼容。
File Format 文件格式 *******
Snippet files are XML files with the sublime-snippet
extension.
代码片段文件是有 sublime-snippet
后缀的XML文件。
<snippet>
<content><![CDATA[]]></content>
<tabTrigger></tabTrigger>
<scope></scope>
<description></description>
</snippet>
content
- Actual snippet content. 实际的代码片段内容。
tabTrigger
- Implicit keybinding for this snippet. Last key (implicit) is
TAB
. 与这段代码片段关联的隐式按键绑定。最后一个(隐式的)按键式TAB
。 scope
- Scope selector to activate this snippet. 适用于这段代码片段的作用域选择子。
description
- User friendly description for menu item. 为了菜单项准备的用户友好的说明性文字。
Escape Sequences 转义序列 ************
\$
- Literal
$
. \$
- 常量
$
。
Environment Variables 环境变量 *****************
$PARAM1 .. $PARAMn |
Arguments passed to the insertSnippet command. |
$PARAM1 .. $PARAMn |
传递给 insertSnippet 命令的各个参数。 |
$SELECTION |
The text that was selected when the snippet was triggered. |
$SELECTION |
代码片段被触发的时候选中的文本内容。 |
$TM_CURRENT_LINE |
Content of the line the cursor was in when the snippet was triggered. |
$TM_CURRENT_LINE |
代码片段被触发的时候光标所在行的内容。 |
$TM_CURRENT_WORD |
Current word under the cursor when the snippet was triggered. |
$TM_CURRENT_WORD |
代码片段被触发的时候光标所在的单词。 |
$TM_FILENAME |
File name of the file being edited including extension. |
$TM_FILENAME |
正在编辑的文件名称,包含文件扩展名。 |
$TM_FILEPATH |
File path to the file being edited. |
$TM_FILEPATH |
正在编辑的文件的文件路径。 |
$TM_FULLNAME |
User’s user name. |
$TM_FULLNAME |
用户的用户名。 |
$TM_LINE_INDEX |
Column the snippet is being inserted at, 0 based. |
$TM_LINE_INDEX |
插入代码片段的列的位置,位置是从0开始计数的。 |
$TM_LINE_NUMBER |
Row the snippet is being inserted at, 1 based. |
$TM_LINE_NUMBER |
插入代码片段的行的位置,位置是从1开始计数的。 |
$TM_SELECTED_TEXT |
An alias for $SELECTION . |
$TM_SELECTED_TEXT |
与 $SELECTION 是等价的。 |
$TM_SOFT_TABS |
YES if translateTabsToSpaces is true, otherwise NO . |
$TM_SOFT_TABS |
当 translateTabsToSpaces 选项是真的时候,值是 YES ,否则为 NO 。 |
$TM_TAB_SIZE |
Spaces per-tab (controlled by the tabSize option). |
$TM_TAB_SIZE |
tab对应的空格数(受 tabSize 选项的控制)。 |
Fields 字域 **
Mark positions to cycle through by pressing TAB
or SHIFT + TAB
.
标记代码片段中可以通过 TAB
或 SHIFT + TAB
循环的各个位置。
Syntax: $1
.. $n
语法: $1
.. $n
$0
- Exit mark. Position at which normal text editing should be resumed. By default,
Sublime Text implicitly sets this mark at the end of the snippet’s
content
element. 退出标记。当循环到这个标记的时候,编辑器应该返回至正常的编辑模式。默认情况下,Sublime Text在content
元素内容的结尾位置隐式的添加这个标记。
Fields with the same name mirror each other. 有相同名字的字域互相映射。
Place Holders 站位符 *********
Fields with a default value. 带有默认值的字域。
Syntax: ${1:PLACE_HOLDER}
.. ${n:PLACE_HOLDER}
语法: ${1:PLACE_HOLDER}
.. ${n:PLACE_HOLDER}
Fields and place holders can be combined and nested within other place holders. 字域和站位符可以遇其他的站位符进行组合和嵌套。
Substitutions 替换 **********
Syntax: 语法:
${var_name/regex/format_string/}
${var_name/regex/format_string/options}
var_name
- The field’s name to base the substitution on: 1, 2, 3… 替换展开所以来的字域的名字:1,2,3……
regex
- Perl-style regular expression: See the Boost library documentation for regular expressions. Perl风格的正则表达式:关于`正则表达式 <http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html>`_ ,请参考Boost库的文档。
format_string
- See the Boost library documentation for format strings. 参考Boost库文档的 格式字符串 内容。
options
Optional. Any of the following: 可选的。可以选择下面的任何一个:
i
- Case-insensitive regex. 忽略大小写敏感的正则。
g
- Replace all occurrences of
regex
. 替换所有匹配regex
的内容。 m
- Don’t ignore newlines in the string. 在字符串中不要忽略换行符。
Syntax Definitions 语法定义 ==================
Warning
This topic is a draft and may contain wrong information.
- 警告:
- 这部分内容仍处于草稿阶段,并可能包含错误信息。
Compatibility with Textmate 与Textmate的兼容性 ***********************
Sublime Text syntax definitions are generally compatible with Textmate language files. Sublime Text的语法定义内容基本上与Textmate的语法定义文件是相互兼容的。
File Format 文件格式 *******
Syntax definitions are files in the Plist format with the tmLanguage
extension.
In this reference files, however, JSON is used instead and converted into Plist.
语法定义文件是以 tmLanguage
作为扩展名的Plist(属性列表)文件。然而,在本文档中,我们将使用
JSON文件来进行讲解,然后再将JSON文件转换为Plist文件。
{ "name": "Sublime Snippet (Raw)",
"scopeName": "source.ssraw",
"fileTypes": ["ssraw"],
"patterns": [
{ "match": "\\$(\\d+)",
"name": "keyword.ssraw",
"captures": {
"1": { "name": "constant.numeric.ssraw" }
},
"comment": "Tab stops like $1, $2..."
},
{ "match": "\\$([A-Za-z][A-Za-z0-9_]+)",
"name": "keyword.ssraw",
"captures": {
"1": { "name": "constant.numeric.ssraw" }
},
"comment": "Variables like $PARAM1, $TM_SELECTION..."
},
{ "name": "variable.complex.ssraw",
"begin": "(\\$)(\\{)([0-9]+):",
"beginCaptures": {
"1": { "name": "keyword.control.ssraw" },
"3": { "name": "constant.numeric.ssraw" }
},
"patterns": [
{ "include": "$self" },
{ "name": "string.ssraw",
"match": "."
}
],
"end": "\\}"
},
{ "name": "constant.character.escape.ssraw",
"match": "\\\\(\\$|\\>|\\<)"
},
{ "name": "invalid.ssraw",
"match": "(\\$|\\>|\\<)"
}
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
name
- Descriptive name for the syntax definition. Shows up in the syntax definition dropdown menu
located in the bottom right of Sublime Text interface. It’s usually the name of the programming
language or equivalent.
所定义语法的描述性名称。这个名称显示在Sublime Text界面右下角的下拉菜单中。通常情况下,
name
表示的是 编程语言或其他标记语言的名称。 scopeName
- Name of the top-level scope for this syntax definition. Either
source.<lang>
ortext.<lang>
. Usesource
for programming languages andtext
for everything else. 语法定义文件起效的顶级坐拥域名称。这个名称一般是source.<语言名称>
或者text.<语言名称>
。 如果是在定义编程语言的语法,那么就使用source
这个名称,否则使用text
作为名称。 fileTypes
- And array of file type extensions for which this syntax should be automatically activated. Include the extensions without the leading dot. 记录适用于这个语法文件的文件扩展名的数组。数组中的每项是去掉”.”的文件扩展名称。
uuid
- Unique indentifier for this syntax definition. Currently ignored. 这个语法定义的唯一标示符。目前被忽略。
foldingStartMarker
- Currently ignored. Used for code folding. 目前被忽略,用于标示折叠内容的开始。
foldingStopMarker
- Currently ignored. Used for code folding. 目前被忽略,用于标示折叠内容的结束。
patterns
- Array of patterns to match against the buffer’s text. 记录与缓冲区中的文字进行匹配的模式的数组。
repository
- Array of patterns abstracted out from the patterns element. Useful to keep the syntax definition tidy as well as for specialized uses like recursive patterns. Optional. 从模式元素中抽象出来的数组。定义这个数组一方面有助于保持语法定义文件整洁,另一方面也能为像 递归模式这样的功能服务。这个内容是可选的。
The Patterns Array 模式数组 **************
Elements contained in the patterns
array.
在 patterns
数组中包含的元素。
match
Contains the following elements: 包含下列原素:
match
Pattern to search for. match
用于搜索的模式。 name
Scope name to be assigned to matches of match
.name
设置被 match
匹配到的内容所具有的作用域。comment
Optional. For information only. comment
可选。只是为了提供信息。 captures
Optional. Refinement of match
. See below.captures
可选。是对 match
的精炼。见下文解释In turn,
captures
can contain n of the following pairs of elements:captures
内容可以包含 多 组下面要说明的元素对:0..n
Name of the group referenced. 0..n
被索引的组的名字。 name
Scope to be assigned to the group. name
组内元素具有的作用域。 Examples: 示例:
// Simple { "name": "constant.character.escape.ssraw", "match": "\\\\(\\$|\\>|\\<)" "comment". "Sequences like \$, \> and \<" } // With captures { "match": "\\$(\\d+)", "name": "keyword.ssraw", "captures": { "1": { "name": "constant.numeric.ssraw" } }, "comment": "Tab stops like $1, $2..." }
include
Includes items in the repository, other syntax definitions or the current one. 在仓库中包含其他的语法定义内容或者当前定义的内容。
References:
$self The current syntax definition. $self 当前的语法定义。 #itemName itemName in the repository. #itemName 仓库中名为 “itemName” 的内容。 source.js External syntax definitions. source.js 外部的语法定义。 Examples: 示例:
// Requires presence of DoubleQuotedStrings element in the repository. { "include": "#DoubleQuotedStrings" } // Recursively includes the current syntax definition. { "include": "$self" } // Includes and external syntax definition. { "include": "source.js" }
begin..end
Defines a scope potentially spanning multiple lines 定义一个可以跨多行的作用域。
Contains the following elements: 包含下面的一些元素:
begin
The start marker pattern. begin
模式的开始标志。 end
The end marker pattern. end
模式的终止标志。 name
Scope name for the whole region. name
整个区域的作用域名称。 beginCaptures
captures
forbegin
. Seecaptures
.beginCaptures
为 begin
准备的captures
。请参考captures
。endCaptures
captures
forend
. Seecaptures
.endCaptures
为 end
准备的captures
。请参考captures
。patterns
patterns
to be matched against the content.patterns
与正文内容进行配对的 patterns
。contentName
Scope name for the content excluding the markers. contentName
除掉标志符之后的内容的作用域名称。 Example: 示例:
{ "name": "variable.complex.ssraw", "begin": "(\\$)(\\{)([0-9]+):", "beginCaptures": { "1": { "name": "keyword.control.ssraw" }, "3": { "name": "constant.numeric.ssraw" } }, "patterns": [ { "include": "$self" }, { "name": "string.ssraw", "match": "." } ], "end": "\\}" }
Repository 仓库 ******
Can be referenced from patterns
or from itself in an include
element.
See include
for more information.
在 include
元素中,既可以从 patterns
中饮用,也可以从自身引用。请参考 include
章节来了解更多信息。
The repository can contain the following elements: 仓库可以包含下列元素:
Simple elements:
"elementName": { "match": "some regexp", "name": "some.scope.somelang" }Complex elements:
"elementName": { "patterns": [ { "match": "some regexp", "name": "some.scope.somelang" }, { "match": "other regexp", "name": "some.other.scope.somelang" } ] }
Examples: 示例:
"repository": {
"numericConstant": {
"patterns": [
{ "match": "\\d*(?<!\\.)(\\.)\\d+(d)?(mb|kb|gb)?",
"name": "constant.numeric.double.powershell",
"captures": {
"1": { "name": "support.constant.powershell" },
"2": { "name": "support.constant.powershell" },
"3": { "name": "keyword.other.powershell" }
}
},
{ "match": "(?<!\\w)\\d+(d)?(mb|kb|gb)?(?!\\w)",
"name": "constant.numeric.powershell",
"captures": {
"1": { "name": "support.constant.powershell" },
"2": { "name": "keyword.other.powershell" }
}
}
]
},
"scriptblock": {
"begin": "\\{",
"end": "\\}",
"name": "meta.scriptblock.powershell",
"patterns": [
{ "include": "$self" }
]
},
}
Escape Sequences 转义序列 ************
Be sure to escape JSON/XML sequences as needed. 请确保对JSON/XML序列内容进行正确的转义。
Build Systems¶
Build systems let you run your files through external programs and see the output they generate within Sublime Text.
构建系统可以让您通过外部程序来运行文件,并可以在Sublime Text查看输出。
Build systems consist of two –or optionally three– parts:
- configuration data in JSON format (the .sublime-build file contents)
- a Sublime Text command driving the build process
- optionally, an external executable file (script, binary file)
构建系统包括两 – 或者说三个 – 部分
- 使用JSON格式保存配置文件 (.sublime-build 内容)
- 使用Sublime Text命令来驱动构建过程
- 还包括一个外部的可执行程序(脚本或者二进制)
Essentially, .sublime-build files are configuration data for an external program as well as for the Sublime Text command just mentioned. In them, you specify the switches, options and environment information you want forwarded.
从根本上来讲,.sublime-build 配置文件对于外部可执行程序与前面提到的Sublime Text命令是一样的。在配置文件中可以指定开关、配置以及环境变量。
The Sublime Text command then receives the data stored in the .sublime-build
file. At this point, it can do whatever it needs to build the files. By
default, build systems will use the exec
command, implemented in
Packages/Default/exec.py. As we’ll explain below, you can override this
command.
Sublime Text命令从 .sublime-build 中读取配置数据,然后根据需要*构建*这些文件。 构建系统缺省会使用``exec`` 命令,该命令在 Packages/Default/exec.py 中实现。 在后续的讲解中,我们会重写这个命令。
Lastly, the external program may be a shell script you’ve created to process
your files, or a well-known utility like make
or tidy
. Usually, these
executable files will receive paths to files or directories, along with
switches and options to be run with.
外部程序可能是你用来处理文件的脚本,也可以能是类似 make
或 tidy
这类的命令。通常,这些可执行文件从配置中获取文件路径或者目录以及运行是需要的开关及选项。
Note that build systems need not call any external program at all if there isn’t any reason to; you could implement a build system entirely in a Sublime Text command.
注意,构建系统可以完全不依赖调用外部程序,完全可以通过Sublime Text
文件格式¶
.构建系统 文件使用JSON. 以下是一个例子:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
选项¶
cmd
- Array containing the command to run and its desired arguments. If you don’t
specify an absolute path, the external program will be searched in your
PATH
, one of your system’s environmental variables.
cmd
包括命令及其参数数组。如果不指定绝对路径,外部程序会在你系统的:const:PATH 环境变量中搜索。
On Windows, GUIs are supressed.
在Windows 系统中,*TBT*
file_regex
- Optional. Regular expression (Perl-style) to capture error output of
cmd
. See the next section for details. file_regex
- 可选。 Perl格式的正则表达式可以获取``cmd``的错误输出,详情参考下一节
line_regex
- Optional. If
file_regex
doesn’t match on the current line, butline_regex
exists, and it does match on the current line, then walk backwards through the buffer until a line matchingfile regex
is found, and use these two matches to determine the file and line to go to.
line_regex
可选。当``file_regex``与该行不匹配,如果``line_regex``存在,并且确实与当前行匹配, 则遍历整个缓冲区,直到与``file regex``匹配的行出现,并用这两个匹配决定最终要跳转的文件 或行。
selector
- Optional. Used when Tools | Build System | Automatic is set to
true
. Sublime Text uses this scope selector to find the appropriate build system for the active view. selector
- 可选。在选定 Tools | Build System | Automatic 时使用。Sublime Text使用这个 选择器自动为活动试图选择构建系统。
working_dir
- Optional. Directory to change the current directory to before running
cmd
. The original current directory is restored afterwards. working_dir
- 可选。在运行``cmd``前会切换到该目录。运行结束后会切换到原来的目录。
encoding
- Optional. Output encoding of
cmd
. Must be a valid python encoding. Defaults toUTF-8
. encoding
- 可选。输出``cmd``的编码。必须是合法的Python编码,缺省为``UTF-8``。
target
Optional. Sublime Text command to run. Defaults to
exec
(Packages/Default/exec.py). This command receives the configuration data specified in the .build-system file.Used to override the default build system command. Note that if you choose to override the default command for build systems, you can add arbitrary variables in the .sublime-build file.
target
可选。运行的Sublime Text命令,缺省为``exec`` (Packages/Default/exec.py)。该命令从 *.build-system*中获取配置数据。
用来替代缺省的构建系统命令。注意,如果你希望替代构建系统的缺省命令,请在*.sublime-build* 文件中专门设置。
env
Optional. Dictionary of environment variables to be merged with the current process’ before passing them to
cmd
.Use this element, for example, to add or modify environment variables without modifying your system’s settings.
env
- 可选。在环境变量被传递给``cmd``前,将他们封装成词典。
shell
- Optional. If
true
,cmd
will be run through the shell (cmd.exe
,bash
…).shell
- 可选。如果该选项为``true`` ,``cmd``则可以通过shell运行。
path
Optional. This string will replace the current process’
PATH
before callingcmd
. The oldPATH
value will be restored after that.Use this option to add directories to
PATH
without having to modify your system’s settings.path
可选。该选项可以在调用``cmd``前替换当前进程的’
PATH
。原来的’PATH
将在运行后恢复。使用这个选项可以在不修改系统设置的前提下将目录添加到’
PATH
中。variants
- Optional. A list of dictionaries of options to override the main build system’s options. Variant ``name``s will appear in the Command Palette for easy access if the build system’s selector matches for the active file.
variants
- 可选。用来替代主构建系统的备选。如果构建系统的选择器与激活的文件匹配,变量的``名称``则 会出现在 Command Palette 中。
name
- Only valid inside a variant (see
variants
). Identifies variant build systems. Ifname
is Run, the variant will show up under the Tools | Build System menu and be bound to Ctrl + Shift + B. name
- 仅在variant中是合法的 (详见
variants
)。用来标识系统中不同的构建系统。如果 ``name``是*Run* ,则会显示在**Tools | Build System** 下,并且可以使用 *Ctrl + Shift + B*调用。
使用 ``file_regex``获取错误输出¶
The file_regex
option uses a Perl-style regular expression to capture up
to four fields of error information from the build program’s output, namely:
file name, line number, column number and error message. Use
groups in the pattern to capture this information. The file name field and
the line number field are required.
``file_regex``选项用Perl的正则表达式来捕获构建系统的错误输出,主要包括四部分内容,分别是 file name*, line number, column number and error message. Sublime Text 在匹配模式中使用分组的方式捕获信息。file name 和 *line number*域是必须的。
When error information is captured, you can navigate to error instances in
your project’s files with F4
and Shift+F4
. If available, the captured
error message will be displayed in the status bar.
当错误信息被捕获时,你可以使用``F4`` 和 ``Shift+F4``在你的项目文件中跳转。被捕获的*错误 信息*会显示在状态栏。
平台相关选项¶
The windows
, osx
and linux
elements let you provide
platform-specific data in the build system. Here’s an example:
``windows``, ``osx`` 以及 ``linux``元素可以帮助你在构建系统中设定平台相关
的选项,举例如下:
- {
“cmd”: [“ant”], “file_regex”: “^ \[javac\] (.+):([0-9]+):() (.)$”, “working_dir”: “${project_path:${folder}}”, “selector”: “source.java”,
“windows”: {
“cmd”: [“ant.bat”]}
}
In this case, ant
will be executed for every platform except Windows,
where ant.bat
will be used instead.
在这个例子中,ant``在除了Windows之外的平台中都是执行 ant ,而在Windows中则执行
``ant.bat
构建系统备选项¶
如下是一个带有备选项的构建系统实例:
{
"selector": "source.python",
"cmd": ["date"],
"variants": [
{ "cmd": ["ls -l *.py"],
"name": "List Python Files",
"shell": true
},
{ "cmd": ["wc", "$file"],
"name": "Word Count (current file)"
},
{ "cmd": ["python", "-u", "$file"],
"name": "Run"
}
]
}
Given these settings, Ctrl + B would run the date command, Crtl + Shift + B would run the Python interpreter and the remaining variants would appear in the Command Palette whenever the build system was active.
根据以上的设定,按 Ctrl + B 会运行*date*命令, 按 Crtl + Shift + B 会运行Python 解释器,并且在构建系统激活时将剩余的备选项显示在Command Palette中。
构建系统变量¶
Build systems expand the following variables in .sublime-build files:
在*.sublime-build* 中包括如下构建系统变量。
$file_path |
当前文件所在路径, 比如 C:\Files. |
$file |
当前文件的完整路径, 比如 C:\Files\Chapter1.txt. |
$file_name |
当前文件的文件名, 比如 Chapter1.txt. |
$file_extension |
当前文件的扩展名, 比如 txt. |
$file_base_name |
当前文件仅包含文件名的部分, 比如 Document. |
$packages |
Packages 文件夹的完整路径. |
$project |
当前项目文件的完整路径. |
$project_path |
当前项目文件的路径. |
$project_name |
当前项目文件的名称. |
$project_extension |
当前项目文件的扩展部分. |
$project_base_name |
当前项目仅包括名的部分. |
变量用法¶
Features found in snippets can be used with these variables. For example:
可以在代码片段上中使用以上变量。例如:
${project_name:Default}
This will emit the name of the current project if there is one, otherwise Default
.
如果当前项目存在则使用该项目名称,否则则使用``Default``替代
${file/\.php/\.txt/}
This will emit the full path of the current file, replacing .php with .txt.
该例会获取当前文件的完整路径,并用*.txt*替换路径中的*.php*
运行构建系统¶
Select the desired build system from Tools | Build System, and then select
Tools | Build or press F7
.
从**Tools | Build System**选择构建系统,然后选择**Tools | Build** ,再按``F7``。
构建系统常见问题¶
Build systems will look for executables in your PATH
, unless you specify
an absolute path to the executable. Therefore, your PATH
variable must be
correctly set.
如果你没有为构建系统指定一个可执行文件的绝对路径,构建系统怎么会在你的 PATH
中进行查找。
所以,你需要正确设置 PATH
。
On some operating systems, the value for PATH
will vary from a terminal
window to a graphical application. Thus, even if the command you are using in
your build system works in the command line, it may not work from Sublime Text.
This is due to user profiles in shells.
在某些操作系统中,终端和图形化应用的 PATH
值会有所不同。所以即便你的构建系统在命令行下
可以正常工作,在Sublime Text也不见得能够正常。这与Shell中的用户设置有关。
To solve this issue, make sure you set the desired PATH
so that graphical
applications such as Sublime Text can find it. See the links below for more
information.
为了解决这个问题,请确认你正确设置了 PATH
,以便类似Sublime Text一类的图形化应用
可以正确找到。更多内容,请参考一下链接
Alternatively, you can use the path
element in .sublime-build files
to override the PATH
used to locate the executable specified in cmd
.
This new value for PATH
will only be in effect for as long as your
build system is running. After that, the old PATH
will be restored.
另外,你也可以在 .sublime-build 文件中设定 path
来替代:const:PATH ,并在 path
指定的路径中查找 cmd
可执行文件。新设定的值,仅在构建系统运行期间有效,过后将会恢复为原始的
PATH
See also
- Managing Environment Variables in Windows
- Search Microsoft knowledge base for this topic.
- Setting environment variables in OSX
- StackOverflow topic.
Key bindings map key presses to commands. 按键绑定为按键与动作建立了映射关系。
File Format 文件格式 *******
Key bindings are stored in .sublime-keymap
files and defined in JSON. All
key map file names need to follow this pattern: Default (<platform>).sublime-keymap
.
Otherwise, Sublime Text will ignore them.
对于按键绑定的配置存储于后缀为 .sublime-keymap
的文件中,文件中记录的是JSON内容。所有按键绑定
配置文件都需要按照如下模式命名: Default (<platform>).sublime-keymap
。否则,Sublime Text
将忽略这些文件。
Platform-Specific Key Maps 平台相关的键位设置 ————————–
Each platform gets its own key map: 每一个平台都有它自己的按键配置文件:
Default (Windows).sublime-keymap
Default (OSX).sublime-keymap
Default (Linux).sublime-keymap
Separate key maps exist to abide by different vendor-specific HCI guidelines. 也有针对不同的硬件提供商指定的 HCI 指导文档准备的按键配置文件。
Structure of a Key Binding 一个按键绑定项的结构 ————————–
Key maps are arrays of key bindings. Below you’ll find valid elements in key bindings. 键位表是一个按键绑定项的数组。接下来将要解释的是按键绑定中的有效构成元素:
keys
- An array of case-sensitive keys to be pressed. Modifiers can be specified
with the
+
sign. Chords are built by adding elements to the array, e. g.["ctrl+k","ctrl+j"]
. Ambiguous chords are resolved with a timeout. 一组大小写敏感的按键组合。可以用+
指定修饰符。向数组中添加元素可以设置组合键,例如:["ctrl+k","ctrl+j"]
。 command
- Name of the command to be executed. 要执行的命令的名称。
args
- Dictionary of arguments to be passed to
command
. Keys must be the names of parameters tocommand
. 传递给command
命令的参数字典。字典中键的名称是command
命令的参数名称。 context
- Array of contexts to selectively enable the key binding. All contexts must be true for the key binding to trigger. See context-reference below. 选择性控制按键绑定是否起效的上下文内容数组。只有当所有上下文都为真时,按键绑定才能被触发。 请参考下面的 上下文参考 内容来了解更多内容。
Here’s an example illustrating most of the features outlined above:: 下面是一个说明上面提到的大部分特性的例子:
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
}
Structure of a Context 上下文的结构 ———————-
key
- Name of a context operand to query. 要请求的上下文操作符的名称。
operator
- Type of test to perform against
key
. 对key
进行测试的类型。 operand
- Value against which the result of
key
is tested. 与key
的结果进行测试的值。 match_all
- Requires the test to succeed for all selections. Defaults to
false
. 需要多所有选择都进行测试。默认值为false
。
Context Operands 上下文操作子 ^^^^^^^^^^^^^^^^
auto_complete_visible
- Returns
true
if the autocomplete list is visible. 如果自动不全列表可见就返回true
。 has_next_field
- Returns
true
if there’s a next snippet field available. 当下一个代码片段域可用时返回true
。 has_prev_field
- Returns
true
if there’s a previous snippet field available. 当上一个代码片段域可用时返回true
。 num_selections
- Returns the number of selections. 返回当前选中的数目。
overlay_visible
- Returns
true
if any overlay is visible. 当覆盖控件可见时返回true
。 panel_visible
- Returns
true
if any panel is visible. 当有面板可见时返回true
。 following_text
- Restricts the test to the text following the caret. 限制测试只对脱字号后的文本进行。
preceding_text
- Restricts the test to the text preceding the caret. 限制测试只对脱字号前的文本进行。
selection_empty
- Returns
true
if the selection is an empty region. 当没有选中内容的时候返回true
。 setting.x
- Returns the value of the
x
setting.x
can be any string. 返回x
设置项的值。x
可以为任意字符串。 text
- Restricts the test to the selected text. 限制测试只对选中的文本有效。
selector
- Returns the current scope. 返回当前作用域。
Context Operators 上下文操作符 ^^^^^^^^^^^^^^^^^
equal
,not_equal
- Test for equality. 测试是否相等。
regex_match
,not_regex_match
- Match against a regular expression. 与一个正则表达式进行匹配。
regex_contains
,not_regex_contains
- Match against a regular expression (containment). 与一个正则表达式进行匹配(检测是否包含)。
Command Mode 命令模式 ********
Sublime Text provides a command_mode
setting to prevent key presses from
being sent to the buffer. This is useful to emulate Vim’s modal behavior.
Sublime Text提供一个称为 command_mode
(命令模式)的设置项,启用这个设置可以阻止按键内容
被送往缓冲区。这个设置项在模拟Vim的模式功能的时候很有用处。
Bindable Keys 可绑定的按键 *********
Keys may be specified literally or by name. Below you’ll find the list of valid names: 按键可以通过字面值或者名字来指定。你可以在下面找到一个有效名称的列表:
up
down
right
left
insert
home
end
pageup
pagedown
backspace
delete
tab
enter
pause
escape
space
keypad0
keypad1
keypad2
keypad3
keypad4
keypad5
keypad6
keypad7
keypad8
keypad9
keypad_period
keypad_divide
keypad_multiply
keypad_minus
keypad_plus
keypad_enter
clear
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
f16
f17
f18
f19
f20
sysreq
break
context_menu
browser_back
browser_forward
browser_refresh
browser_stop
browser_search
browser_favorites
browser_home
Modifiers 修饰符 ———
shift
ctrl
alt
super
(Windows key, Command key…)super
(在Windows平台为Windows键,在OS X平台为Command键……)
Warning about Bindable Keys 关于可绑定按键的警告 —————————
If you’re developing a package, keep this in mind: 如果你正在开发一个包,请谨记下面几点:
Ctrl+Alt+<alphanum>
should not be used on any Windows key bindings.- 在Windows平台上,不要使用
Ctrl+Alt+<alphanum>
进行任何键位绑定。 Option+<alphanum>
should not be used on any OS X key bindings.- 在OS X平台上,不要使用
Option+<alphanum>
进行任何键位绑定。
In both cases, the user’s ability to insert non-ascii characters would be compromised. 在以上两种情况下,用户都将在插入非ascii字符时遇到问题。
If you are the end-user, you are free to remap those key combinations. 如果你是终端用户,你可以随意重新映射这些按键组合。
Keeping Key Maps Organized 让按键映射井井有条 **********************
Sublime Text ships with default key maps under Packages/Default
. Other
packages may include their own key map files. The recommended storage location
for your personal key map is Packages/User
.
Sublime Text自带的按键组合存放在 Packages/Default
目录下。其他包组可以包含它们特有的按键
映射文件。对于你自己的键位映射设置而言,推荐的文件存放地址是 Packages/User
目录。
See Merging and Order of Precedence for information about how Sublime Text sorts files for merging. 请参考 排序与优先级顺序 以了解关于Sublime Text排序文件并进行合并的更多信息。
International Keyboards 国际化键盘 *******************
Due to the way Sublime Text maps key names to physical keys, there might be a mismatch between the two. 根据Sublime Text将按键名称与物理按键进行映射的方式,此二者在不同平台上可能有不同的配对。
Troubleshooting 常见问题解答 ***********
See sublime.log_commands(flag) to enable command logging. It may help when debugging key maps. 使用 sublime.log_commands(flag) 开启命令日志。这对于调试按键映射有所帮助。
Global Settings 全局设置项 ===============
Target file: Global.sublime-settings
.
对应文件: Global.sublime-settings
。
theme
- Theme to be used. Accepts a file base name (e. g.:
Default.sublime-theme
). 系统使用的主题文件。接受主题文件的名称(例如:Default.sublime-theme
)。 remember_open_files
- Determines whether to reopen the buffers that were open when Sublime Text was last closed. 设置Sublime Text启动时是否需要打开上次关闭时打开了的缓冲区。
folder_exclude_patterns
- Excludes the matching folders from the side bar, GoTo Anything, etc. 与匹配模式相符的目录将不会出现在侧边栏、快速跳转面板等位置。
file_exclude_patterns
- Excludes the matching files from the side bar, GoTo Anything, etc. 与匹配模式相符的文件将不会出现在侧边栏、快速跳转面板等位置。
scroll_speed
- Set to
0
to disable smooth scrolling. Set to a value between0
and1
to scroll slower, or set to a value larger than1
to scroll faster. 如果把值设为0
,将禁止平滑滚动。取0
到1
之间的数值将使滑动变的比较缓慢,取大于1
的值使得滑动更加迅速。 show_tab_close_buttons
- If
false
, hides the tabs’ close buttons until the mouse is hovered over the tab. 如果设置为false
,通常情况下就不会显示标签页的关闭按钮,只有当鼠标移动到标签上时才显示。 mouse_wheel_switches_tabs
- If
true
, scrolling the mouse wheel will cause tabs to switch if the cursor is in the tab area. 如果设置为true
,在标签区域滑动鼠标滚轮会触发标签页之间的切换。 open_files_in_new_window
- OS X only. When filters are opened from Finder, or by dragging onto the dock icon, this controls if a new window is created or not. 仅在OS X平台有效。当用户从Finder中开打文件,或者把文件拖拽到dock面板的图标上,这个设置项将决定 是否需要创建一个新窗口。
File Settings 文件设置项 =============
Target files: Base File.sublime-settings
, <file_type>.sublime-settings
.
对应文件: Base File.sublime-settings
, <file_type>.sublime-settings
。
Whitespace and Indentation 空格与缩进 **********************
auto_indent
- Toggles automatic indentation. 开/关自动缩进选项。
tab_size
- Number of spaces a tab is considered to be equal to. 设置tab键对应的空格数。
translate_tabs_to_spaces
- Determines whether to replace a tab character with
tab_size
number of spaces whenTab
is pressed. 设置当用户按下Tab
键时,是否需要用tab_size
选项所指定数目的空格进行替换。 use_tab_stops
- If
translate_tabs_to_spaces
istrue
, will makeTab
andBackspace
insert/deletetab_size
number of spaces per key press. 如果translate_tabs_to_spaces
选项为true
,设置这个选项就使得每次按下Tab
与Backspace
键时,将插入/删除tab_size
选项所指定数目的空格。 trim_automatic_white_space
- Toggles deletion of white space added by
auto_indent
. 开/关对由auto_indent
选项自动添加的只有空格的行的检测。 detect_indentation
- Set to
false
to disable detection of tabs vs. spaces whenever a buffer is loaded. If set totrue
, it will automatically modifytranslate_tabs_to_spaces
andtab_size
. 如果设置为false
,当系统加在缓冲区内容的时候,就会停止对tab与空格的检测。如果设置为true
则会自动修改translate_tabs_to_spaces
以及tab_size
的值。 draw_white_space
- Valid values:
none
,selection
,all
. 有效值:none
,selection
,all
。 trim_trailing_white_space_on_save
- Set to
true
to remove white space on save. 将这个选项设置为true
就会在文件保存时候自动去处行为的空格。
Visual Settings 显示设置项 ***********
color_scheme
- Sets the colors used for text highlighting. Accepts a path rooted at the
data directory (e. g.:
Packages/Color Scheme - Default/Monokai Bright.tmTheme
). 设置文本高亮的配色方案。接受从数据目录开始的相对路径(例如:Packages/Color Scheme - Default/Monokai Bright.tmTheme
)。 font_face
- Font face to be used for editable text. 设置可编辑文本的字体样式。
font_size
- Size of the font for editable text. 设置可编辑字体的字体大小。
font_options
- Valid values:
bold
,italic
,no_antialias
,gray_antialias
,subpixel_antialias
,directwrite
(Windows). 有效值:bold
,italic
,no_antialias
,gray_antialias
,subpixel_antialias
,directwrite
(对Windows平台有效)。 gutter
- Toggles display of gutter. 开/关侧边栏选项。
rulers
- Columns in which to display vertical rules. Accepts a list of numeric values
(e. g.
[79, 89, 99]
or a single numeric value (e. g.79
). 设置标尺所在的列坐标。接受一个数字值的列表(例如[79, 89, 99]
或者一个单一的数字值79
)。 draw_minimap_border
- Set to
true
to draw a border around the minimap’s region corresponding to the the view’s currently visible text. The active color scheme’sminimapBorder
key controls the border’s color. 如果将这个值设置为true
,就将根据视图当前可见文本的内容在迷你地图区域画一个边框。当前选中的 配色方案中的minimapBorder
键对应的值用于控制边框的颜色。 highlight_line
- Set to
false
to stop highlighting lines with a cursor. 将这个值设置为false
来阻止高亮当前光标所在行。 line_padding_top
- Additional spacing at the top of each line, in pixels. 每行文字与上一行的额外距离,以像素为单位。
line_padding_bottom
- Additional spacing at the bottom of each line, in pixels. 每行文字与下一行的额外距离,以像素为单位。
scroll_past_end
- Set to
false
to disable scrolling past the end of the buffer. Iftrue
, Sublime Text will leave a wide, empty margin between the last line and the bottom of the window. 设置为false
以关闭超出缓冲区的滚动。如果设置为true
,Sublime Text将在文本的最后一行 与窗口下边界之间添加一大块空白区域。 line_numbers
- Toggles display of line numbers in the gutter. 开/关对行号的显示。
word_wrap
- If set to
false
, long lines will be clipped instead of wrapped. Scroll the screen horizontally to see the clipped text. 如果设置为false
那么对于内容很多的行,文本将被截取,而不会自动换行。在水平方向拖动滚动条可以 查看被截取的文字。 wrap_width
- If greater than
0
, wraps long lines at the specified column as opposed to the window width. Only takes effect ifwrap_width
is set totrue
. 如果这个值大于0
, 系统就会在这个指定的列进行换行切分;否则会根据屏幕的宽度进行换行。这个值 只有在wrap_width
设置为true
的时候才有效果。 indent_subsequent_lines
- If set to
false
, wrapped lines will not be indented. Only takes effect ifwrap_width
is set totrue
. 如果这个值设置为false
,被转换的行就不会进行缩进。只有在wrap_width
为true
时 才有效。 draw_centered
- If set to
true
, text will be drawn centered rather than left-aligned. 如果设置为true
,文本将居中对齐,否则为左对齐。 match_brackets
- Set to
false
to disable underlining the brackets surrounding the cursor. 当值设置为false
时,光标放在括号周围的时候就不会显示下划线。 match_brackets_content
- Set to
false
is you’d rather only highlight the brackets when the cursor is next to one. 设置光标在括号周围时,是否要高亮括号中的内容。 match_brackets_square
- Set to
false
to stop highlighting square brackets. Only takes effect ifmatch_brackets
istrue
. 如果设置项值为false
,就停止对方括号的配对显示。只有在match_brackets
值为true
时有效。 match_bracktets_braces
- Set to
false
to stop highlighting curly brackets. Only takes effect ifmatch_brackets
istrue
. 如果设置项值为false
,就停止对花括号的配对显示。只有在match_brackets
值为true
时有效。 match_bracktets_angle
- Set to
false
to stop highlighting angle brackets. Only takes effect ifmatch_brackets
istrue
. 如果设置项值为false
,就停止对尖括号的配对显示。只有在match_brackets
值为true
时有效。
Automatic Behavior 自动行为设置项 **************
auto_match_enabled
- Toggles automatic pairing of quotes, brackets, etc. 开/关自动配对引号、括号等符号。
save_on_focus_lost
- Set to true to automatically save files when switching to a different file or application. 如果这个值为真,那么当用户切换到一个不同的文件,或不同的应用程序时,文件的内容将会自动保存。
find_selected_text
- If
true
, the selected text will be copied into the find panel when it’s shown. 如果设置为true
,那么当打开搜索面板时,当前选中的文字会被自动的复制到搜索面板中。 word_separators
- Characters considered to separate words in actions like advancing the cursor, etc. They are not used in all contexts where a notion of a word separator is useful (e. g.: word wrapping). In such other contexts, the text might be tokenized based on other criteria (e. g. the syntax definition rules). 设置在动作中用于分割单词的字符,例如光标跨单词移动的时候来界定单词的分隔符。这个单词分隔符并 不用于所有需要区分单词的情况(例如:换行时不切分单词)。在这种情况下,文本是基于其他标准来界 定的(例如:语法定义规则)。
ensure_newline_at_eof_on_save
- Always adds a new line at the end of the file if not present when saving. 如果文本末尾没有空行,那么当保存文件的时候,会自动在文件末尾添加一个空行。
System and Miscellaneous Settings 系统与其他设置项 *****************************
is_widget
- Returns
true
if the buffer is an input field in a dialog as opposed to a regular buffer. 当缓冲区为输入对话框中的输入域的时候,返回true
。 spell_check
- Toggles the spell checker. 开/关拼写检查选项。
dictionary
- Word list to be used by the spell checker. Accepts a path rooted at the
data directory (e. g.:
Packages/Language - English/en_US.dic
). You can add more dictionaries. 拼写检查器可选的单词列表。接受从数据目录开始的一个路径(例如:Packages/Language - English/en_US.dic
)。 你也可以 添加更多目录 。 fallback_encoding
- The encoding to use when the encoding can’t be determined automatically. ASCII, UTF-8 and UTF-16 encodings will be automatically detected. 控制当无法自动判断编码的时候选用的默认编码。系统可以自动检测的编码包括ASCII,UTF-8以及UTF-16.
default_line_ending
- Determines what characters to use to designate new lines. Valid values:
system
(OS-dependant),windows
(CRLF
) andunix
(LF
). 控制系统使用的换行符的字符。有效选项:system
(OS相关),windows
(即CRLF
)以及unix
(LF
)。 tab_completion
- Determines whether pressing
Tab
will insert completions. 控制按下Tab
时是否进行补全。
Build and Error Navigation Settings 构建与错误导航设置项 *******************************
result_file_regex
- Regular expression used to extract error information from some output dumped into a view or output panel. Follows the same rules as error capturing in build systems.º 用于过滤视图或输出面板中的错误信息的正则表达式。这里的正则表达式遵循与构建系统中的错误捕获相同的规则。
result_line_regex
- Regular expression used to extract error information from some output dumpºed into a view or output panel. Follows the same rules as error capturing in build systems. 用于过滤视图或输出面板中的错误信息的正则表达式。这里的正则表达式遵循与构建系统中的错误捕获相同的规则。
result_base_dir
- Directory to start looking for offending files in based on information
extracted with
result_file_regex
andresult_line_regex
. 设置基于result_file_regex
以及result_line_regex
抽取出来的信息开始搜索的文件路径。 build_env
- List of paths to add to build systems by default. 默认添加到构建系统中的路径列表。
File and Directory Settings 文件与目录设置项 ***********************
default_dir
- Sets the default save directory for the view. 设置视图对应的默认保存路径。
Input Settings 输入设置项 **********
command_mode
- If set to
true
, the buffer will ignore key strokes. Useful to emulate Vim. 如果将这个值设为true
,则缓冲区将忽略用户按键。这对模拟Vim很有帮助。
命令面板¶
命令面板由 .sublime-commands
文件中的各项组成.
文件格式 (.sublime-commands
文件)¶
如下是来自 Packages/Default/Default.sublime-commands
的实例:
[
{ "caption": "Project: Save As", "command": "save_project_as" },
{ "caption": "Project: Close", "command": "close_project" },
{ "caption": "Project: Add Folder", "command": "prompt_add_folder" },
{ "caption": "Preferences: Default File Settings", "command": "open_file", "args": {"file": "${packages}/Default/Base File.sublime-settings"} },
{ "caption": "Preferences: User File Settings", "command": "open_file", "args": {"file": "${packages}/User/Base File.sublime-settings"} },
{ "caption": "Preferences: Default Global Settings", "command": "open_file", "args": {"file": "${packages}/Default/Global.sublime-settings"} },
{ "caption": "Preferences: User Global Settings", "command": "open_file", "args": {"file": "${packages}/User/Global.sublime-settings"} },
{ "caption": "Preferences: Browse Packages", "command": "open_dir", "args": {"dir": "$packages"} }
]
caption
- 显示在命令面板中的标题.
command
- 代执行的命令.
args
- Arguments to pass to
command
. Note that to locate the packages folder you need to use a snippet-like variable:${packages}
or $packages. This different to other areas of the editor due to different implementations of the lower level layers.
传给 command
的参数。 需要注意的是,要定位包所在目录,需要使用 ${packages}
或 $packages。由于底层的实现不同,这与在编辑器的其他区域的用法略有不同。
如何使用命令面板¶
- 按
Ctrl+Shift+P
- 选择命令
Entries are filtered by current context. Not all entries will be visible at all times.
显示的选项会根据上下文不同有所区别,并不是在任何时候都会显示所有选项。
Completions 补全 ===========
Completions provide an IDE-like functionality to insert dynamic content through
the completions list or by pressing Tab
.
补全提供了像IDE那样的使用补全列表或者 Tab
键插入动态内容的功能。
File Format 文件格式 *******
Completions are JSON files with the .sublime-completions
extension.
补全信息是以 .sublime-completions
作为扩展名的JSON文件。
Structure of a Completions List 补全列表的结构 ***************************
scope
- Determines whether the completions are to be sourced from this file. See Scopes for more information. 控制补全是否应该在这个文件中发挥作用。参考 作用域与作用域选择子 来了解更多信息。
completions
- Array of completions. 补全的数组。
Here’s an excerpt from the html completions:: 下面是从html补全列表中截取出来的一部分:
{
"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
"completions":
[
{ "trigger": "a", "contents": "<a href=\"$1\">$0</a>" },
{ "trigger": "abbr", "contents": "<abbr>$0</abbr>" },
{ "trigger": "acronym", "contents": "<acronym>$0</acronym>" }
]
}
Types of Completions 补全的类型 ****************
Plain Strings 纯文本字符串 ————-
Plain strings are equivalent to an entry where the trigger
is identical to
the contents
::
当某个补全项 trigger
的内容与 contents
的内容完全一样的时候,纯文本字符串与这个补全项
是等价的。
“foo”
# is equivalent to: # 等价于:
{ “trigger”: “foo”, “contents”: “foo” }
Trigger-based Completions 基于触发内容的补全 ————————-
trigger
- Text that will be displayed in the completions list and will cause the
contents
to be inserted when validated. 在补全列表中显示的文本,在被确认后,对应的contents
内容被插入到缓冲区中。 contents
- Text to be inserted in the buffer. Can use snippet features. 要插入到缓冲区中的文本。可以使用代码片段的特性。
Sources for Completions 补全的来源 *******************
These are the sources for completions the user can control: 用户可以控制的补全来源包括:
.sublime-completions
EventListener.on_query_completions()
Additionally, other completions are folded into the final list: 除此之外,其他在最终补全列表中可以显示的内容包括:
- Snippets
- Words in the buffer
- 代码片段
- 缓冲区中的单词
Priority of Sources for Completions 补全来源的优先级 ———————————–
- Snippets
- API-injected completions
.sublime-completions
files- Words in buffer
- 代码片段
- 使用API插入的补全内容
.sublime-completions
文件- 缓冲区中的单词
Snippets will only be automatically completed against an exact match of their tab trigger. Other sources for completions are filtered with a case insensitve fuzzy search instead. 代码片段只有在与设置的tab触发器精确匹配时才会被插入。其他类型的补全则是使用大小写不敏感的模糊 搜索进行匹配。
The Completions List 补全列表 *****************
To use the completions list: 要使用补全列表需要:
- Press
Ctrl+spacebar
to open- Optionally, press
Ctrl+spacebar
again to select next entry- Press
Enter
orTab
to validate selection- 按
Ctrl+空格
来打开补全列表- 可选的, 再次按下
Ctrl+空格
来选择下一个候选项- 按下
回车
orTab
来确认选择
Note
The current selection in the completions list can actually be validated with any punctuation sign that isn’t itself bound to a snippet.
Snippets show up in the completions list following the pattern:
<tab_trigger> : <name>
. For the other completions, you will just see the
text to be inserted.
代码片段以如下形式出现在补全列表中:<tab触发器> : <名称>
。对于其他补全项,你只能看到要被
插入的文本。
If the list of completions can be narrowed down to one choice, the autocomplete dialog will be bypassed and the corresponding content will be inserted straight away according to the priority rules stated above. 当补全列表被缩减到只有一个候选项时,系统就会绕开自动补全对话框,根据之前介绍的优先级,对应内容 会被直接插入。
Enabling and Disabling Tab Completion for Completions 为补全列表启用或禁用Tab补全 *************************************************
The tab_completion
setting is true
by default. Set it to false
if
you want Tab
to stop sourcing the most likely completion. This setting
has no effect on triggers defined in .sublime-snippet
files, so snippets
will always be inserted after a Tab
.
tab_completion
选项默认是 true
。如果你想停止 Tab
键对最可能选项的索引功能,
就把这个值设置为 false
。这个设置项对定义在 .sublime-snippet
文件中的触发器没有效果,
因此按下 Tab
时,代码片段一定会被插入。
With tab_completion
on, The same order of priority as stated above applies,
but, unlike in the case of the completions list, Sublime Text will always
insert a completion, even if faced with an ambiguous choice.
当 tab_completion
选项开启的时候,上面介绍的优先级顺序仍然有效,但是,与补全列表不同的是,
Sbulime Text总会插入一个补全项,及时选择项存在模糊内容。
Inserting a Literal Tab 插入一个Tab(缩进)字符 ———————–
If tab_completion
is true
, you can press Shift+Tab
after a prefix
to insert a literal tab character.
如果 tab_completion
值为 true
,你可以使用 Shift+Tab
来插入一个缩进字符。
Plugins 插件 =======
See also
- API Reference
- More information on the Python API.
更多信息请参考:
- API参考文档
- 有关Python API的更详细的信息。
Plugins are Python scripts implementing *Command
classes from
sublime_plugin
.
插件是实现了 sublime_plugin
模块中 *Command
类的Python脚本。
Where to Store Plugins 插件放到哪里 ******************
Sublime Text 2 will look for plugins in these places: Sublime Text 2在以下这些目录中寻找可用插件:
Packages
Packages/<pkg_name>
Packages/<包名称>
Any plugin nested deeper in Packages
won’t be loaded.
存放在 Packages
更深层次的目录结构中的插件不会被加载。
All plugins should live inside a directory of their own and not directly
under Packages
.
任何插件都应该又自己单独的目录,而不应该直接放在 Packages
目录下。
Conventions for Command Names 命令名称的命名规则 *************************
Sublime Text 2 command class names are suffixed by convention with Command
and written as CamelCasedPhrases
.
Sublime Text 2遵循 CamelCasedPhrases
命名规则来定义命令类,同时用 Command
作为后缀。
However, Sublime Text 2 transforms the class name from CamelCasedPhrases
to camel_cased_phrases
. So ExampleCommand
would turn into example
and AnotherExampleCommand
would turn into another_example
.
然而,Sublime Text 2将类名从 CamelCasedPhrases
形式自动转换成 camel_cased_phrases
。
举例来说, ExampleCommand
将被转换为 example
,而 AnotherExampleCommand
将
转换为 another_example
。
For class definition names, use CamelCasedPhrasesCommand
; to call a
command from the API, use the normalized name (camel_cased_phrases
).
对于类定义名称,可以使用 CamelCasedPhrasesCommand
命名方式;要从API中调用一个命令,请使用
标准化后的名称( camel_cased_phrases
)。
Types of Commands 命令类型 *************
sublime_plugin.ApplicationCommand
sublime_plugin.WindowCommand
sublime_plugin.TextCommand
sublime_plugin.EventListener
Instances of WindowCommand
have a .window
attribute pointing to the
window instance that created them. Similarly, instances of TextCommand
have a .view
attribute.
WindowCommand
类的实例都有一个 .window
属性,指向创建他们的那个窗口实例。于此类似,
TextCommand
类的实例拥有 .view
属性。
Shared Traits for Commands 命令之间的共享特性 ————————–
All commands must implement a .run()
method.
所有命令都必须实现一个 .run()
方法。
All commands can receive and arbitrarily long number of keyword arguments,
but they must be valid JSON types.
所有命令都可以接受任意长度的关键字参数,但是这些参数一定要是有效的JSON类型。
How to Call Commands from the API 如何利用API调用命令 *****************************
Use a reference to a View
or a Window
, or sublime
depending on
the type of command, and call object.run_command('command_name')
.
In addition, you can pass a dictionary where keys are names of parameters
to command_name
.
window.run_command("echo", {"Tempus": "Irreparabile", "Fugit": "."})
Command Arguments
*****************
All user-provided arguments to commands must be valid JSON types. Only
Sublime Text can pass other types of arguments to commands (such as edit
objects, view instances, etc.).
Use a reference to a View
or a Window
, or sublime
depending on
the type of command, and call object.run_command('command_name')
.
根据命令的类型来选择对 View
、 Window
或者 sublime
的引用,然后通过
object.run_command('command_name')
来调用。
In addition, you can pass a dictionary where keys are names of parameters
to command_name
. ::
除此之外, 你可以用字典作为参数,字典中的键就是要传给 command_name
的参数名称:
window.run_command("echo", {"Tempus": "Irreparabile", "Fugit": "."})
Command Arguments
命令参数
*****************
All user-provided arguments to commands must be valid JSON types. Only
Sublime Text can pass other types of arguments to commands (such as edit
objects, view instances, etc.).
用户提供给命令的所有参数都必须是有效的JSON类型。只有Sublime Text可以给命令传递其他类型的参数
(例如修改对象,视图实例等等)。
Text Commands and the edit
Object
文本命令以及 修改
对象
*********************************
The two API functions of interest are view.begin_edit()
, which takes an
optional command name and an optional dictionary of arguments, and
view.end_edit()
, which finishes the edit.
关于两个文本命令的两个较为重要的API是 view.begin_edit()
和 view.end_edit()
。
其中 view.begin_edit()
可以接受一个可选的命令名称和可选的参数字典;而 view.end_edit()
用来结束编辑过程。
All actions done within an edit are grouped as a single undo action. Callbacks
such as on_modified()
and on_selection_modified()
are called when the
edit is finished.
在修改过程中发生的所有动作都被整合成一个单一的撤销动作。当编辑过程结束的时候,类似与
on_modified
和 on_selection_modified()
的回调函数会被触发。
It’s important to call view.end_edit()
after each view.begin_edit()
,
otherwise the buffer will be in an inconsistent state. An attempt will be made
to fix it automatically if the edit object gets collected, but that often
doesn’t happen when you expect, and will result in a warning printed to the
console. In other words, you should always bracket an edit in a
try..finally
block.
有一点非常重要,每次调用 view.begin_edit()
之后必须调用 view.end_edit()
方法,否则
缓冲将处于一种不一致状态。在不匹配发生时,系统将尝试自动进行修正,但是这种自动修正的发生频率并
没有你想象的那么多,同时会在控制台输出一条警告信息。换句话说,你应该始终使用 try..finally
来包裹代码快。
The command name passed to begin_edit()
is used for repeat, macro
recording, and for describing the action when undoing/redoing it. If you’re
making an edit outside of a TextCommand
, you should almost never supply a
command name.
传递给 begin_edit()
的命令名称用于重复、宏录制以及撤销/重复过程中的动作描述。如果你在
TextCommand
外面做修改,你就不该指定命令名称。
If you have created an edit object, and call a function that creates another
one, that’s fine: the edit is only considered finished when the outermost call
to end_edit()
runs.
你可以在开始的时候创建一个修改对象,然后调用了一个方法又创建了另外的一个修改对象:只有当最外层
的修改对象执行了 end_edit()
方法之后,系统才认为整个修改都完成了。
As well as grouping modifications, you can use edit objects for grouping changes to the selection, so they’re undone in a single step. 与群组修改类似,你也可以使用修改对象把对选中文本做的修改组合成一个群组,对它们的修改只要一步就 能撤销。
Responding to Events 对事件的响应 ****************
Any subclass of EventListener
will be able to respond to events. You
cannot make a class derive from both EventListener
and any other type of
command.
任何 EventListener
的子类都能够响应事件。对于任何一个类,不能同时继承 EventListener
和其他任何的命令类。
Python and the Standard Library Python与标准库 ***************************
Sublime Text ships with a trimmed down standard library. Notable missing modules are the Tkinter, multiprocessing and sqlite3 modules. Sublime Text集成了一个精简版的标准库。被裁剪掉的模块包括 Tkinter , multiprocessing 以及 sqlite3 。
Automatic Plugin Reload 自动插件重载 *******************
Sublime Text will automatically reload top-level Python modules from packages as they change (perhaps because you are editing a .py file). Note that Python subpackages won’t be reloaded; this can lead to confusion while developing plugins. Generally, it’s best to restart Sublime Text after you’ve made changes to plugin files so all changes take effect. 当你对插件做修改的时候(比如你正在修改一个 .py 文件),Sublime Text会自动加载包中的顶级 Python模块。值得注意的是Python的子模块不会被自动重新加载;这一点在插件开发中可能会产生一些挺 奇葩的问题。一般来说,当你对插件文件做修改之后,最好重启以下Sublime Text,这样能保证你做的修 改能发挥作用。
Multithreading 多线程 **********
Only the .set_timeout()
function is safe to call from different threads.
只有 .set_timeout()
方法可以安全的从其他线程调用。
Python API¶
浏览 API¶
A quick way to see the API in action:
快速查看API的方法:
- Add
Packages\Default
(Preferences | Browse Packages…) to your project. CTRL + SHIFT + F
- Enter
*.py
in the In Files: field - Check
Use Buffer
option - Search API name
F4
- Study relevant source code
- 将
Packages\Default
(Preferences | Browse Packages…) 添加到你的项目中. - 按下组合键
CTRL + SHIFT + F
- 在 In Files: 栏中输入
*.py
- 检查
Use Buffer
选项 - 搜索 API 名字
- 按
F4
- 学习相关的源代码
Commands 命令 ****
Overview 概览 ========
This list of commands is a work in progress. 对命令列表的整理仍在进行中。
About Paths in Command Arguments 关于命令参数中的路径信息 ================================
Some commands take paths as parameters. Among these, some support snippet-like syntax, while others don’t. A command of the first kind would take a parameter like ${packages}/SomeDir/SomeFile.Ext whereas a command of the second kind would take a parameter like Packages/SomeDir/SomeFile.Ext. 有些命令把路径作为参数。这些命令中,有些支持代码片段那样的语法,有些则不支持。第一中类型的命令 可以接受类似 ${packages}/SomeDir/SomeFile.Ext 这样的参数,而第二种类型的命令可以接受类似 Packages/SomeDir/SomeFile.Ext 这样的参数。
Generally, newer commands support the snippet-like syntax. 大体上来说,较新引入的命令支持类似代码片段的语法。
Often, relative paths in arguments to commands are assumed to start at the
Data
directory.
通常情况下,认为命令参数中的相对路径是相对与 数据
目录来说的。
Variables in Paths as Arguments 参数中路径包含的变量 ——————————-
The same variables available to build systems are expanded in arguments to commands. See build-system-variables for more information. 构建系统中使用的变量在参数中也可以使用。参考 构建系统变量 来了解更多信息。
Commands 命令列表 ========
- build
Runs a build system. 运行某个构件系统。
- variant [String]: Optional. The name of the variant to be run.
- variant [String]: 可选参数。要运行配置的名称。
- run_macro_file
Runs a .sublime-macro file. 运行一个 .sublime-macro 文件。
- file [String]: Path to the macro file.
- file [String]: 宏文件路径。
- insert_snippet
Inserts a snippet from a string or .sublime-snippet file. 从字符串或者 .sublime-snippet 文件中插入一个代码片段。
- contents [String]: Snippet as a string to be inserted.
- contents [String]: 要插入的代码片段的字符串内容。
- name [String]: Path to the .sublime-snippet file to be inserted.
- name [String]: 要插入的 .sublime-snippet 文件的路径。
- insert
Inserts a string. 插入一个字符串。
- characters [String]: String to be inserted.
- characters [String]: 要插入的字符串内容。
- move
Advances the caret by predefined units. 根据指定的单位移动光标。
- by [Enum]: Values: characters, words, word_ends, subwords, subword_ends, lines, pages, stops.
- by [Enum]: 可选值: characters, words, word_ends, subwords, subword_ends, lines, pages, stops 。
- forward [Bool]: Whether to advance or reverse in the buffer.
- forward [Bool]: 在缓冲区中向前或向后移动。
- word_begin [Bool]
- empty_line [Bool]
- punct_begin [Bool]
- separators [Bool]
- move_to
Advances the caret to predefined locations. 将光标移动到指定位置。
- to [Enum]: Values: bol, eol, bof, eof, brackets.
- to [Enum]: 可选值: bol, eol, bof, eof, brackets.
- extend [Bool]: Whether to extend the selection. Defaults to
false
. - extend [Bool]: 是否扩展选择内容。默认值是
false
。
- new_window
- Opens a new window. 打开一个新的窗口。
- close_window
- Closes the active window. 关闭当前活跃窗口。
- switch_file
Switches between two files with the same name and different extensions. 在有相同文件名、不同扩展名的两个文件之间进行切换。
- extensions [[String]]: Extensions (without leading dot) for which switching will be enabled.
- extensions [[String]]: 切换可以发生的文件扩展名(不包括点号)。
- close
- Closes the active view. 关闭当前视图。
- close_file
- Closes the active view and, under certain circumsances, the whole application. 关闭当前视图,在某些情况下关闭整个应用程序。 XXX Sounds kinda wrong. XXX 看上去好像不对。
- toggle_sidebar
- Shows or hides the sidebar. 开启或关闭侧边栏。
- toggle_full_screen
- Toggles full screen mode on or off. 开启或退出全屏模式。
- toggle_distraction_free
- Toggles distraction free mode on or off. 开启或退出免打扰模式。
- left_delete
- Deletes the character right before the caret. 删除光标前的那个字符。
- right_delete
- Deletes the character right after the caret. 删除光标后的那个字符。
- undo
- Undoes the latest action. 撤销上次操作。
- redo
- Reapplies the latest undone action. 重做上次撤销的操作。
- redo_or_repeat
- Performs the latest action again. 再次执行上次的动作。
- soft_undo
- Undoes each action stepping through granular edits. 先移动到编辑位置再进行撤销操作。
- soft_redo
- Redoes each action stepping through granular edits. 先移动到编辑位置再进行重做操作。
- cut
- Removes the selected text and sends it to the system clipboard. Put differently, it cuts. 把当前选中的文字从缓冲区中移除,并送到系统剪贴板中。换句话说,执行剪切操作。
- copy
- Sends the selected text to to the system clipboard. 把当前选中的文字送到系统剪贴板中。
- paste
- Inserts the clipboard contents after the caret. 把剪贴板中的内容插入到光标后。
- paste_and_indent
- Inserts the clipboard contents after the caret and indents contextually. 把剪贴板中的内容插入到光标后同时根据上下文进行缩进。
- select_lines
Adds a line to the current selection. 在当前选择的内容中添加一行。
- forward [Bool]: Whether to add the next or previous line. Defaults to
true
. - forward [Bool]: 添加下一行还是上一行。默认值是
true
。
- forward [Bool]: Whether to add the next or previous line. Defaults to
- scroll_lines
Scrolls lines in the view. 在视图中滚动行。
- amount [Float]: Positive values scroll lines down and negative values scroll lines up.
- amount [Float]: 正值向下滚动,负值向上滚动。
- prev_view
- Switches to the previous view. 切换到上一个视图。
- next_view
- Switches to the next view. 切换到下一个视图。
- next_view_in_stack
- Switches to the most recently active view. 切换到最近的活跃视图。
- previous_view_in_stack
- Switches to the view that was active before the most recently active view. I don’t think this is very clear or even true. 切换到最近活跃视图的前一个活跃视图。我不认为这种说法非常确切,这么说甚至是不正确的。
- select_all
- Select the view’s content. 选择视图的全部内容。
- split_selection_into_lines
- Unsurprisingly, it splits the selection into lines. 不出所料的,把当前的选择切散成不同行。
- single_selection
- Collapses multiple selections into a single selection. 把多重选择整合成单一选择。
- clear_fields
- Breaks out of the active snippet field cycle. 跳出活跃代码片段域的选择。
- hide_panel
Hides the active panel. 隐藏当前活跃面板。
- cancel [Bool]: Notifies the panel to restore the selection to what it
was when the panel was opened. (Only incremental find panel.) - cancel [Bool]: 当面板打开的时候恢复它之前选择的内容。(仅对增量搜索面板有效。)
- hide_overlay
- Hides the active overlay. Show the overlay using the show_overlay command. 隐藏覆盖控件。使用 show_overlay 命令打开覆盖控件。
- hide_auto_complete
- Hides the auto complete list. 隐藏自动补全列表。
- insert_best_completion
Inserts the best completion that can be inferred from the current context. XXX Probably useless. XXX 插入根据当前上下文能推断出的最佳补全内容。 XXX 可能没什么用。 XXX
- default [String]: String to insert failing a best completion.
- default [String]: 当没有找到最佳补全内容时插入的字符串。
- replace_completion_with_next_completion
- XXX Useless for users. XXX XXX 对用户来说没什么用。 XXX
- reindent
XXX ??? XXX
(译者注:重新进行缩进操作,常用于整理文件缩进。)
- indent
- Increments indentation. 增加缩进。
- next_field
- Advances the caret to the text snippet field in the current snippet field cycle. 将光标移动到下一个代码片段中的可修改区域。
- prev_field
- Moves the caret to the previous snippet field in the current snippet field cycle. 将光标移动到上一个代码片段中的可修改区域。
- commit_completion
- Inserts into the buffer the item that’s currently selected in the auto complete list. XXX Probably not useful for users. XXX 向缓冲区中插入自动补全列表中当前选中项的内容。 XXX 对用户来说没很么用。 XXX
- unindent
- Unindents. 取消缩进。
- toggle_overwrite
- Toggles overwriting on or off. 开启关闭覆盖插入选项。
- expand_selection
Extends the selection up to predifined limits. 将选择内容扩展到预定义的边界。
- to [Enum]: Values: bol, hardbol, eol, hardeol, bof, eof, brackets, line.
- to [Enum]: 可选值: bol, hardbol, eol, hardeol, bof, eof, brackets, line.
- find_under_expand
- Adds a new selection based on the current selection or expands the selection to the current word. 根据当前选中的内容增加一个新的选择或者把选择项扩展到当前单词。
- close_tag
- Surrounds the current inner text with the appropiate tags. 为当前内部文本添加适当的标签。
- toggle_record_macro
- Starts or stops the macro recorder. 开始或关闭宏录制器。
- run_macro
- Runs the macro stored in the macro buffer. 运行宏缓冲区中存储的宏脚本。
- show_overlay
Shows the requested overlay. Use the hide_overlay command to hide it. 显示请求的覆盖控件。使用 hide_overlay 命令来隐藏覆盖控件。
- overlay [Enum]:
The type of overlay to show. Possible values: 要显示的覆盖控件的类型。可选值:
- goto: Show the Goto Anything overlay.
- goto: 显示 Goto Anything(快速跳转) 覆盖控件。
- command_palette: Show the command palette.
- command_palette: 显示 命令面板.
show_files [Bool]: If using the goto overlay, start by displaying files rather than an empty widget.
show_files [Bool]: 如果显示快速跳转面板,开始的时候显示文件列表,而不是显示一个空的控件。
text [String]: The initial contents to put in the overlay.
text [String]: 放到覆盖控件中的初始值。
- show_panel
Shows a panel. 显示面板。
- panel [Enum]: Values: incremental_find, find, replace, find_in_files, console
- panel [Enum]: 可选值: incremental_find, find, replace, find_in_files, console
- reverse [Bool]: Whether to search backwards in the buffer.
- reverse [Bool]: 在缓冲区中是否后向搜索内容。
- toggle [Bool]: Whether to hide the panel if it’s already visible.
- toggle [Bool]: 当面板已经可见时,是否隐藏面板。
- find_next
- Finds the next occurrence of the current search term. 找到当前搜索内容的下一个匹配项。
- find_prev
- Finds the previous occurrence of the current search term. 找到当前搜索内容的上一个匹配项。
- find_under
- Finds the next occurrence of the current selection or the current word. 找到与当前选中内容或光标所在位置档次匹配的下一个内容。
- find_under_prev
- Finds the previous occurrence of the current selection or the current word. 找到与当前选中内容或光标所在位置档次匹配的上一个内容。
- find_all_under
- Finds all occurrences of the current selection or the current word. 选中与当前选择内容或光标所在位置单词匹配的所有内容。
- slurp_find_string
- Copies the current selection or word into the “find” field of the find panel. 复制当前选中内容或当前单词到搜索面板中的 “find” 域。
- slurp_replace_string
- Copies the current selection or word into the “replace” field of the find and replace panel. 复制当前选中内容或当前单词到搜索域替换面板中的 “replace” 域。
- next_result
- Advance to the next captured result. 移动到下一个搜索到的结果。
- prev_result
- Move to the previous captured result. 移动到上一个搜索到的结果。
- toggle_setting
Toggles the value of a boolean setting. 修改布尔型设置项的值。
- setting [String]: The name of the setting to be toggled.
- setting [String]: 要修改的设置项的名称。
- next_misspelling
- Advance to the next misspelling 移动到下一个错误拼写的单词的位置。
- prev_misspelling
- Move to the previous misspelling. 移动到上一个错误拼写的单词的位置。
- swap_line_down
- Swaps the current line with the line below. 交换当前行与下一行。
- swap_line_up
- Swaps the current line with the line above. 交换当前行与上一行。
- toggle_comment
Comments or uncomments the active lines. 为当前行添加或取消注释。
- block [Bool]: Whether to use a block comment.
- block [Bool]: 是否使用块注释。
- join_lines
- Joins the current line with the next one. 把当前行与下一行连接起来。
- duplicate_line
- Duplicates the current line. 重复当前行内容。
- auto_complete
- Opens the auto comeplete list. 打开自动补全列表。
- replace_completion_with_auto_complete
- XXX Useless for users. XXX XXX 对用户来说没什么用。 XXX
- show_scope_name
- Shows the name for the caret’s scope in the status bar. 在状态栏中显示光标所在作用域的名称。
- exec
Runs an external process asynchronously. 异步运行一个外部进程。
XXX Document all options. XXX 为所有选项添加文档。
- transpose
- Makes stuff dance. 移动内容。
- sort_lines
Sorts lines. 对行进行排序。
- case_sensitive [Bool]: Whether the sort should be case sensitive.
- case_sensitive [Bool]: 排序时是否考虑大小写。
- set_layout
- XXX
- focus_group
- XXX
- move_to_group
- XXX
- select_by_index
- XXX
- next_bookmark
- Select the next bookmarked region. 选择下一个被标记的区域。
- prev_bookmark
- Select the previous bookmarked region. 选择上一个被书签标记的区域。
- toggle_bookmark
- Sets or unsets a bookmark for the active region(s). (Bookmarks can be
accessed via the regions API using
"bookmarks"
as the key.) 对活跃区域设置书签或取消书签。(在区域API中使用"bookmarks"
作为键可以访问书签内容。) - clear_bookmarks
- Removes all bookmarks. 清楚所有书签。
- select_all_bookmarks
- Selects all bookmarked regions. 选择所有被书签标记过的区域。
- wrap_lines
Wraps lines. By default, it wraps lines at the first ruler’s column. 环绕行。默认情况下,在第一个标尺所在的列进行环绕。
- width [Int]: Specifies the column at which lines should be wrapped.
- width [Int]: 设置环绕开始的列坐标。
- upper_case
- Makes the selection upper case. 把选择的内容改成大写。
- lower_case
- Makes the selection lower case. 把选择的内容改成小写。
- set_mark
- XXX
- select_to_mark
- XXX
- delete_to_mark
- XXX
- swap_with_mark
- XXX
- yank
- XXX
- show_at_center
- XXX
- increase_font_size
- Increases the font size. 增加字体大小。
- decrease_font_size
- Decreases the font size. 较少字体大小。
- fold
- XXX
- unfold
- XXX
- fold_by_level
- XXX
- context_menu
- Shows the context menu. 显示上下文菜单。
Keyboard Shortcuts - Windows/Linux Windows/Linux平台快捷键 ==================================
Warning
This topic is a draft and may contain wrong information.
Editing 编辑 ——-
Navigation/Goto Anywhere 导航/快速跳转 ————————
General 通用快捷键 ————————
Find/Replace 查找/替换 ————————
Tabs 标签页 ————————
Split window 分割窗口 ————————
Bookmarks 书签 ————————
Text manipulation 文本操作 ————————
Keyboard Shortcuts - OSX OSX平台快捷键 ==================================
Warning
This topic is a draft and may contain wrong information.
Editing 编辑 ——-
Navigation/Goto Anywhere 导航/快速跳转 ————————
General 通用快捷键 ————————
Find/Replace 查找/替换 ————————
Tabs 标签页 ————————
Split window 分割窗口 ————————
Bookmarks 书签 ————————
Text manipulation 文本操作 ————————
词汇表¶
- buffer
缓冲区 - Data of a loaded file and additional metadata. Associated with one or more views. The distinction between buffer and view is technical. Most of the time, both terms can be used interchangeably. 存放已经加载文件的内容以及文件元数据的区域称为缓冲区。缓冲区一般与一个或多个视图相关联。 缓冲区 与 视图 只有一些细节上的差别。大多数情况下这两个术语是可以混用的。
- view
视图 - Graphical display of a buffer. Multiple views can show the same buffer. 显示缓冲区内容的图形区域。多个不同的视图可以显示同一块缓冲区内容。
- plugin
插件 - A feature impemented in Python. It can consist of a single command or multiple commands. It can be contained in one .py file or many .py files. 使用Python实现的一个功能称为插件。它可以包含一个或多个命令。它可以由一个或多个 .py 文件组成。
- package
包 - This term in ambiguous in the context of Sublime Text, because it can
refer to a Python package (unlikely), a directory inside
Packages
or a .sublime-package file. Most of the time, it means a directory insidePackages
containing resources that belong together to build a new feature or provide support for a programming or markup language. 在Sublime Text中这个术语的意义有点模糊,它可以指一个Python包(这种用法很少),或者 是Packages
目录下的一个文件夹,亦或是一个 .sublime-package 文件。大多数情况下, 包指的是Packages
目录下的一个文件夹,这个文件夹中包含为某个特性或者某种语言服务的各 种资源。 译者注: Packages 目录保存在Sublime Text的安装目录中 - panel
面板 - An input/output widget such as a search panel or the output panel. 像搜索或者输出这样的,用于进行输入/输出的窗体控件称为面板。
- overlay
覆盖层控件 - An input widget of a special kind. Goto Anything is an overlay. 一种特殊的输入控件。快速跳转就是一种覆盖层控件。