Search code examples
sublimetext2

Sublime text 2 Snippets - autocomplete


I've created a bunch of snippets in Sublime Text 2, but I cant remember them all off the top of my head. I've seen in a number of tutorials that as people start typing their snippets tab-triggers it will start to provide a list of the matching snippets. I don't see this.

Is there a setting somewhere for this? Or do I need to create a special file (completions file?). For most snippets I have the <scope> commented out as I may use in a PHP or HTML file for example depending what I am working on.

Most of my snippets tab triggers start the same elq- prefix, so it would be very helpful if it were to start showing me the options as I type.


Solution

  • The setting auto_complete_selector controls when Sublime automatically offers the popup for possible completions. The default value for this setting is:

    // Controls what scopes auto complete will be triggered in
    "auto_complete_selector": "source - comment",
    

    This means that it will automatically pop up for any file that's considered a source code file, except within a comment.

    The scopes for the file types that you mention in your question are text scopes and not source scopes, which stops the popup from appearing.

    One way around that would be to manually invoke the auto complete panel by using the appropriate key binding, which by default is Alt+/ on Linux or Ctrl+Space on Windows/OSX. When you do that, the popup for possible completions at this point is manually displayed.

    To allow this to work more automatically, you would need to modify the setting for auto_complete_selector to be more appropriate for your situation.

    To do that you could select Preferences > Settings - User from the menu and add or modify the auto_complete_selector setting as follows:

    "auto_complete_selector": "source - comment, text.html",
    

    This says that the selector should always be displayed in source files except inside comments (like the default) and also within HTML files.

    You could also use text instead of text.html if you want it to work in all text files of all types, although this would possibly get quite annoying while working with plain text files. Substitute an appropriate scope or set of scopes here as appropriate to dial in the places you want this to be automatically offered.