Snippets: A Love Story

Coding is hard work, and as they say, being lazy as a coder is a virtue. Snippets are a great way to put this virtue into practice. Even beginner programmers in Ruby are familiar with the attr_accessor. But what makes it even greater than turning six lines of code into one, is turning it into three keystrokes. “r, w, tab” and you’re set.

After hitting tab

While that’s one you’re going to use frequently, there are plenty others that you might want, or that you might use frequently for a specific program you’re working on. That’s where custom snippets come in. Here I’ll show you how to you create your own custom snippet in Atom. (Sorry Sublime users, but why are you still using that?)

It’s a shockingly easy process in Atom, and for anything I see repetition in my future for, I’ll be creating these shortcuts to help out. I think it’s easiest just to show you how the process works, and then explain a little bit.

Snippet Walkthrough

See how easy that was? Obviously there is a snippet to write a snippet, so you just type ‘snip’ + tab and it gives you the template. It’s default is to javascript, so you need to change that to Ruby or whatever language you’re using. And for multiple lines of code, you should use triple-double quotation marks.

A little extra, for those of us writing sql commands in our text editor, you might appreciate something like this:

No matter what you’re writing though, snippets can make your life easier. Take advantage of such a useful function.

Like what you read? Give Mike Handwerker a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.