Quick RST Preview From Vi

I use reStructuredText a lot because I think it looks really good in text form. Better than Markdown, Textile, WikiFormatting (Trac, ugh!), IMO. There are also plenty of converters to make it into HTML, PDF, LaTeX, or what have you. This way I write it once and it is pretty much readable everywhere.

The site rst2a.com lets you play with it online and add different themes / styles with one click.

But anyway, enough evangelism, this post is about a small vim snippet I made to quickly preview any rST doc you’re writing. Put this in your ~/.vimrc:

:command Rst :!rst2html.py % > /tmp/rstprev.html && open /tmp/rstprev.html
:nnoremap <C-p><C-r> :Rst<CR>

This works on my Mac OS X setup. For other OS’s you probably just need to change the “open” command to whatever your launcher is.

So, while you’re in command mode of your RST doc, just type “:Rst” or CTRL-P CTRL-R, to instantly see your doc formatted for HTML in your web browser!

Do feel free to change the hot-keys to anything that is comfortable for you. I was thinking (P)review (R)st. :)