Sublime Forum

Changing default snippets

#1

I have created a new snippet for php which uses pri-tab as a shortcut.
The snippet should be:
echo "<pre>";
print_r();
echo "</pre>";
Whenever I press pri-tab though, it prints
print_r(expression);
If I hit ctrl-z and then hit tab again it prints my snippet.

I can’t find the snippet code for the first (wrong) one anywhere. Can anyone offer any suggestions?

0 Likes

#2

what third party packages do you have installed? maybe one of those is providing this unwanted snippet?

0 Likes

#3

I’ve tried uninstalling a couple that I weren’t really using, but still no joy. I’ve been through all of the snippets that I can find, but I can’t find anything relating to the print_r() php function. Is there anywhere else I should be looking?

0 Likes

#4

Something to try would be to open the Sublime console with View > Show Console and enter the following lines, one at a time:

[r for r in sublime.find_resources("*.sublime-snippet") if "print_r" in sublime.load_resource(r)]
[r for r in sublime.find_resources("*.sublime-completions") if "print_r" in sublime.load_resource(r)]

The first one fines all snippets across all packages and checks to see if the text print_r appears inside them at all, and the second does the same thing for all of the completions files.

The result of each line will either be a list of the files that contained that text, or an empty list if it wasn’t found. For example, this is the result of doing the same as the above while checking for the text lorem instead of print_r:

>>> [r for r in sublime.find_resources("*.sublime-snippet") if "lorem" in sublime.load_resource(r)]
['Packages/Text/Snippets/lorem.sublime-snippet']
>>> [r for r in sublime.find_resources("*.sublime-completions") if "lorem" in sublime.load_resource(r)]
[]

From this we can infer that the snippet that’s providing the lorem completion is in the Text package, but that there is no completion that matches.

From doing that locally I don’t see anything that ships with Sublime providing anything that provides print_r, but when you do it you should see at least the snippet you created yourself, if nothing else.

If that doesn’t expose any other likely files that might be the culprit, the next best guess is that a plugin is doing it. Possibly doing the same as the above but with *.py instead of *.sublime-snippet may provide a result, assuming such a plugin has the data hard coded into it and isn’t gathering it from a file:

>>> [r for r in sublime.find_resources("*.py") if "lorem" in sublime.load_resource(r)]
['Packages/ScreencastTools/buzzwords.py']
1 Like

#5

Thank you so much!
It turned out to be in the Packages/PHP/PHP.sublime-completions file
I used PackageResourceViewer to comment the offending line out and it’s all fixed.

You have saved my sanity

1 Like

#6

Awesome, glad I could assist. :smiley:

Just to clarify my post above, indeed that ships with Sublime even though I said above it didn’t seem to; from checking my console history here, I had a typo in the resource spec when I tried it locally myself. Fortunately I managed to type it correctly in the post. :blush:

0 Likes