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

How do I create and auto-format Markdown or textile tables in Vim?

Answer

<Leader>tm

Explanation

The vim-table-mode plugin by Dhruva Sagar turns Vim into a powerful table editor that automatically formats and aligns table columns as you type. Instead of manually counting spaces and adjusting pipes, you toggle table mode on and the plugin handles all the alignment in real time.

How it works

Press <Leader>tm (by default m) to toggle table mode on. Once enabled, any line you type that starts with | is treated as a table row. As you type columns separated by |, the plugin auto-aligns all columns in the table and adds separator lines.

Creating a table from scratch

With table mode enabled, just start typing:

| Name | Age | Role |

Press Enter and type || to insert a horizontal separator line automatically:

| Name  | Age | Role    |
|-------+-----+---------|

Continue adding rows and the plugin keeps every column perfectly aligned:

| Name    | Age | Role      |
|---------+-----+-----------|
| Alice   | 30  | Developer |
| Bob     | 25  | Designer  |
| Charlie | 35  | Manager   |

Reformatting existing tables

If you paste in a messy, unaligned table, place your cursor inside it and run:

:TableModeRealign

The plugin recalculates all column widths and aligns everything instantly.

Table formulas

Vim-table-mode supports spreadsheet-like formulas. Add a formula row at the bottom of your table:

| Item   | Price |
|--------+-------|
| Widget | 10    |
| Gadget | 25    |
| Total  |       |

Run :TableEvalFormulaLine with a formula to sum the Price column, bringing basic spreadsheet functionality into your text editor.

Deleting rows and columns

The plugin provides commands for structural table editing:

<Leader>tdd    " delete the current row
<Leader>tdc    " delete the current column
<Leader>tic    " insert a column after the current one

Moving between cells

While in table mode, use these motions to navigate:

<Leader>t]    " move to the next cell
<Leader>t[    " move to the previous cell

Markdown vs textile format

By default, the plugin uses a format compatible with most Markdown parsers. Switch the corner character for pure Markdown compatibility:

let g:table_mode_corner='|'

This changes the separator line from |---+---| to |---|---|, which GitHub-flavored Markdown expects.

Tips

  • Use :Tableize on CSV data to instantly convert comma-separated values into a formatted table
  • Pass a custom delimiter to :Tableize: :Tableize/; converts semicolon-separated data
  • The plugin auto-detects when you leave the table area and stops formatting non-table lines
  • Add let g:table_mode_always_active = 1 to your vimrc if you frequently edit table-heavy files like documentation
  • Works perfectly with Markdown, reStructuredText, and textile table formats
  • Combine with vim-surround to quickly wrap cell contents in formatting like bold or links

Next

How do I edit multiple lines at once using multiple cursors in Vim?