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

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

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!

Take a look at the Indigo.Design sample applications to learn more about how apps are created with design to code software.

Topics:
editor ,plugin ,markdown ,markdown editor

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}