Multimarkdown table formatting in Vim

15

6

I've recently moved from using TextMate to using Vim a lot more (because I split my time between Mac and Linux). One thing I miss is the wonderful MultiMarkdown bundle which, amongst other features, lets me enter tables in MultiMarkdown syntax and then reformats them so they look pretty.

So, for example this:

| Heading 1 | Heading 2 | Heading 3 |
| --: | -- | -- |
| 1 | Some text | Some other text |
| 2 | A somewhat longer piece of text | Further text |

Becomes this:

| Heading 1 | Heading 2                       | Heading 3       |
| --------: | ------------------------------- | --------------- |
|         1 | Some text                       | Some other text |
|         2 | A somewhat longer piece of text | Further text    |

The closest thing I've found to this is table_format.vim, but it's pretty old and uses spaces instead of vertical bars to delimit columns.

Is there anything better out there to reformat tables like these in Vim?

Jez

Posted 2011-06-08T10:35:35.367

Reputation: 400

Answers

11

The Align plugin can table-format by vertical bars using the shortcut "\t|".

Don Reba

Posted 2011-06-08T10:35:35.367

Reputation: 238

That's great, thanks. It looks like that plugin will be handy formatting LaTeX documents too. – Jez – 2011-06-08T13:02:52.790

You are welcome. I use Align all the time. I just love table formatting. – Don Reba – 2011-06-08T15:39:51.747

6

I've also now come across Tabular.vim which is another plugin along the same lines as Align.vim. They're similar but each have advantages and disadvantages in how they work.

Jez

Posted 2011-06-08T10:35:35.367

Reputation: 400

It's an old question BUT Vimcasts has an excellent podcast on using tabular.vim here: http://vimcasts.org/episodes/aligning-text-with-tabular-vim/

– Screenack – 2015-01-03T19:45:31.640

3

I think vim-table-mode may be more powerful. It will format table when inserting vertical bar "|", and can generate tables with many styles, not just Markdown.

SenZhang

Posted 2011-06-08T10:35:35.367

Reputation: 41