Перейти к содержимому

Как включить подсказки в sublime text

  • автор:

Как включить подсказки в sublime text

Sublime Text includes a few methods to save typing and time by finishing words or inserting boilerplate. Completions include the following sources:

Words from the current file

Context-aware suggestions 4050

Various settings exist to customize the behavior of completions. Users can write their own snippets or completions files, and many third-party packages exist to provide completions.

Usage��

By default, Sublime Text will automatically show the completions popup when a user is editing source code or markup, but not within prose in comments, strings or markups.

Pressing the Esc key will hide the completions popup. To manually show the completions popup, press Ctrl+Space . If no completions are available, the message No available completions will be displayed in the status bar.

Context-Aware Suggestions��

The completion engine in Sublime Text uses background processes to scan all of the files in a project to build a completion index. This index is used to provide suggested completions to the user, based on patterns in existing code.

If a property is frequently set to a boolean value, the suggestions will include true or false .

If an identifier is typically “called”, the name will be suggested with () appended.

The exact completions offered are based on various heuristics, and are derived from existing code in a project. Since completions are based on analysing existing code, words not used in a project will not be suggested.

Completion Metadata��

In addition to their textual contents, completions may also provide additional details to users. These include the kind of element the completion represents, a short annotation to help in picking a completion, and details that may contain links to additional resources.

Kind Info��

Completions may provide kind info to be presented with the completion trigger. This includes a high-level category, an identifying letter, and a name. The following are some of the most common kinds:

Icon Name
k Keyword
t Type
f Function
a Namespace
n Navigation
m Markup
v Variable
s Snippet

Both in this documentation and in Sublime Text, hovering the mouse over a kind letter will show a tooltip with the full name. The color of kind metadata is determined by the theme, and may not match what is shown above.

.sublime-completions files and plugins can use combinations of any category listed above, along with any Unicode character and name for a custom presentation.

Annotations��

Annotations are displayed on the right-hand edge of the completions popup, and may contain any information the author deems useful. Typically the annotations will be a word or two.

Details��

The details field of a completion may contain a rich text description with links. The details for a completion is shown at the bottom of the completions popup when the completion is selected.

Customization��

There exist a number of ways in which the engine can be augmented with new completions:

Completion Files��

The most basic form of adding completions to Sublime Text is by creating a .sublime-completions file. Completions files use the JSON format, and contain an object with the keys "scope" and "completions" .

The "scope" key’s value is a string containing a selector of the syntax the completions apply to. The "completions" value is an array of completions. Each entry in the array represents a single completion, and may be a string or an object.

Simple Format��

When a completion is a string, the string reprents both the trigger text and the completion contents.

A basic .sublime-completions file:

Rich Format��

When a completion is an object, the valid keys include:

"trigger" string (REQUIRED) ��

The text the user must enter to match the completion.

"contents" string (REQUIRED) ��

The contents that will be inserted into the file. Supports snippet fields and variables.

The annotation to display for the completion.

The kind metadata for the completion.

If the value is a string, it must be one of:

If the value is a 3-element array of strings, they must be:

A string from the list above, which is used by the theme to select the color of the kind metadata

A single Unicode character to be shown to the left of the trigger

A description of the kind, viewable in the kind letter tool tip, and the detail pane (when visible)

A single line description of the completion. May contain the following HTML tags for basic formatting:

Автокомплит

Каждый раз когда вы начинаете печатать, редактор анализирует набранный текст и предлагает наиболее релевантные варианты продолжения слова или функции в виде симпатичного выпадающего списка. По-умолчанию функция доступна для языков программирования и для HTML, если набранное слово начинается со скобки «<».

Отключение автокомплита

Для отключения автокомплита установите false для параметра auto_complete.

В этом случае выпадающий список перестанет появляться автоматически, но его все равно можно будет вызвать вручную, когда вам это потребуется. Также, нажатие табуляции приведет к выбору наиболее подходящего варианта.

Отображение автокомплита

Для того, чтобы вызвать подсказку вручную, нажмите ctrl space . Повторное нажатие приведет к выбору следующего в списке элемента.

Варианты срабатывания

