Tuesday, 15 March 2016

Quick Vim tip: convert piped table to pandoc/RST/Emacs grid table

Inspired by a snippet by Conner McDaniel, I added a little snippet to my .vimrc that can convert a piped table to a grid table used by pandoc/RST/Emacs.

It goes from this:

 Fruit | Price | Advantages         
 Bananas | $1.34 | - built-in wrapper     
 Oranges | $2.10 | - cures scurvy           
To this:
+---------------+---------------+--------------------+
| Fruit         | Price         | Advantages         |
+===============+===============+====================+
| Bananas       | $1.34         | - built-in wrapper |
+---------------+---------------+--------------------+
| Oranges       | $2.10         | - cures scurvy     |
+---------------+---------------+--------------------+
Add this to your .vimrc file:
Now, make a visual selection and type :TablePandoc. It uses tabular.vim to align the pipe characters. Example:


If you have additional tips for using Pandoc from Vim, please let me know in the comments.

No comments:

Post a Comment