Sublime Forum

n00b] how to edit / change javascript autocomplete snippets?

#1

Hello,

I am new to ST3. How can I edit/change existing JS snippets?

For instance, when I type in a JS file: “fun” and press TAB, it will expand the function snippet template (name, args, body).

I would like to change the body of “fun” for instance.

I am using Mac OS.

Thanks,
Elias

0 Likes

#2

According to the docs you can “override” a built-in snippet by saving a snippet as <original_package_name>/<original_filename> under your Packages/User/ directory. (Find the original snippet in an archive in the Packages/ directory under your Sublime installation directory – in your case, the JavaScript.sublime-package archive.)

For example, to override the “function” JS snippet on my Ubuntu system, I’d create:

~/.config/sublime-text-3/Packages/User/Javascript/function-(fun).sublime-snippet

Annoyingly, this doesn’t actually override the original snippet; it simply creates a new one alongside the first. If the built-in and new snippet have the same trigger, they’ll both show up in your autocomplete list, and you’ll have to pick the right one using arrows or mouse. You could create the new snippet with a different trigger, but that’s kind of a bummer because it still leaves the built-in snippet junking up your autocomplete.

Alternatively, you can edit the built-in snippet in its archive, but you’ll lose your changes every time you upgrade Sublime. (Still, I do this for a small handful of my most-used Snippets, and keep faith that this situation will someday be improved.)

0 Likes