Christopher Peterson

March 19, 2018

Quick and easy unit conversions within Vim (vim-convert)



Editing some varieties of documents I noticed myself jumping into a browser or terminal often to do unit conversion. But no longer! Vim-convert is a plugin I made for Vim that allows easy unit conversion from a simple command.

The command

:Convert [[value]|[start unit]] {target unit}

Some usage examples

" To convert in-place the currently visually-selected text which includes a unit, e.g. `500g`:
:Convert {target unit}

" To convert in-place the currently visually-selected text which does *not* include a unit, e.g. `500`, you'll need to specify one:
:Convert {start unit} {target unit}

" To insert a unit conversion as a new value after the cursor, give both fields:
:Convert <value><start unit> <target unit>

To cause an error because parsecs are a unit of distance:
:Convert 12parsecs hours

This plugin will try to be mindful of whether the unit itself is desired when replacing text. That is, if the selected text lacks a unit, the result will be placed without one as well.

Installation instructions and other details in the README.

Header image bits: Vim logo from D0ktorz and SI Units from Dono