Supercharge Your Workflow With Yasnippet

I’ve long been an enthusiastic Yasnippet user and have written about it a few times. Its canonical use case is in programming to fill in primitives such as the for loop in C or a class definition in Python but I rarely use it that way. I mostly use it with Org files to do things like create the header for blog posts, add boilerplate, do simple expansions like latex → LaTeX, insert daily checklists into my journal, and add code blocks to my blog posts.

These are all pretty simple operations that don’t begin to use all that Yasnippet has to offer. Jack of Some has an excellent video on how to superchage Emacs with Yasnippet. He does, of course, cover simple text substitutions but he also shows how to use its more advanced features.

One particularly nice example is his expansion of a Python class definition. As he adds arguments to the definition, the snippet automatically adds the code to initialize the instance with the arguments’ values. More generally, he shows how you can embed Elisp into the snippet template to do non-trivial things like insert the name of the current file into the text.

One thing I didn’t know how to do was to add “global snippets”. Usually snippets are only active for a particular type of file but it’s possible to have snippets that are always available. Take a look at the video to see how to do this.

The video is two years old but I just came across it. It’s definitely worth a few minutes of your time. It’s a few seconds over 12 minutes long so it should be easy to fit into your schedule.

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