A physics high school student of mine is typesetting latex documents using vim. I noticed however that he doesn't use the siunitx package which typesets units properly. However the syntax for example \SI{3}{m} for 3 Meter or \SI{3}{\meter\per\second} etc. Especially for a beginner (on a german keyboard) it is a pain to type in this manually if you have lots of numbers with units in your document.

As an emacs user I use yasnipped for myself like

# -*- mode: snippet -*-
# name: si
# key: s
# --

Typing s and then shift space (in my config) expands this to \SI{}{} and places the cursor between the first two brackets after typing in the number you can go to the second pair using tab.

Now I am looking for a similar or even better setup for vim to encourage my student to use siunitx with proper editor support.

Would be great if you could add a little animated gif to your answer to see the solution working.

1 Answer 1


siunitx is a very useful and good package. Notice, though, that version 3 have introduced some major changes. For instance, the \SI and \si commands are deprecated in favor of \qty and \unit. I recommend people who are used to the old commands to read the manual for the updated version, at least the first few pages and the chapter about these changes.

There are several plugins for Vim for snippet functionality. I personally use one of the old ones, UltiSnips. It works very well, but I know there are other snippet engines that may work equally well. With UltiSnips, you would typically type qty then a trigger key to expand into \qty{|}{} where | is the cursor position.

Elijan J. Mastnak has written a very nice tutorial series on how to write LaTeX with Vim (or neovim). It is lengthy, but well worth the read in my opinion. He has a part dedicated to snippets: An UltiSnips guide for LaTeX workflows. I believe this text may be well suited as an introduction of UltiSnips to your student.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.