Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default code snippets in Sublime Text 3?

People also ask

How do I change the snippet in Sublime Text?

Select Package Resource Viewer: Open Resource, navigate down the list to LaTeX, then open the section-.. -(section). sublime-snippet file. You should now be able to edit this file and save it, which will create a new file Packages/LaTeX/section-..

How do I create a custom snippet in Sublime Text 3?

To create a new snippet in Sublime Text 3, go to: Tools -> Developer -> New Snippet... This opens a new window containing a new snippet template, which looks like this: There are four parts to a snippet.

How do I use snippets in Sublime Text 3?

Sublime text provides a default template in XML format when we create a new snippet. To create the template got to SUBLIME TEXT → TOOLS → DEVELOPER → NEW SNIPPET. Let's understand the template definition and modify the parameters. The actual content or block of code to be inserted should be placed within <content><!

Where are sublime text snippets stored?

Sublime Text will present you with an skeleton for a new snippet. Snippets can be stored under any package's folder, but to keep it simple while you're learning, you can save them to your Packages/User folder.


Sublime Text 3 stores its packages in .sublime-package zip files (the location varies by OS), so unlike ST2 you can't just go to the Packages folder and see everything. However, there is an excellent plugin called PackageResourceViewer (available via Package Control) that can, among other things, extract files or whole packages to the Packages directory.

Once you've installed the plugin:

  • hit CtrlShiftP to open the command palette
  • type prv to get the Package Resource Viewer: options
  • select Package Resource Viewer: Open Resource
  • navigate down the list to LaTeX
  • then open the section-..-(section).sublime-snippet file.

You should now be able to edit this file and save it, which will create a new file Packages/LaTeX/section-..-(section).sublime-snippet that you can open directly via the file menu if you need to alter it again.

If you'd like to work on multiple files, or an entire package, use Package Resource Viewer: Extract Package which will unzip everything into the Packages/PackageName folder. Please keep in mind, though, that once packages or individual files are extracted into the Packages folder, they overrule files of the same name located in the .sublime-package archive. This is good for customization, but if at some point the parent package is updated, you won't see the effects because they're being masked by what's in Packages. Therefore, it's probably best to extract only what you need, and keep an eye on your package updates in case new features are introduced that you want to take advantage of.

Good luck!


To easily jump there in terminal (if you are using ST3 on OSX) is /Users/$USER/Library/Application\ Support/Sublime\ Text\ 3/Packages/User. You can see all of your snippets here and edit them as you like.


In addition to the other answer, here is how to do it without having to install any additional plugin.

Solution not requiring any additional plugin (October 2016).


I had a similar problem while trying to override some key bindings defined in a package.

Steps

  • Install your package (using Package Manager or any other method you prefer).

Your zipped package file should be now placed within the folder ~/.config/sublime-text-3/Installed Packages/<your-package>.sublime-package.

  • Check the content of the package by unzipping it (just make sure to keep the original zipped file).

    Among these files, find the one that contains the preference you want to edit (see Package Contents). In your case it should be a .sublime-snippet file. Remember its name.

  • Create a folder with the same name of your package inside ~/.config/sublime-text-3/Packages.

  • Create inside this folder a new snippet file that will override the default package behaviour. Note that the new file should have the same name of the snippet file that you found inside the package. From console:

    > cd ~/.config/sublime-text-3/Packages
    > mkdir <YOUR-PACKAGE-NAME>
    > gedit <YOUR-SNIPPET-NAME>.sublime-snippet
    
  • Put the content of your new snippet in your <YOUR-SNIPPET-NAME>.sublime-snippet. This will override the old snippet behaviour.

Sources:

  • How To Override Sublime Text Packages Shortcuts and Preferences (my blog)
  • How To Find out Sublime Text Key Binding Commands (my blog)
  • ST Unofficial Documentation - Package Contents
  • Personal experience