Sublime Forum

Snippet tabTrigger does not work on all scopes when no scope defined as scope selector

#1
  • SW, Version: ST3.0, 3143
  • OS: Windows 8.1

details

I created a custom snippet and saved it to Packages/User. I defined a tab trigger for the snippet. I did NOT define a scope.

Test case

  1. new file created, unsaved: tab did not trigger
  2. test.txt file created, tab did not trigger
  3. test.bat file created, tab did trigger
  4. test.c file created, tab did trigger

Understandings and Doupts

I understand that tab trigger does not work on new created, unsaved files.
I understand that tab trigger works for several scopes when no scope is defined.
I beleave that tab trigger works for a certain top level scope only when no scope is defined. Is this correct?

Goals and further thoughts:

My goal is to create a snippet that works on any text file, regardless extension.

For this, I’d need to achieve anything conceptually similar to this:

  1. no scope defined
  2. <scope>source.*,text.*</scope>

Can someone give me further hints on solving this issue, thank you.

Documents read:

0 Likes

#2

In a clean install, the default snippet,

<snippet>
    <content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

with the tabTrigger uncommented, works just fine typing hello Tab in a new, unsaved, Plain Text document.

Perhaps you have something (i.e. a keybinding) conflicting that is causing the behavior you describe?

2 Likes

#3

@kingkeith,

Thank you for your reply, this was helpful.

2 observations to make:

  1. my tab trigger contains spaces, like “hello world” which is a bad habit of mine. I’ll stop doing this from now on
  2. confirmed, I can replicate your test

Comments on observation 2:

  • I am used to the context menu that appears with a list of available snippets as you type. This is why obs. 1 never
    caused issues to me.

  • In my test cases, “tab did not trigger” is incorrect. It actually triggers with typing hello + TAB. The context menu does not show up in this cases, which I incorrectly interpreted as “tab did not trigger”.

Why does context menu not appear for text scope?

0 Likes

#4

because the default setting auto_complete_selector contains a scope selector that doesn’t match the text scope, it should appear if you manually trigger autocomplete

2 Likes

#5

I used this forum post to change my settings for auto_complete_selector, together with this modification.

Thank you @kingkeith for your help.

0 Likes