Настраиваем sublime text 3
Содержание:
Class sublime.Settings
Methods | Return Value | Description |
---|---|---|
get(name) | value | Returns the named setting. |
get(name, default) | value | Returns the named setting, or default if it’s not defined. |
set(name, value) | None | Sets the named setting. Only primitive types, lists, and dictionaries are accepted. |
erase(name) | None | Removes the named setting. Does not remove it from any parent Settings. |
has(name) | bool | Returns true iff the named option exists in this set of Settings or one of its parents. |
add_on_change(key, on_change) | None | Register a callback to be run whenever a setting in this object is changed. |
clear_on_change(key) | None | Remove all callbacks registered with the given key. |
Automatic Indentation
Automatic indentation guesses the amount of leading whitespace to insert on each line when you press enter. It’s controlled with these settings:
auto_indent | Boolean, enabled by default. Enables auto indent |
smart_indent | Boolean, enabled by default. Makes auto indent a little smarter, e.g., by indenting the next line after an if statement in C. |
trim_automatic_white_space | Boolean, enabled by default. Trims white space added by auto_indent when moving the caret off the line. |
indent_to_bracket |
Boolean, disabled by default. Adds whitespace up to the first open bracket when indenting. Use when indenting like this: |
Settings
Settings are accessed via the Preferences Settings menu item. The left-hand pane contains all of the default settings, along with a description of each. The right-hand pane is where customization can be saved.
Categories
The settings in Sublime Text are organized into three categories. The default settings file organizes the settings into sections for easier distinction.
- Editor Settings: These settings affect the behavior and functionality presented when editing text in a file. Examples include the font_face, tab_size and spell_check. These settings are presented in the first section of the default settings file.
- User Interface Settings: These settings affect the general user interface, across all open windows. Examples include the theme, animation_enabled and overlay_scroll_bars. These settings are presented in the second section of the default settings file.
- Application Behavior Settings: These settings affect the behavior of the application, across all open windows. Examples include the hot_exit, index_files and ignored_packages. These settings are presented in the third section of the default settings file.
The User Interface Settings and Application Behavior Settings are global to the entire application and can not be controlled by a syntax specific settings file, nor the settings key in a .sublime-project.
Settings Files
Settings files are consulted in this order:
- Packages/Default/Preferences.sublime-settings
- Packages/Default/Preferences (<platform>).sublime-settings
- Packages/User/Preferences.sublime-settings
- <Project Settings>
- Packages/<syntax>/<syntax>.sublime-settings
- Packages/User/<syntax>.sublime-settings
- <Buffer Specific Settings>
In general, you should place your settings in Packages/User/Preferences.sublime-settings, which is opened in the right-hand pane when selecting the menu item Preferences Settings. If you want to specify settings for a certain file type, for example, Python, you should place them in Packages/User/Python.sublime-settings. This can be accessed via the right-hand pane when a Python file is open, and the menu item Preferences Settings – Syntax Specific is selected.
Syntax Specific Settings
Settings may be specified on a per-syntax basis. Common uses for this are to have different indentation settings or the color scheme vary by file type.
You can edit the settings for the syntax of the current file by selecting the Preferences Settings – Syntax Specific menu item.
Note that only Editor Settings can be specified in syntax specific settings.
Per-project Settings
Settings can be set on a per-project basis, details are in the Project Documentation.
Note that only Editor Settings can be specified in project settings.
Distraction Free Settings
Distraction Free Mode has an additional settings file applied (Distraction Free.sublime-settings). You can place file settings in here to have them only apply when in Distraction Free Mode – access it from the Preferences Settings – Distraction Free menu item.
Changing Settings with a Key Binding
The toggle_setting command can be used to toggle a setting. For example, to make a key binding that toggles the word_wrap setting on the current file, you can use (in Preferences Key Bindings):
The set_setting command can be used to set a setting to a specific value. For example, this key binding makes the current file use the Cobalt color scheme:
The settings modified here are buffer specific settings: they override any settings placed in a settings file, but apply to the current file only.
Troubleshooting
As settings can be specified in several different places, sometimes in can be helpful to view the applied setting that’s actually being used by the current file. You can do this by using the console:
Selected Examples
Advanced Stack Usage
In C, symbols are often defined with the typedef keyword. So that Goto Definition can pick these up, the symbols should have the entity.name.type scope attached to them.
Doing this can be a little tricky, as while typedefs are sometimes simple, they can get quite complex:
To recognise these, after matching the typedef keyword, two contexts will be pushed onto the stack: the first will recognise a typename, and then pop off, while the second will recognise the introduced name for the type:
In the above example, typename is a reusable context, that will read in a typename and pop itself off the stack when it’s done. It can be used in any context where a type needs to be consumed, such as within a typedef, or as a function argument.
The main context uses a match pattern that pushes two contexts on the stack, with the rightmost context in the list becoming the topmost context on the stack. Once the typename context has popped itself off, the typedef_after_typename context will be at the top of the stack.
Also note above the use of anonymous contexts for brevity within the typename context.
PHP Heredocs
This example shows how to match against in PHP. The match pattern in the main context captures the heredoc identifier, and the corresponding pop pattern in the heredoc context refers to this captured text with the \1 symbol:
Class sublime_plugin.EventListener
Methods | Return Value | Description |
---|---|---|
on_new(view) | None | Called when a new buffer is created. |
on_clone(view) | None | Called when a view is cloned from an existing one. |
on_load(view) | None | Called when the file is finished loading. |
on_close(view) | None | Called when a view is closed (note, there may still be other views into the same buffer). |
on_pre_save(view) | None | Called just before a view is saved. |
on_post_save(view) | None | Called after a view has been saved. |
on_modified(view) | None | Called after changes have been made to a view. |
on_selection_modified(view) | None | Called after the selection has been modified in a view. |
on_activated(view) | None | Called when a view gains input focus. |
on_deactivated(view) | None | Called when a view loses input focus. |
on_query_context(view, key, operator, operand, match_all) | bool or None |
Called when determining to trigger a key binding with the given context key. If the plugin knows how to respond to the context, it should return either True of False. If the context is unknown, it should return None. operator is one of:
match_all should be used if the context relates to the selections: does every selection have to match (match_all = True), or is at least one matching enough (match_all = Fals)? |
Scope Rules
Color schemes interact with the text in a file via scopes. Scopes are set
to code or prose tokens via the syntax. Scopes are dotted strings,
specified from least-to-most specific. For example, the
keyword in PHP could be specified via the scope name
.
Matching
Color schemes apply colors and font styles to the scopes by matching the
dotted labels, starting with the first. Prefix matching is the standard
way to have a color scheme apply to multiple syntaxes. Instead of matching
, most color schemes will instead assign
a color to . Matching the first one or two labels
in a scope is most common. Including the final label, the syntax name, is
uncommon unless a syntax-specific override is desired.
Naming
Author of syntaxes can assign whatever scopes they want to a given token.
This combined with the fact that there are hundreds of community-maintained
syntaxes means that is can be hard to know what scopes to target. The
official Scope
Naming guidelines were established to help syntax and color scheme
authors use a common set, for better interoperability. The
section provides a baseline set of scopes that color
scheme authors should strive to handle.
Style Rules
Each scope style rule consists of an object containing a
key, along with one or more of the following optional keys:
- – the (arbitrary) name for the scope rule
- – the text color
- – the background color
- – adjustment to the color, only valid with
- – the text color when selected
- – zero or more of , , separated by spaces
The key accepts a space-separated
list of adjusters that are supported by the
. It is only supported when the
key is also specified, and thus allows
modifying all foregrounds used in combination with the background,
without having to create different rules for every permutation.
Hashed Syntax Highlighting
The key supports a special mode called
Hashed Syntax Highlighting, where each token matching the scope
specified will receive a unique color from one, or more, gradients.
Some editors refer to this style of highlighting as
«Semantic Highlighting».
To use Hashed Syntax Highlighting, the key
must have a value that is a list of two or more colors. Sublime Text
will create 256 different colors that are linear interpolations
(lerp) between the colors provided. The interpolation is done in
HSL space.
As Sublime Text highlights the tokens in a file, it will create a
hashed value of the token, and use that to pick one of the 256
linear interpolations. Every instance of a given token will use the
same color. For instance, each instance of
would have the same color, but every instance of
would have a different color.
For Hashed Syntax Highlighting to be most obvious, the hue
difference between the start and end points should be as far apart
as possible. Here is an example of using blues, purples and pinks
for variable names:
Global Settings
The following global settings go in the object with the
key.
- background
- The default background color
- foreground
- The default color for text
- invisibles
-
The color for whitespace, when rendered. When not specified,
defaults to with an opacity of
. - caret
- The color of the caret
- block_caret
- The color of the caret when using a block caret
- line_highlight
-
The background color of the line containing the caret. Only used
when the setting is enabled.
Accents
- misspelling
-
The color to use for the squiggly underline drawn under
misspelled words. - fold_marker
-
The color to use for the marker that indicates content has
been folded. - minimap_border
-
The color of the border drawn around the viewport
area of the minimap when the setting
is enabled. Note
that the viewport is normally only visible on
hover, unless the
setting is enabled. - accent
-
A color made available for use by the theme. The Default
theme uses this to highlight modified tabs when the
setting is enabled.
CSS
CSS is applied to minihtml content
created via the popups and phantoms functionality that is exposed
through the API. Supported CSS properties are discussed in the
.
Plugins that use minihtml are encouraged to set a unique
attribute on the tag of generated HTML
to allow color schemes to override default plugin styles.
- popup_css
- CSS passed to popups.
- phantom_css
-
CSS passed to phantoms. If not specified, uses
.
Diff
The diff functionality is displayed in the gutter as colored lines
for added and modified lines, and a triangle where lines were
deleted.
- line_diff_width
- The width of the diff lines, between 1 and 8
- line_diff_added
- The color of diff markers for added lines
- line_diff_modified
- The color of diff markers for modified lines
- line_diff_deleted
- The color of diff markers for deleted lines
Selection
- selection
- The background color of selected text
- selection_foreground
-
A color that will override the scope-based text color
of the selection - selection_border
- The color for the border of the selection
- selection_border_width
-
The width of the selection border, from to
. - inactive_selection
-
The background color of a selection in a view that
is not currently focused - inactive_selection_foreground
-
A color that will override the scope-based text color
of the selection in a view that is not currently focused - selection_corner_style
-
The style of corners to use on selections. Options include:
(the default), or
. - selection_corner_radius
-
The radius to use when the
is or .
Find
- highlight
-
The border color for «other» matches when the
Highlight matches option is selected
in the Find panel. Also used to highlight matches
in Find in Files results. - find_highlight
- The background color of text matched by the Find panel
- find_highlight_foreground
-
A color that will override the scope-based text color
of text matched by the Find panel
Guides
Guides are controlled globally by the
setting.
- guide
-
The color used to draw indent guides. Only used if
the option is present in
the setting . - active_guide
-
The color used to draw the indent guides for the
indentation levels containing the caret. Only used
if the option is present in
the setting . - stack_guide
-
The color used to draw the indent guides for the
parent indentation levels of the indentation level
containing the caret. Only used if the option
is present in
the setting .
Brackets
Bracket matching is controlled globally by the
setting.
- brackets_options
-
How brackets are highlighted when the caret is next to
one. Accepts a space-separated list from the following: - brackets_foreground
-
The color to use when drawing the style specified by
. - bracket_contents_options
-
How brackets are highlighted when the caret is
positioned in between a pair of brackets. Accepts a
space-separated list from the following: - bracket_contents_foreground
-
The color to use when drawing the style specified by
.
Tags
Tag matching is controlled globally by the
setting.
- tags_options
-
How tags are highlighted when the caret is inside of
one. Accepts a space-separated list from the following: - tags_foreground
-
The color to use when drawing the style specified by
.
CSS
The following list provides an overview of supported properties and
values:
-
: ,
, , -
: positive
: positive
: positive
: positive
: positive - : ,
-
: positive and negative
: positive and negative
: positive and negative
: positive and negative -
:
comma-separated list of font families: positive
: ,
: ,
: positive
: , -
: positive
: positive
: positive
: positive
: positive -
: positive
||
||
: positive
||
||
: positive
||
||
: positive
||
||
: positive
||
|| -
: ,
:
:
:
: -
: positive
: positive
: positive
: positive
: positive -
:
:
:
:
: -
: positive
: positive
: positive
: positive
: positive
Units
Supported units of measurement include:
units are recommended because they are based on the
user’s setting, and they will not cascade.
Colors
Colors may be specified via:
- Named colors: , , etc
- Shorthand hex:
- Shorthand hex with alpha:
- Full hex:
- Full hex with alpha:
- RGB functional notation:
- RGBA functional notation:
- HSL functional notation:
- HSLA functional notation:
Mod Function
Additionally, color values may be modified using the CSS Color Module Level 4 with the following adjusters:
The color-mod function will be most useful in combination with .
Variables
CSS variables are also supported using custom properties and the functional notation. Custom properties are those starting with .
The one limitation is that the notation can not be used for part of a multi-number value, such as or . With those aggregate properties, the notation must be used for the complete value.
Predefined Variables
When a color scheme is loaded, the background and foreground colors are set to CSS variables, along with the closest color found to a handful of basic colors. These are all set in an rule set in the default CSS style sheet.
The algorithm to pick the colors uses the HSL color space and uses several heuristics to try and pick colors that are suitable for foreground use. In the case that the automatic color selection is undesirable, color scheme authors may override the appropriate values with their own rule set contained in the
or settings.
Преимущества и недостатки Sublime Text
Преимущества
Sublime Text — это легкий текстовый редактор, который подойдет любому программисту. Программа сделана со скоростью, находящейся в ее основе. Особенность программы в ее скорости и отзывчивости пользовательского интерфейса.
В редакторе доступно множество плагинов, которые интегрируются в одном месте.
Полностью настраиваемый — текстовый редактор создан, чтобы позволить конечному пользователю легко «поиграть» с ПО на свой лад. Sublime позволяет настраивать множество функций, включая: привязки клавиш, меню, фрагменты, макросы и многие другие. Кроме того, изменяйте внешний вид, настроив свои темы для ПО.
Кроссплатформенная поддержка — в редакторе доступна на большинстве распространенных настольных клиентов, включая Windows, macOS и Linux.
Sublime с открытым исходным кодом, соответственно бесплатный. Но в то же время, ПО также можно купить – по желанию
Важно отметить, что бесплатная версия работает просто отлично.
С редактором, вы можете комфортно переключаться между различными файлами. К тому же, благодаря функции Goto Anything, доступ к которой получаете непосредственно с клавиатуры с помощью клавиш Ctrl или Command + P.
Простота в использовании
Редактор подходит для любого пользователя, независимо от уровня его опыта.
Недостатки
При поддержке плагинов, к сожалению, некоторые их них в редакторе все еще глючат. Необходимо требовательно подходить к выбору плагинов
Properties
The key of a file
is a JSON array of of objects describing how UI elements should be
styled. Every element in the UI supports the following keys:
- layer0.*
-
the bottom-most texture
for the element - layer1.*
-
the second texture
for the element - layer2.*
-
the third texture
for the element - layer3.*
-
the fourth texture
for the element - hit_test_level
-
a float value setting the required opacity
of a pixel for a click to be considering a «hit»
Layer Properties
Every element in the UI supports up to four texture layers for
displaying fill colors and raster graphics. Each layer has dotted
sub-keys in the format
. Valid sub-keys
include:
- layer#.opacity
-
a float value from to that
controls the master opacity of the layer.Example:
- layer#.tint
-
a of a fill color to apply to the layer.
Example:
- layer#.texture
-
a string of the file path to a PNG
image, relative to the folder.Example:
- layer#.inner_margin
-
texture images are stretched to fit the element by slicing
into a grid of 9 using four lines. See
for valid
formats with which to specify the margin used to make the
slices.Example:
- layer#.draw_center
-
a boolean that controls if the center rectangle of the
9-grid created via
should be drawn. This is an optimization that allows skipping
an unused section of texture.Example:
- layer#.repeat
-
a boolean that controls if the
texture should be repeated instead of stretched.Example:
Value Animation
Properties specified by floats may be animated over time. Instead of
providing a single numeric value, the animation is specified with an
object including details of the animation. Value animation is
primarily useful for changing opacity over time. The object keys
are:
- target
-
a float value from
to that controls the destination valueExample:
- speed
-
a float value of or greater that
controls the relative length of time the animation takesExample:
- interpolation
-
an optional string that allow specifying the use of
function instead of the default
linear function.Default:
Example:
Texture Animation
The sub-key may be an object to
specify an animation based on two or more PNG images. The object keys are:
- keyframes
-
an array of strings of the paths to PNG images,
in orderExample:
- loop
-
an optional boolean that controls if the animation
should repeatDefault:
Example: - frame_time
-
an optional float specifying how long each
frame should be displayed. represents 1 second.Default: (30 fps)
Example: (60 fps)
Texture Tinting Properties
Certain elements have an available tint value set by the background of
current color scheme. The tint can be modified and applied to a
image.
- tint_index
-
Controls which layer the tint is applied to.
Must be an integer from to . - tint_modifier
-
An array of four integers in the range to
. The first three are blended into the
RGB values from the tint color with the fourth value
specifying how much of these RGB modifier values to apply.
Font Properties
Certain textual elements allow setting the following font properties:
- font.face
- the name of the font face
- font.size
- an integer point size
- font.bold
- a boolean, if the font should be bold
- font.italic
- a boolean, if the font should be italic
Shadow Properties
Some text elements allow setting the following properties:
- shadow_color
- a to use for the text shadow
- shadow_offset
-
a 2-element array containing the X and Y offsets of
the shadow
Filter Label Properties
Labels used in the quick panel have color control based
on selection and matching
- fg
-
a for
unselected, unmatched text - match_fg
- a for unselected, matched text
- bg
-
a for
the background of an unselected row - selected_fg
- a for selected, unmatched text
- selected_match_fg
- a for selected, matched text
- bg
-
a for
the background of a selected row - font.face
- the name of the font face
- font.size
- an integer point size
Data Table Properties
Row-based tables of data provide the following properties:
- dark_content
-
if the background is dark – used
to set the attribute for scrollbars - row_padding
-
padding added to each row, in
one of the formats described in
Certain labels allow for additional control over their appearance.
They support the properties:
Testing
When building a syntax definition, rather than manually checking scopes with the show_scope_name command, you can define a syntax test file that will do the checking for you:
To make one, follow these rules
- Ensure the file name starts with syntax_test_.
- Ensure the file is saved somewhere within the Packages directory: next to the corresponding .sublime-syntax file is a good choice.
- Ensure the first line of the file starts with: <comment_token> SYNTAX TEST "<syntax_file>". Note that the syntax file can either be a .sublime-syntax or .tmLanguage file.
Once the above conditions are met, running the build command with a syntax test or syntax definition file selected will run all the Syntax Tests, and show the results in an output panel. Next Result (F4) can be used to navigate to the first failing test.
Each test in the syntax test file must first start the comment token (established on the first line, it doesn’t actually have to be a comment according to the syntax), and then either a ^ or <- token.
The two types of tests are:
- Caret: ^ this will test the following selector against the scope on the most recent non-test line. It will test it at the same column the ^ is in. Consecutive ^s will test each column against the selector.
- Arrow: <- this will test the following selector against the scope on the most recent non-test line. It will test it at the same column as the comment character is in.
Settings
tab_size | Integer. The number of spaces a tab is considered equal to |
translate_tabs_to_spaces | Boolean, if true, spaces will be inserted up to the next tab stop when tab is pressed, rather than inserting a tab character |
detect_indentation | Boolean, if true (the default), tab_size and translate_tabs_to_spaces will be calculated automatically when loading a file |
use_tab_stops | Boolean, If translate_tabs_to_spaces is true, use_tab_stops will make tab and backspace insert/delete up to the next tab stop |
Settings Files
Settings files are consulted in this order:
- Packages/Default/Preferences.sublime-settings
- Packages/Default/Preferences (<platform>).sublime-settings
- Packages/User/Preferences.sublime-settings
- Packages/<syntax>/<syntax>.sublime-settings
- Packages/User/<syntax>.sublime-settings
In general, you should place your settings in Packages/User/Preferences.sublime-settings. If you want to specify settings for a certain file type, for example, Python, you should place them in Packages/User/Python.sublime-settings.
Per-syntax Settings
Settings may be specified on a per-syntax basis. You can edit the settings for the current syntax using the Preferences Settings – Syntax Specific menu.