Sublime Forum

Remove default snippet

#1

Hello.

I use Sublime Text 3 and I met such a problem. For example, in JavaScript I have two default snippets for “for” loop. So each time I type “for” and press TAB I get a dropdown menu before snippet is actually expanded. Also I’d like to modify inserted text a bit. So I can create a new snippet in Packages/User, but now I have 3 items in dropdown, and I would like to expand it immediately. How can I remove snippets shipped with Sublime by default and use my own instead?

Also I don’t want to create separate topic for such a simple question, sorry for that. But can I open a file, put cursor in certain position and get current scope in this position to use it in new snippet for exapmle, if I want to limit it by certain scope?

1 Like

[solved] How to deactivate default snippet(s)
#2

May be it is documented but I cant figure out how to do that, and can’t find a manual that works.

Maybe I’m missing something important?

1 Like

#3

Unfortunately, the way ST3 is set up, it’s quite difficult to completely remove files contained in the default packages, and even if you did, upon upgrade the files would be there again. So, in your case, what we’ll have to do is override the default files by creating new files with the same name, but no active content.

First, go to Preferences -> Browse Packages… to open up a file explorer window from your operating system (Finder, Windows Explorer, Nautilus, etc.). Create a new folder called “JavaScript”, then inside that folder, create two new empty files called “for-()-{}.sublime-snippet” and “for-()-{}-(faster).sublime-snippet”. Open each of these files in Sublime, and paste the following contents into them:

<snippet>
    <content><![CDATA[$1]]></content>
</snippet>

This essentially creates a valid but empty snippet with no tabTrigger. Save these files, restart Sublime for good luck, and now when you’re working in JavaScript and type “for”, only your “Packages/User/for.sublime-snippet” (or whatever you named it) should be active.

Good luck!

1 Like

#4

MattDMo, thank you, it worked perfectly!

My problem was that I didn’t understand how to name my snippet files to override defaults, thank you again!

But how did you figured out theese file names?

1 Like

#5

I even searched for theese names inside ~/Library/Application Support, and nothing was wound, only the files I created.

I can’t even find the default package itself :frowning:

~/Library/Application Support]$ find . -iname 'JavaScript.sublime-package' ~/Library/Application Support]$

2 Likes

#6

As far as I can tell with ST3, the only items for default packages in ~/Library/Application Support/Sublime Text 3 are cached items. In OS X, I’ve found the best approach for looking into default packages is via /Applications/Sublime\ Text.app/Contents/MacOS/Packages/

2 Likes

#7

subhaze, yes, that’s it!

I also could find only cache, but I wasn’t smart enough to look inside app itself! Thank you, I think it solves my problem at least for now!

1 Like

#8

Wow, this actually worked.
I though I was doomed to see double snippets in my Tab Completion.

But that’s kind of a hack, why isn’t there a simpler way?
Or at least make it work like it did with ST2, meaning if you use the same trigger or the same file name, it overrides the default snippet (not sure which one of those it was).

1 Like

#9

To extract the file, you can use github.com/skuroda/PackageResourceViewer. If you use the plugin to navigate to the file you want, you can make your edits there. Upon saving, it will create the proper structure to override an existing package file. Of course, you can always extract and what not manually, but the plugin will likely save you some trouble in finding everything since plugins can be in the packages folder, the installed packages folder, or in the executable folder.

2 Likes