По-умолчанию выбор в выпадающем списке происходит по нажатию на enter . Но в некоторых ситуациях, вместо комплита строки необходимо вставить перенос. Чтобы добавить однозначности своим действиям, вы можете воспользоваться параметром auto_complete_commit_on_tab. Если установить его значение как true, то автокомплит будет срабатывать только по нажатию табуляции. Enter будет работать как ему назначено природой.

Completions

In the spirit of IDEs, Sublime Text suggests completions that aggregate code or content while writing by catching everything that you have written, like variable names.

There are however several ways to extend the list of completions (for example, depending on the current syntax).

This topic deals with how completions are used and where they come from.

# How to Use Completions

There are two methods for using completions. Even though, when screening them, the priority given to completions always stays the same, the two methods produce different results.

Completions can be inserted in two ways:

  • through the completions list ( Ctrl ␣ ), or
  • by pressing ⭾ .

# The Completions List

To use the completions list:

  1. Press Ctrl ␣ or just type something.
  2. Optionally, press Ctrl ␣ again to select the next entry or use up and down arrow keys.
  3. Press ⏎ or ⭾ to validate selection (depending on the auto_complete_commit_on_tab setting).
  4. Optionally, press ⭾ repeatedly to insert the next available completion.

If the completions list was opened explicitly, the current selection in the completions list can also be validated with any punctuation sign that isn’t itself bound to a snippet (e.g. . ).

When the list of completion candidates can be narrowed down to one unambiguous choice given the current prefix, this one completion will be validated automatically the moment you trigger the completion list.

# Hints

Additionally, you may see a trigger hint on the right side of a completion’s trigger in the completions list. This can be used as a preview of the completion’s content.

image

The above is in fact a snippet and expands to $arrayName = array(» => , ); .

# Triggers and Contents

Completions not sourced from the text in the current file may provide a trigger that is different to the content they will insert if selected. This is commonly used for function completions where the content also includes the function’s signature.

For example, completing array_map from the PHP completions will result in array_map(, ) :

You may notice in the animation that the cursor automatically selected callback . This is because completions support the same features as snippets with fields and placeholders. For more details, refer to Snippet Features.

# Completions with multiple cursors

Sublime Text can also handle completions with multiple cursors but will only open the completion list when all cursors share the same text between the current cursor positions and the last word separator character (e.g. . or a line break).

Working example ( | represents one cursor):

Not working example:

Selections are essentially ignored, only the position of the cursor matters. Thus, e|[-some selection] example , with | as the cursor and [. ] as the current selection, completes to example|[-some selection] example .

# ⭾ -Completed Completions

If you want to be able to tab-complete completions, the setting tab_completion must be set to true (default). 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. This means, unlike the case of the completions list, that Sublime Text will always make the decision for you. The rules for selecting the best completion are the same as described above, but in case of ambiguity, Sublime Text will insert the item it deems most suitable. You can press the ⭾ key multiple times to walk through other available options.

# Inserting a Literal tab Character

When tab_completion is enabled, you can press ⇧ ⭾ to insert a literal tab character.

# Sources for Completions and their Priorities

These are the sources for completions the user can control, in the order they are prioritized:

Additionally, the following completions are folded into the final list:

  1. Words in the buffer

Snippets will always win when the current prefix matches their tab trigger exactly. For the rest of the completion sources, a fuzzy match is performed. Furthermore, snippets always lose in a fuzzy match.

When a list of completions is shown, snippets will still be listed alongside the other items, even if the prefix only partially matches the snippets’ tab triggers.

Completions sourced from words in the buffer can be suppressed explicitly from an on_query_completions event hook.

# Auto Completion Triggers and Selector

Sublime Text provides two settings for users and package authors to tweak their auto completion behavior. Both settings work independently of each other and either of them can trigger the auto-completion popup.

auto_complete_selector expects a scope selector that when matched causes the auto-completion popup to open for any non-punctuation character, i.e. for identifiers. The default configuration disables this for syntaxes with a focus on plain text, comments and strings.

Before 4070, the selector was applied to the position after the just-typed character.

auto_complete_triggers expects a list of mappings that may specify characters that should trigger the auto-completion popup and/or a scope selector . If both are provided, both are required to match.

Additionally, a rhs_empty boolean may be provided that states whether the right-hand side of the caret must be empty or a whitespace character. It defaults to false .

Package authors may be interested in configuring triggers and/or the selector in a syntax-specific settings file.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *