sysid blog

Code Snippets

March 20, 2021 ☕️ 2 min read


Using code snippets cross platform in VIM and JetBrains IDE without having to maintain them twice!

As developer we are always striving to improve our (work)flow.

This includes especially tooling, of course.

Here omes taste, capability, technology and craze come together in an unholy mélange of preferences. Your idea of Nirvana surely will be different from mine.

I am using two IDEs:

  1. vim
  2. JetBrains PyCharm

A challenge while coding is to remember correct syntax, so IDEs provide helpers like code completion, linters and yes, still code snippets (call me old-fashioned).

Ultisnips (vim) and Live-Templates (PyCharm) come into play. Now my brain is not suited to remember syntax specific boilerplate or idioms for the variety of languages I have to deal with. So I am a fan of code snippets.

However, snippets are managed IDE specific, i.e. there is a boundary to cross which usually results in maintaining multiple sources of snippets, e.g. Ultisnips, Live-Templates, Github Gists, …

This is not DRY, and sure as hell the code snippet I am looking for is ALWAYS in the other tool.

A universal snippet repository used by the different IDEs would be nice, but I am not aware of the existence of such a thing.

To solve this challenge for me, I decided to maintain all my snippets in Ultisnips as single point of truth.

To use them in JetBrains IDE involves translating from one domain specific language (Ultisnips) to another (Live-Templates).

So I wrote a little helper for it.

Making it 100% bullet-proof is beyond my willingness to spend effort. There is a number of edge cases, where a simple transformation is impossible. But to transform standard Ultisnips snippets with Placeholders and Mirrors to Live-Templates with matching variable substitution is not too complicated.

It allows to create a Live-Template file (user.xml) with all the Ultisnips snippets you want to use in JetBrains. In my case I am translating my shell, python, sql snippets from Ultisnips to PyCharm.


Using snippets does make sense for me. Having snippets available in my most important dev-tools without maintaining them twice brings back sanity.

always be building, by sysid.

© 2022