Manish Jethani ([info]mannu) wrote,
  • Mood: geeky

Markdown preview with Vim

More on OS X geek lifestyle.

How do you compose your blog entries? I write mine in Markdown format; once done, I pass the text through the Markdown and SmartyPants filters, and finally to Charm (all in one command).

While composing in Vim, I feel the need to preview sometimes, often every few seconds. To save myself all the typing, I’ve now made this entry in my .vimrc file:

imap <F8> <ESC>:w!<CR>:!markdown % \| smartypants > %.html && open %.html<CR><CR>a

It says, “When I press F8, (1) save the file, (2) run it through Markdown and SmartyPants, saving the output in an HTML file, (3) and open it in the default web browser (Safari).” Works wonderfully for me! I’ve hit F8 about ten times while composing this post, heh.

You can also make this entry if you want F8 to work in command mode as well:

map <F8> :w!<CR>:!markdown % \| smartypants > %.html && open %.html<CR><CR>

In addition, I also make sure to click the little plus icon (the green one) on my preview window.

[image: Safari window controls]

It’s the “zoom” function in OS X, and it works differently in different applications. In Safari, zooming a window sets its size to be just large enough to be able to display all the content. This is great while previewing HTML—you don’t want your text to be flowing end to end, because that’s not how it shows on your blog (does it?).

Soon I’m going to integrate Charm with Vim so I can manage my blog entirely from one editor window. And then I shall unleash the terror of my blogging and rule the blogosphere with an iron fist. Muahahaha!!!

PS: I’ve never seen UNIX so sexy. God bless Apple.


Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…