Sublime Forum

How to add snippets triggered by special characters (such as . or =)

#1

I’d like to trigger a snippet by pressing tab after typing special characters, such as . or =. However, putting them as the trigger doesn’t seem to work.

I can do this in Atom, but it doesn’t work for Sublime Text :frowning:. Is there a way to make this work?

0 Likes

#2

Triggers are controlled by settings in ST. I added the following snippet to my Preferences.sublime-settings to enable completions triggering with . in source code.

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

You can modify the “selector” to enable certain trigger characters for single languages or place this snippet into syntax-specific settings files.

Here is another example I use for auto-completion of .gitattributes in https://github.com/deathaxe/Packages/tree/pr/add_git_files/Git%20Files

    "auto_complete_triggers": [
        {
            "selector": "meta.attributes-list.git.attributes - meta.attribute - punctuation.separator",
            "characters": " -!"
        },
        {
            "selector": "meta.attribute.builtin & meta.mapping.expect-value.git.attributes",
            "characters": "-=,"
        }
    ],
0 Likes

#3

you can work round it by using keybindings to trigger the snippet

1 Like

#4

Thanks for the reply! I don’t think it worked for me, but I actually tried creating a snippet instead of a completion with ., and it worked perfectly.

@kingkeith Thanks for the link! It gave me the inspiration I needed.

1 Like

#5

You can use backslash before special character. Example: this.\$log.inf();

0 Likes