vimtricks.wiki Concise Vim tricks, one at a time.

How do I align text into columns using an external command in Vim?

Answer

:%!column -t

Explanation

The column -t command formats whitespace-separated text into neatly aligned columns. By piping your buffer (or a selection) through it with :%!, you can instantly align data without installing any plugins.

How it works

" Align entire buffer
:%!column -t

" Align selected lines
:'<,'>!column -t

" Align using a specific delimiter
:%!column -t -s ','

Example

Before:

name age city
Alice 30 NYC
Bob 25 LA
Charlie 35 Chicago

After :%!column -t:

name     age  city
Alice    30   NYC
Bob      25   LA
Charlie  35   Chicago

For CSV data

" Align CSV with comma separator
:%!column -t -s ','

" Align with pipe separator
:%!column -t -s '|'

Tips

  • column -t is available on Linux and macOS by default (part of util-linux or bsdmainutils)
  • Use visual selection to align only a specific section of your file
  • For more advanced alignment (by regex, specific characters), consider the vim-tabular or vim-easy-align plugins
  • Combine with :sort to sort and align in one workflow
  • The -o flag sets the output delimiter: column -t -s ',' -o ' | ' for pipe-separated output

Next

How do I always access my last yanked text regardless of deletes?