I was dumb. You don’t actually have to make a snippet unless you want something special, because Atom’s autocomplete does it already. Just type
a and then
enter. Then you can press
tab again to put the cursor between the tags. But I’ll explain snippets to you because it’s a powerful tool for automation.
To make the snippet I posted (say you want all the links on your site to open in new windows), this is what you need to add to your snippets file (you can get to it via the menu or the
snippets.cson file in your
body: "<a href=\"$1\" target=\"_blank\">$2</a>"
Since you’re new to this, I’ll break down how to read that. Indentation matters a lot in CoffeeScript. The unindented text is the “root” of the object, and represents a scope in the TextEditor (written here and in many places just like you write classes in CSS, so that’s easy). The text on the left of the colon is called the key, and the text on the right is the value. When a key is by itself and indented text follows, then everything on that next level of indentation is the value. You can have many different snippets under the same scope, as long as they have unique titles. The first indented line is the title of the snippet, which should be unique within that scope. The
prefix is what you start typing, and the
body is what it expands to when you’re finished. With that snippet, I can type
a-tab and it expands to whatever’s in the
body, in this case,
<a href="" target="_blank"></a>, with the cursor between the first two quotes. Take care to escape any quotes inside quotes in your code files; the color coding will let you know that something is off.
The dollar signs are one of the best parts of snippets, because each press of the
tab key moves the cursor to the next one. You can fill out a form only navigating with one key, which is great.
Here’s the manual page on snippets.