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 -tis available on Linux and macOS by default (part ofutil-linuxorbsdmainutils)- Use visual selection to align only a specific section of your file
- For more advanced alignment (by regex, specific characters), consider the
vim-tabularorvim-easy-alignplugins - Combine with
:sortto sort and align in one workflow - The
-oflag sets the output delimiter:column -t -s ',' -o ' | 'for pipe-separated output