David - Musings of an SRE

Creating a custom jekyll-markdown snippet

In the time spent writing the previous blog post, I come to realize that I really need a snippet to help me with the highlight tags.

I’m using Jekyll to run this journal and with Jekyll comes a really cool liquid template that helps make pasting code snippets easy.

For example, to write a ruby codeblock, I’d need to:

{% highlight ruby %}
puts "a code block here"
{% endhighlight %}
view raw gistfile1.txt hosted with ❤ by GitHub

To do this multiple times, it is quite a mouthful of keystrokes.

So with that, I’ve decided to write my own snippet since I’m already using snipmate-vim with my vim environment.

I created a new file in a new custom directory

# ~/.vim/bundle/my-snippets/snippets/markdown.snippets
snippet highlight
{% highlight ${1} %}
%{2}
{% endhighlight %}
view raw gistfile1.txt hosted with ❤ by GitHub

and setup my vimrc to autoload the directory

  # .vimrc
  let g:snippets_dir="~/.vim/bundle/snipmate/snippets/, ~/.vim/bundle/my-snippets/snippets"

Now, when I open up my markdown files and type “highlight”, I’ll be able to select the code-type and the content in just two tabs.

Hope this helps someone else.