Align Markdown Tables in Vim
GitHub-Flavored Markdown supports formatting data as a table:
| Step | Users | Conversion | Obstacles |
| --- | --- | --- | --- |
| Viewed Home Page | 13,129 | 7.9% | Messaging |
| Viewed Sign Up Page | 1,044 | 20.6% | Cost, credit card |
| Signed Up | 215 | 31.2% | Credit card required |
| Entered Credit Card | 67 | 50.7% | HTML, deployment |
| Received Submission | 34 | | |
Over time, as you edit this data in Vim, keeping the Markdown table aligned could be painful, but doesn't have to be.
Install vim-easy-align with a plugin manager such as vim-plug.
Plug 'junegunn/vim-easy-align'
Set a mapping:
" ~/.vim/ftdetect/markdown.vim
" Align GitHub-Flavored Markdown tables
vmap <Leader><Bslash> :EasyAlign*<Bar><Enter>
The <Bslash>
key is the |
key,
a mnemonic for the table's |
s.
Here's how it looks: