Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Use Vim's :make to Preview Markdown

DZone's Guide to

Use Vim's :make to Preview Markdown

One thing I'm used to is that when I run the build command on a Markdown file, I expect Marked for Mac to open and render the file that I'm writing. Vim has :make which by default runs make and is mapped to cmd+b on MacVim, so I just needed to reconfigure that command to do the right thing. Read on and see how it's done.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

As it becomes more painful to use a pointing device for long periods of time, I find myself using vim more and so I'm paying more attention to customization so that the things I'm used to from Sublime Text are available to me.

One thing I'm used to is that when I run the build command on a Markdown file, I expect Marked for Mac to open and render the file that I'm writing. Vim has :make which by default runs make and is mapped to cmd+b on MacVim, so I just needed to reconfigure that command to do the right thing.

The easiest way to do this is via a file type plugin. These are files that live in ~/.vim/ftplugin and are named after the file type. In this case, the file is markdown.vim. The commands inside the file are then available whenever you're editing a file of that type. (You can use :set ft? to find out the file type of the current file.)

To configure what :make does, we set the makeprg setting like this:

set makeprg=open\ -a\ Marked\\\ 2.app\ '%:p'

Note that spaces need to be escaped for vim and then the space in "Marked 2.app" needs escaping for the shell, which is why there are three \s in a row.

Add this line to ~/.vim/ftplugin/markdown.vim and :make now opens Marked and life is just that little bit easier…

Obviously, if you're not on a Mac or use a different tool to preview Markdown, then configure appropriately!

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
editor ,plugin ,markdown ,markdown editor

Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}