Markdown Preview in Vim
2012-09-08 11:20:15
/Linux/Vim

Nate gives a nice script to preview Markdown files in Vim:

http://blog.natesilva.com/post/5256838248/how-to-preview-a-markdown-document-in-vim

But he hasn't tested it on Linux. Minor changes will make it work on Linux.

  1. Change open to xdg-open.
  2. Add a redraw! command in the end (in case some terminals don't automatically redraw).

The modified version is shown below. I like to use <Leader> rather than comma, but you're free to change it.

"
" While editing a Markdown document in Vim, preview it in the
" default browser.
"
" Author: Nate Silva
"
" To install: Place markdown.vim in ~/.vim/ftplugin or
" %USERPROFILE%\vimfiles\ftplugin.
"
" To use: While editing a Markdown file, press '\a' (backslash a)
"
" Tested on Windows and Mac OS X. Should work on Linux if you set
" BROWSER_COMMAND properly.
"
" Requires the `markdown` command to be on the system path. If you
" do not have the `markdown` command, install one of the following:
"
" http://www.pell.portland.or.us/~orc/Code/discount/
" http://www.freewisdom.org/projects/python-markdown/
"
function!PreviewMarkdown()
    " **************************************************************
    " Configurable settings

    let MARKDOWN_COMMAND = 'markdown'

    if has('win32')
        " note important extra pair of double-quotes
        let BROWSER_COMMAND = 'cmd.exe /c start ""'
    else
        let BROWSER_COMMAND = 'xdg-open'
    endif

    " End of configurable settings
    " **************************************************************

    silent update
    let output_name = tempname() . '.html'

    " Some Markdown implementations, especially the Python one,
    " work best with UTF-8. If our buffer is not in UTF-8, convert
    " it before running Markdown, then convert it back.
    let original_encoding = &fileencoding
    let original_bomb = &bomb
    if original_encoding != 'utf-8' || original_bomb == 1
        set nobomb
        set fileencoding=utf-8
        silent update
    endif

    " Write the HTML header. Do a CSS reset, followed by setting up
    " some basic styles from YUI, so the output looks nice.
    let file_header = ['<html>', '<head>',
        \ '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">',
        \ '<title>Markdown Preview</title>',
        \ '<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css">',
        \ '<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssbase/base-min.css">',
        \ '<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css">',
        \ '<style>body{padding:20px;}div#container{background-color:#F2F2F2;padding:0 20px;margin:0px;border:solid #D0D0D0 1px;}</style>',
        \ '</head>', '<body>', '<div id="container">']
    call writefile(file_header, output_name)

    let md_command = '!' . MARKDOWN_COMMAND . ' "' . expand('%:p') . '" >> "' .
        \ output_name . '"'
    silent exec md_command

    if has('win32')
        let footer_name = tempname()
        call writefile(['</div></body></html>'], footer_name)
        silent exec '!type "' . footer_name . '" >> "' . output_name . '"'
        exec delete(footer_name)
    else
        silent exec '!echo "</div></body></html>" >> "' .
            \ output_name . '"'
    endif

    " If we changed the encoding, change it back.
    if original_encoding != 'utf-8' || original_bomb == 1
        if original_bomb == 1
            set bomb
        endif
        silent exec 'set fileencoding=' . original_encoding
        silent update
    endif

    silent exec '!' . BROWSER_COMMAND . ' "' . output_name . '"'

    exec input('Press ENTER to continue...')
    echo
    exec delete(output_name)
    redraw!

endfunction

" Map this feature to the key sequence '\a' (backslash lowercase-a)
map <Leader>a :call PreviewMarkdown()<CR>

posted by Cyker Way
michael kors at 2015-04-04 08:19:48

Bergdorf <a href="http://www.louisvuittonoutlet-us.com" target="_blank">louis vuitton outlet,louis vuitton outlet stores</a> Goo <a href="http://www.coachfactorycoachoutlet.com" target="_blank">coach factory,coach outlet</a> dman <a href="http://www.truereligion-jeans.com" target="_blank">true religion Jeans,true religion outlet</a> Sale: <a href="http://www.saclouisvuittons.com" target="_blank">sac louis vuitton</a> Extra <a href="http://www.sacportefeuillepascher.com" target="_blank">sac longchamp</a> 25% <a href="http://www.thenorthfaceclearance.us.com" target="_blank">the north face,north face outlet</a> Off <a href="http://www.michaelkorsoutletonlines.us.com" target="_blank">michael kors outlet,michael kors</a> Already-Reduced <a href="http://www.coachoutletfactorystore.us.com" target="_blank">coach factory outlet,coach outlet</a> Items! It's <a href="http://www.coachoutletsonlinesell.com" target="_blank">coach outlet online</a> that time <a href="http://www.coachoutletstoresus.com" target="_blank">coach outlet store online,coach factory outlet</a> again. Yes <a href="http://www.michaelkorsoutletline.com" target="_blank">michael kors outlet online,michael kors outlet</a> indeed, the latest episode of my podcast, The No Bullshit Guide <a href="http://www.truereligionjean.com" target="_blank">true religion Jeans,true religion</a> to Life, is <a href="http://www.louisvuittonoutlet-store.com" target="_blank">louis vuitton outlet,louis vuitton</a> now <a href="http://www.coachoutletnet.com" target="_blank">coach outlet,coach factory outlet</a> live. This <a href="http://www.chanel-handbag.us.com" target="_blank">chanel handbags</a> week's <a href="http://www.michaelkorsoutletonlinestore.com" target="_blank">michael kors outlet store online,michael kors outlet</a> episode <a href="http://www.louis-vuittonoutletstores.com" target="_blank">louis vuitton outlet stores,louis vuitton outlet</a> is all <a href="http://www.ralphlaurenoutlets.us.com" target="_blank">ralph lauren outlet</a> about <a href="http://www.coachfactory-outlets.us.com" target="_blank">coach factory outlet,coach outlet store online</a> how <a href="http://www.oakleyoutletstore.us.com" target="_blank">oakley outlet sunglasses,oakley sunglasses</a> we <a href="http://www.coachfactoryoutletstoreonline.us.com" target="_blank">coach factory outlet store online,coach outlet</a> define <a href="http://www.valentinoshoes.us.org" target="_blank">valentino shoes</a> ourselves <a href="http://www.coachfactory-outletonline.us.com" target="_blank">coach factory outlet.coach outlet</a> by our jobs <a href="http://www.hollistercoclothingstore.com" target="_blank">hollister clothing store</a> and how to stop <a href="http://www.coachfactoryoutletsstore.us.com" target="_blank">coach factory outlet,coach factory outlet online</a> doing that. <a href="http://www.guccioutletstores.us.com" target="_blank">gucci outlet,gucci handbags</a> Would <a href="http://www.northfaceoutlet.us.com" target="_blank">north face outlet,the north face</a> love <a href="http://www.celinehandbags.us.com" target="_blank">celine handbags</a> to <a href="http://www.katespadehandbags.us.com" target="_blank">kate spade handbags,kate spade outlet online</a> hear <a href="http://www.chanel-bag.us.com" target="_blank">chanel handbags</a> your thoughts. If you haven't <a href="http://www.valentinoshoe.com" target="_blank">valentino shoes</a> already, do <a href="http://www.raybanoutlets.us.com" target="_blank">ray ban outlet,cheap ray ban</a> have <a href="http://www.michael--korsoutletonline.us.com" target="_blank">michael kors outlet,michael kors</a> a listen back <a href="http://www.coachonlinestoresoutlet.com" target="_blank">coach outlet store online,coach outlet,coach factory outlet</a> through <a href="http://www.katespadeoutletsonline.com" target="_blank">kate spade outlet,kate spade</a> the other <a href="http://www.michael-korsoutletonlinesale.us.com" target="_blank">michael kors outlet,michael kors outlet online sale</a> episodes <a href="http://www.michaelkorsoutlet2015.us.com" target="_blank">michael kors,michael kors outlet</a> too.The <a href="http://www.katespadeoutletstores.us.com" target="_blank">kate spade outlet online,kate spade outlet</a> proposed <a href="http://www.hermesbelt.us.com" target="_blank">hermes belts</a> Revolutionary <a href="http://www.ralphlaurenoutletonline.us.com" target="_blank">Ralph Lauren outlet</a> Fibers and <a href="http://www.coach-outletstores.us.com" target="_blank">coach outlet,coach factory outlet store</a> Textiles <a href="http://www.christianlouboutins.us.com" target="_blank">louboutin shoes,christian louboutin,christian louboutin outlet</a> Manufacturing <a href="http://www.coachoutlet-stores.us.com" target="_blank">coach outlet,coach factory outlet</a> Innovation Institute, part of a planned <a href="http://www.coandtiffanys.com" target="_blank">tiffany and co,engagement rings for women necklaces,earrings,,bangles</a> Network <a href="http://www.hermesbag.us.com" target="_blank">hermes bag</a> for <a href="http://www.burberryoutlets.us.com" target="_blank">burberry outlet,burberry.com,burberry handbags</a> Manufacturing <a href="http://www.coachoutlet-store.us.com" target="_blank">coach outlet store online,coach factory outlet</a> Innovation, aims <a href="http://www.coachoutletstore.us.org" target="_blank">coach outlet stores,coach outlet</a> to "ensure that <a href="http://www.saclancel.com" target="_blank">sac lancel</a> America <a href="http://www.coachoutletstores.us.org" target="_blank">coach handbags,coach outlet</a> remains <a href="http://www.louisvuitton.us.org" target="_blank">louis vuitton,louis vuitton outlet</a> at the <a href="http://www.abercrombieandfitchclothing.com" target="_blank">abercrombie and fitch</a> leading edge <a href="http://www.coachfactoryoutletstore.cc" target="_blank">coach factory outlet.coach outlet</a> of fiber <a href="http://www.coachstoreoutletonline.com" target="_blank">coach factory outlet,coach outlet store online</a> science, <a href="http://www.celine-handbags.com" target="_blank">celine handbags</a> As part <a href="http://www.ralphlaurenpolos.us.com" target="_blank">polo ralph lauren,ralph lauren outlet</a> of the <a href="http://www.coachfactoryinc.us.com" target="_blank">coach factory outlet online,coach factory</a> ongoing <a href="http://www.michaelkorsoutletinc.us.com" target="_blank">michael kors outlet,michael kors outlet online sale</a> partnership <a href="http://www.coachoutletfactorystoresonline.com" target="_blank">coach outlet,coach factory outlet online</a> between W <a href="http://www.sacshermes.com" target="_blank">sac hermes</a> Hotels and <a href="http://www.oakleyssunglasses.us.com" target="_blank">oakley sunglasses,cheap oakley sunglasses</a> the <a href="http://www.pradahandbags.eu.com" target="_blank">prada handbags</a> (Fashion <a href="http://www.abercrombieandfitchsale.com" target="_blank">abercrombie clothes</a>) program, NYC-based label Lucio Castro was offered the <a href="http://www.beatsbydrdre.us.com" target="_blank">beats by dr dre</a> opportunity to <a href="http://www.tiffanysandco.us.com" target="_blank">tiffany and co</a> create <a href="http://www.redbottomshoe.us.com" target="_blank">red bottoms shoes</a> a unique <a href="http://www.burberryoutletstore.us.com" target="_blank">burberry outlet,burberry outlet stores</a> piece <a href="http://www.michael-kors-outletonline.us.com" target="_blank">michael kors outlet,michael kors outlet online</a> and launch <a href="http://www.cocochanelhandbag.us.com" target="_blank">chanel handbags</a> it at <a href="http://www.ray-bansunglasses.us.org" target="_blank">ray-ban sunglasses,cheap rayban sunglasses</a> South <a href="http://www.oakleysunglasses.us.org" target="_blank">oakley sunglasses,cheap oakley sunglasses</a> by <a href="http://www.coach-outlet-online.us.com" target="_blank">coach outlet online,coach factory outlet</a> Southwest. <a href="http://www.ray-bansunglassesoutlet.us.com" target="_blank">ray ban sunglasses,ray ban sunglasses outlet</a> Castro <a href="http://www.michaelkorsoutletin.com" target="_blank">michael kors outlet,michael kors</a> created <a href="http://www.louisvuittonoutlet-online.com" target="_blank">louis vuitton outlet,louis vuitton</a> an <a href="http://www.louisvuitton-outletsale.com" target="_blank">louis vuitton outlet,louis vuitton 86% off sale</a> original <a href="http://www.michaelkorsoutlet-onlinesale.us.com" target="_blank">michael kors,outlet michael kors online</a> print <a href="http://www.coachfactoryoutletcoachoutletonline.com" target="_blank">coach factory outlet,coach outlet online</a> eaturing <a href="http://www.louis-vuittonus.com" target="_blank">louis vuitton,louis vuitton outlet stores</a> -drawn bats <a href="http://www.raybanoutletstoreonline.us.com" target="_blank">ray ban outlet,ray ban outlet store online</a> and <a href="http://www.kate-spadeoutletonline.com" target="_blank">kate spade outlet online</a> bagels,When <a href="http://www.oakleyssunglassescheap.com" target="_blank">oakley sunglasses cheap,oakley sunglasses</a> it <a href="http://www.tomsoutlet.in.net" target="_blank">toms outlet</a> comes <a href="http://www.portefeuillepascher.com" target="_blank">sac chanel</a> to <a href="http://www.truereligionoutlets.us.com" target="_blank">true religion outlet,true religion,true religion brand jeans</a> modern <a href="http://www.oakleysunglasses.com.co" target="_blank">oakley sunglasses,cheap oakley sunglasses</a> moccasins, <a href="http://www.raybansunglassesweb.com" target="_blank">ray ban sunglasses,cheap ray ban sunglasses</a> there <a href="http://www.oakleyglasses.us.com" target="_blank">oakley sunglasses</a> aren't <a href="http://www.raybanglasses.us.com" target="_blank">ray ban sunglasses</a> many <a href="http://www.abercrombieandfitchoutlets.com" target="_blank">abercrombie and fitch</a> doing it <a href="http://www.michaelkorsoutletonlineinc.us.com" target="_blank">michael kors outlet online,michael kors</a> better than Yuketen. The brand has been tasked with <a href="http://www.pradaoutlet.eu.com" target="_blank">prada outlet</a> creating <a href="http://www.pradahandbags.us.org" target="_blank">prada handbags</a> an <a href="http://www.giuseppezanottishoe.com" target="_blank">giuseppe zanotti shoes</a> exclusive <a href="http://www.marcbymarc-jacobs.com" target="_blank">marc by marc jacobs</a> version of its <a href="http://www.tomsshoesoutletonline.in.net" target="_blank">toms shoes outlet online</a> Moc for <a href="http://www.ray-bansunglasses.com" target="_blank">ray-ban sunglasses,cheap ray ban sunglasses 90% off</a> USA-based <a href="http://www.truereligionoutlet.us.org" target="_blank">true religion outlet</a> store, Double <a href="http://www.ray-banoutlets.com" target="_blank">ray ban outlet,cheap ray ban sunglasses</a> Select, and doesn't disappoint.EST <a href="http://www.coachoutletsstoreonline.cc" target="_blank">coach outlet store online,coach outlet</a> tomorrow, and you wouldn't want to miss it!When stark <a href="http://www.michaelkorsoutletsstore.cc" target="_blank">michael kors outlet,michael kors outlet online sale</a> white feels like <a href="http://www.guccibag.us.com" target="_blank">gucci,gucci handbags,gucci outlet</a> too much of a commitment, go for the vanilla-cream, the off-white, the milky, the <a href="http://www.oakleyoutlets.us.com" target="_blank">oakley outlet,cheap oakley sunglasses</a> ivory shades. Here's a case where "almost" most certainly counts. Whatever you call it, no color is more neutral.

Reply
Name
Email
Homepage
Content
/images/Facebook_32x32.png
/images/Twitter_32x32.png
/images/Feed_32x32.png
Creative Commons divcense