sublimetextsublime-text-plugin

How can I set the character "&" as a trigger for a sublime completions list?


I'm trying to make a .sublime-completions file where all the commands start with "&". The general format for this is:

        {
            "trigger": "&Command",
            "annotation": "basic function",
            "contents": "&Command",
            "kind": "function",
            "details": "Command description"
        },

The problem is that the trigger isn't picking up the & symbol so it'll only show after typing the first letter of the command (in this example, it's "C") and outputs an extra "&" symbol.

How can I get the "&" to be included with the trigger? I tried putting \ infront of the & symbol but that didn't work.


Solution

  • Open your preferences (Win/Lin - Preferences → Settings, Mac - Sublime Text → Preferences → Settings) and add the following:

    "auto_complete_triggers":
        [
            {
                "characters": "&",
                "selector": "source",
            }
        ]
    

    You can add additional scopes to "selector" to make it more specific. For example, if you only want this behavior in Javascript, you could change that line to "selector": "source.js". If you want it in JS and HTML, the value would become "source.js, text.html". To find the full scope at any point in a document, place your cursor and select Tools → Developer → Show Scope Name. The first line describes the document as a whole, and is generally all you need for this rule. However, feel free to make the rule as specific as you want.

    You may also want to remove & from the list of word separation characters. This means that when you double-click on a word starting with &, that character is selected along with the rest of the word.

    "word_separators": "./\\()\"'-:,.;<>~!@#$%^*|+=[]{}`~?"
    

    The settings file needs to be valid JSONC, meaning that comments are allowed, and each setting needs to be separated by a comma ,.