I am using Sublime Text to code my website where I have a JavaScript file with a lot of functions. I use those functions quite frequently and every time I do, I have to type the whole function out.
I noticed that for each function, I could create a Sublime Text snippet with a shortcut. However there is a huge list of functions and they keep changing.
Is there a way where in I could just import this JavaScript file and this snippet file is created, such that I have my autocompletes ready to use?
Usage. By default, Sublime Text will automatically show the completions popup when a user is editing source code or markup, but not within prose in comments, strings or markups. Pressing the Esc key will hide the completions popup. To manually show the completions popup, press Ctrl+Space.
A simple snippet that creates three opening and closing p
tags:
<snippet>
<content>
<![CDATA[
<p>
$1
</p>
<p>
$2
</p>
<p>
$3
</p>
]]>
</content>
<tabTrigger>p3</tabTrigger>
<scope>text.html</scope>
</snippet>
Save it as html-p3.sublime-snippet
in (Mac OS X) /Users/yourname/Library/Application Support/Sublime Text 2/Packages/User
and you can enter p3+tab
to create three <p>
tags. The $1, $2, $3
are where your cursor will jump after you press tab. This allows you to easily add content without having to select manually.
This great blog post explains everything you need to know about Sublime Text snippets:
You can use snippets for CSS as well as HTML (actually, you can use snippets with any language or text that works inside Sublime Text).
To summarize, you can put all of your function snippets in between the <snippet><content><![CDATA[ *content here*]]></content></snippet>
and save it as a .snippet file in the default preferences folder of Sublime Text.
Sublime Text should automatically autocomplete the function names (not the parameters) if everything is in one big file. The only possible issue I can think of is that Sublime Text doesn’t recognize the file type. Check if View → Syntax is set to JavaScript.
If you want full autocompletion with parameters, try Tern for Sublime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With