title: "Column formatting within Shell / Vim, e.g., for Neomutt and Abook" date: 2019-01-16
The following is a micro-tip for formatting text in vim. If you are writing a document and want to have the text in neatly aligned columns, resembling a table, you can pipe text to the shell's column command.
To do so, select a range of text with visual mode (Shift-V), and then enter the following ex command:
:!column -t
So to demonstrate, you can go from having text that looks like this:
GNU Linux Parabola Gentoo Comfy Memes
RC 1337 N3rd Ghanoo Wizard SuperDuperLongWord
Apples Oranges Windoze 9000 Remainder Clutch
to text that looks like this:
GNU | Linux | Parabola | Gentoo | Comfy | Memes |
RC | 1337 | N3rd | Ghanoo | Wizard | SuperDuperLongWord |
Apples | Oranges | Windoze | 9000 | Remainder | Clutch |
I like using this command for managing my abook address book file that is used by neomutt. To illustrate: the raw text of the alias file, generated by calling abook from within neomutt, looks like this:
#<alias><nickname><fullaname><address>
alias bob bob jones <bobjones@fakemail.com>
alias joe joe bobs <joebobs@fakemail.com>
alias mimi mimi gator <mimigator@superfakemail.com>
alias sally sally sullen <ssullen@sallymail.com>
alias zeb zeb doolio <zd@doolmail.com>
This is pretty messy and hard to parse at a glance. So I occasionally open up the file and run the column command to clean it up, yielding this:
# | \ | \ | \ | \ |
alias | bob | bob | jones | |
alias | joe | joe | bobs | |
alias | mimi | mimi | gator | |
alias | sally | sally | sullen | |
alias | zeb | zeb | doolio |