53
votes

In Sublime Text 3, how do I edit my pre-existing snippet files? Is there a way of doing this within ST?

At the time of writing, there doesn't seem to be a straightforward answer to this anywhere on the web.

6
I have not tried it myself (still using ST2 at the moment), but this article maximilianhoffmann.com/posts/configuring-sublime-text-3 might give you some idea on how to unpack package archives in Sublime Text 3 and modify their content (e.g. snippets). - Bohuslav Burghardt
Thanks, the PackageResourceViewer plugin looks promising. I feel there should be an option in the tools menu within ST next to 'new snippet' to 'edit snippets' - Inigo
I agree, because currently even if you edit the snippet in some package other than User then your changes will probably be lost when you upgrade the package/Sublime Text which kind of sucks. Ideal solution would be to copy the snippet to the User package modify it and then the modified snippet would take precedence over the default one. But I just tried this and it doesn't work :( (both snippets are shown in autocompletion and you can't really distinguish them unless you give them different tab trigger for instance) - Bohuslav Burghardt
Should the title be changed to "How do I edit custom user snippets in Sublime Text 3?"? Right now both answers are specific to user snippets which doesn't cover snippets from other sources. The question title makes it sound as though the question is supposed to cover all snippets but the question body says "my pre-existing snippet files" which makes it sound as though it is only about custom user snippets. - AnnanFay

6 Answers

67
votes

Custom snippets are saved in a .sublime-snippet file that you create when you first save the snippet.

By default, these are placed in the "User" package. You can either browse to the file like you would any other file, or using PackageResourceViewer: Open Resource -> User -> [name of your snippet file]

54
votes

For those of you that like a visual instruction here it is:

enter image description here

Then, you can find your snippet like this:

enter image description here

1
votes

Here are the steps I had to follow (figure out on my own) for anyone else who wants to edit the built-in snippets of Sublime (in my case Javascript's "fun" "function" snippet). Note: this assumes you've installed the Package "PackageResourceViewer" already:

  1. --> PackageResourceViewer: Extract Package
  2. Then specify which package(s) you want to extract. FWIW this process was a bit confusing for me ... somehow I managed to select everything? but I only wanted/needed "JavaScript".
  3. Wait a second or three for Sublime to extract these (no idea what this does in background, I assume maybe unzipping/extracting loose files to your file system?)
  4. You'll get a confirmation dialog about your successful extraction
  5. NOW you can edit built-in snippets by --> PackageResourceViewer: Open Resource
  6. --> Select "JavaScript" (in my case)
  7. --> Select "/Snippets" (in my case)
  8. --> Select your snippet (in my case it was "function-(fun).sublime-snippet" or something like that.
  9. The file will open and you can modify/save your changes ... FINALLY!

WAY too complicated IMHO but at least it works.

1
votes

If someone (like me) is looking to edit a custom snippet: open file *.sublime-snippet which exists in

[home_directory]/.config/sublime-text-3/Packages/User/

If you have another file organization:

  1. Start to make new snippet - Tools->developer->new snippet
  2. Try to save it. Sublime shows you the right directory with snippets
0
votes

Here is how to edit built-in snippets manually on macOS, in this case the JavaScript snippets. This is a way to do it without installing plugins:

  1. Right click the Sublime Text app, select "Show Package Contents"
  2. In the Finder, navigate to Contents -> MacOS -> Packages
  3. Copy the JavaScript.sublime-package file to ~/Library/Application Support/Sublime Text 3/Installed Packages
  4. Change the file name from JavaScript.sublime-package to JavaScript.zip and unzip the file
  5. In your text editor, edit the contents of the unzipped JavaScript folder as required (e.g. delete the fun snippet from the Snippets folder)
  6. Zip up the JavaScript folder again, rename it from JavaScript.zip to JavaScript.sublime-package and leave it in the Installed Packages folder.
  7. Restart Sublime. Your new JavaScript package will override the built-in package.
0
votes

Tools -> Developer -> View package file -> search for the existing snippet. Change and save.