Sublime Forum

Python snippet doubled after modified

#1

Win 10, ST3 dev build 3210.
The default for.sublime-snippet is

<snippet>
  <tabTrigger>for</tabTrigger>
  <scope>source.python</scope>
  <description>For Loop</description>
  <content><![CDATA[
for ${1:x} in ${2:xrange(1,10)}:
  ${0:pass}
]]></content>
</snippet>

but xrange is not supported in python3, so I create a new for.sublime-snippet in \Packages\python\Snippets\ like this

<snippet>
  <tabTrigger>for</tabTrigger>
  <scope>source.python</scope>
  <description>For Loop</description>
  <content><![CDATA[
for ${1:x} in ${2:range(1,10)}:
  ${0:pass}
]]></content>
</snippet>

then I type for, it gives two for snippets both of which give for snippet with range.

0 Likes

#2

did you try renaming your python folder to have the correct case, with a capital first letter? maybe it will make a difference.

0 Likes

#3

It worked with your suggestion.Thank you very much!

0 Likes

#4

Unfortunately SublimeText does not have different scopes for Python 2 and 3. this will leave you with 2 “For Loop” snippets, I don’t want that.

Instead of creating a user snippet I installed the plug-in OverrideAudit and applied this change directly in the snippet of Python package. Now there’s only one “For Loop” snippet and I don’t use Python 2 anymore.

Also, I noted the snippet deletes “pass” even though “pass” had been accepted. Is this intended?

for ${1:x} in ${2:range(1,10)}:
    ${0:pass}

Instead, I defined it like this:

for ${1:x} in ${2:range(1,10)}:
    ${3:pass}
0 Likes