Home Download Buy Blog Forum Support

Remove default snippet

Remove default snippet

Postby Antonius on Thu Nov 14, 2013 9:21 pm

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?
Antonius
 
Posts: 5
Joined: Thu Nov 14, 2013 9:07 pm

Re: Remove default snippet

Postby Antonius on Fri Nov 15, 2013 4:49 pm

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?
Antonius
 
Posts: 5
Joined: Thu Nov 14, 2013 9:07 pm

Re: Remove default snippet

Postby MattDMo on Sat Nov 16, 2013 10:08 pm

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:

Code: Select all
<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!
MattDMo
 
Posts: 36
Joined: Thu Jan 17, 2013 3:15 am
Location: near Boston

Re: Remove default snippet

Postby Antonius on Mon Nov 18, 2013 2:37 am

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?
Antonius
 
Posts: 5
Joined: Thu Nov 14, 2013 9:07 pm

Re: Remove default snippet

Postby Antonius on Mon Nov 18, 2013 3:29 pm

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 :(

Code: Select all
[~/Library/Application Support]$ find . -iname 'JavaScript.sublime-package'
[~/Library/Application Support]$
Antonius
 
Posts: 5
Joined: Thu Nov 14, 2013 9:07 pm

Re: Remove default snippet

Postby subhaze on Mon Nov 18, 2013 4:12 pm

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/`
subhaze
 
Posts: 230
Joined: Tue Apr 09, 2013 3:22 am

Re: Remove default snippet

Postby Antonius on Mon Nov 18, 2013 4:20 pm

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!
Antonius
 
Posts: 5
Joined: Thu Nov 14, 2013 9:07 pm

Re: Remove default snippet

Postby spine on Thu Dec 26, 2013 8:32 pm

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).
spine
 
Posts: 11
Joined: Mon Sep 24, 2012 1:54 pm

Re: Remove default snippet

Postby skuroda on Fri Dec 27, 2013 12:33 am

To extract the file, you can use https://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.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 23 guests