ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 快速不全 Completions 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. * * * * * # Tab Completion ### Overview `Tab` Completion allows quickly completing words by pressing the tab key. When enabled, pressing tab will expand the text to the left of the cursor into the best match, using Sublime Text's fuzzy matching algorithm. `Tab` Completion is enabled by default. **Disabling Tab Completion** Sometimes `tab` completion isn't desirable. To turn it off, add this line to `Preferences/File Settings - User`: ~~~ "tab_completion": false ~~~ ### Inserting Literal Tabs To insert a tab rather than a completion, press shift+tab. ### Changing the Completion Sometimes the completed text isn't what's desired: to change to an alternative, press ctrl+space. This will roll back the completion, and display the standard auto complete list. Alternatively, tab can be pressed again to cycle to the next completion. ### Completion Sources Information on completion sources, and creating your own completions, is available at sublimetext.info.