Yasnippets Tutorial

Lefteris Karapetsas has an interesting tutorial on using yasnippets for entering boilerplate code. A lot of us use small snippets for minor tasks such as filling in a for or while loop. Karapetsas shows how to use it for large portions of boilerplate.

The examples he gives are from C but the techniques are equally applicable to other languages. The idea is that code for defining a structure and functions to allocate it, initialize it, and free it is usually pretty much the same so a snippet can “write” most of the code for you. The snippet parameters fill in many of the unique parts, leaving only the application specific code to write. The same ideas apply, of course, in other common situations.

Karapetsas also has links to another tutorial and the Yasnippet Development Manual. If you aren’t using yasnippets or are only using them in trivial ways, take a look at Karapetsas’ post.

UPDATE: Added missing link.

This entry was posted in General and tagged . Bookmark the permalink.