Sublime Forum

How to overwrite native Sublime Text 3 code snippets?

#1

I want to modify the try snippet (for inserting a try/catch block) for PHP. I have created a snippet with the same tabkey, but when I type try now, it asks me which of the snippets with try as the tabkey I want to use. Is there a way to overwrite or delete the existing snippet? I can’t seem to find it anywhere (and I have tried using Google to find an answer, but none of the answers I found worked for me).

0 Likes

#2

I have been wresting with the same question in regard to HTML autocompletions. I can’t give you a full answer, but what I think you need to do is to Ctrl-shift-p and then go to PackageResourceViewer:Extract Package (you might need to install this using PackageControl, I can’t remember) and scroll down the list of packages until you come to PHP. Clicking on that will unpack the ST3 PHP package into folder ~/Sublime Text 3/Packages/PHP which you can see by using Preferences->Browse Packages. In there will be the file you need to edit. In the HTML package I am getting to grips with editing HTML_completions.py and its working for me.

Good luck, and do let us know how you get on.

Kind regards - David

0 Likes

#3

All the snippets are in .sublime-snippet files.

So for you, Go to Preferences → Browse Packages → Find the PHP folder → edit or delete the try-{-___-}-catch-(___)-{-___-}.sublime-snippet

0 Likes

#4

On the menu go to Preferences > Browse Packages…

Create a folder named “PHP” and override the default snippet by creating a snippet with the same name.

In your case create the snippet with file name “try-{-___-}-catch-(___)-{-___-}.sublime-snippet”.

This will override the default one.

See sublime-text-unofficial-document … kages.html

0 Likes