配置

Sublime Text在.sublime-settings文件中存储的数据。 以稍微复杂地设置配置的代价实现了灵活性。当然,有一条黄金原则:

永远把你个人的配置文件放在Packages/User下来保证他们将会优先覆盖其他冲突的配置文件。

有了这样的方式,让我们来揭开的奥秘,如何设置工作,满足自虐的读者。

格式

配置文件使用JSON并且以.sublime-settings为扩展名。

配置的类型

每个.sublime-settings文件的用途有它的名字决定了。这些名字可以是描述性的(像Preferences (Windows).sublime-settingsMinimap.sublime-settings), 也可以是和它所控制的相关。举个例子,用来加载与.tmLanguage语法定义文件类型同名的文件类型的配置文件。因此对于 .py文件类型, 它的语法定义在Python.tmLanguage中, 它相关的配置文件就会是Python.sublime-settings

当然,一些配置文件只适用于指定平台。这个可以通过文件名识别: Preferences (Windows).sublime-settings, Preferences (Linux).sublime-settings, 等等。

这是很重要的: 位于Packages/User目录的特定平台的配置文件 将被忽略。 通过这种方式,你可以确保一个配置文件覆盖其他所有的配置。

如何编辑普通的配置文件

除非你想要通过配置文件实现粒度非常细的控制,你可以访问主要的配置文件通过Preferences | Settings - UserPreferences | Settings - More 菜单项目。修改Preferences - Settings Default不是一件明智的事情,因为每次升级软件它都会被覆盖。然而你可以把它当做参考:它包含了解释所有全局和文件类型配置的注释。

.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.

Let us remember again that any given settings file in Packages/User ultimately overrides every other settings file of the same name.

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.

To check the value of a setting in effect for a particular file, use view.settings().get(<setting_name>) from the console.

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:

  • 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.

Valid names for <platform> are 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.

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.

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.

Also, let us emphasize that under Pakages/User only Python.sublime-settings would be read, but not any Python (<platform>).sublime-settings variant.

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.