reformat in vim for a nice column layout

If you're on some kind of UNIX (Linux, etc), you can cheat and filter it through the column(1) command.

:%!column -t

The above will parse on delimiters inside string literals which is wrong, so you will likely need pre-processing steps and specifying the delimiter for this file for example:

%!sed 's/","/\&/' | column -t -s '&'

Sometimes we want to align just two columns. In that case, we don't need any plugins and can use pure Vim functionality like this:

  1. Choose a separator. In OP's post this is a comma, in my example this is =.
  2. Add spaces before/after it. I use s/=/= ...spaces... / in visual selection for this.
  3. Locate to the longest word and place cursor after it.
  4. Remove all the extra whitespace using dw and vertical movement.

Example of this technique demonstrated below:

Example

I don't find myself needing to align things often enough to install another plugin, so this was my preferred way of accomplishing it - especially that it doesn't require much thinking.

Tags:

Vim

Reformat