Files
lk/writing/vim/md_columns.md
T
2026-05-14 13:17:01 +02:00

949 B

title, tags
title tags
Format Markdown Columns in Vim
writing
vim
markdown
TUI

Got a wonky markdown table?


| Real Time | Game Time |
|:--|:-|
| 1 week | 1 month |
| 3 weeks | 3 months|
| 6 months | 2 years|
| 1 year | 4 years|

Vim can fix it without plugins. Just use this snippet (type : to begin inputting a command):

:vmap <C-t> :!tr -s ' -' \|column -ts '\|' -o '\|'<Enter>j:s/ /-/g<Enter>k

Highlight the whole thing with vap then press Control + t. Instantly, it is aligned:


| Real Time | Game Time |
|:----------|:----------|
| 1 week    | 1 month   |
| 3 weeks   | 3 months  |
| 6 months  | 2 years   |
| 1 year    | 4 years   |

NB: This method has problems with centre-aligned columns (using :---:).

Vim Run Commands

Put this in your ~/.vimrc to make the mapping permanent:

vmap <C-t> :!tr -s ' -' \|column -ts '\|' -o '\|'<Enter>j:s/ /-/g<Enter>k