Sublime Forum

[Solved] st3 change snippet body depending on set syntax or file type being edited

#1

I have following two snippets defined (for shell script and perl):

elif_sh.sublime-snippet:

<snippet>
    <content><![CDATA[
if [ ]; then
elif [ ]; then
else
fi
]]></content>
    <tabTrigger>elif_sh</tabTrigger>
</snippet>

elif_pl.sublime-snippet:

<snippet>
    <content><![CDATA[
if () {
;
}
elsif () {
;
}
else {
;
}
]]></content>
    <tabTrigger>elif_pl</tabTrigger>
</snippet>

Both are working fine (I either type elif_sh or elif_pl and hit the tab) but I’m curious if is possible to type just elif hit tab and appropriate snippet will be used, depending on file type (or set syntax) being edited. Thanks

0 Likes

#2

Yep, just modify the <tabTrgger> of both to be elif and then add one of the following two lines to the snippet to set the scope that they will trigger in:

    <scope>source.shell</scope>
    <scope>source.perl</scope>
2 Likes