a vim setup for octopress

Disclaimer: This content is not owned by the current webmaster nor do we claim the credit.  Ownership of this domain has changed hands. This URL however as a courtesy to web users is a  historic copy of what was originally published.

Conner Mcdaniel has created a new blog athttps://connermcd.wordpress.com You can find all of his current publication there.

A vim setup for octopress
Jul 15, 2012

There’s been plenty of posts out there discussing the pros and cons of octopress and other static site generators, so I’m not going to add to the list. I will say that from my personal experience the transition was relatively smooth and that octopress happened to have the necessary features, plugins, and community I needed to get the website I wanted. This certainly may not be the case for everyone, but I am pleased with the overall result so far. Octopress probably does require a bit of web development experience, which I’m fortunate to have. For users without that knowledge base, wordpress is very friendly. However, my needs in a personal webpage are simplistic, and wordpress is just a little too much overkill. It has also become rather mainstream and uses a lot of PHP, which makes it a potential security threat — especially with a lot of (often shady) plugins. I enjoyed working with vimrepress, but since I’m moving away from wordpress, I won’t be developing on it anymore. I did learn something about python-based vim plugins from the experience though.

I wanted a similar vim setup for my new octopress blog. I read another post belaboring this as a lacking feature that ultimately moved them back to wordpress. I was confused by that, since making a decent workflow in octopress is not all that difficult. Here’s the steps I took:

nnoremap ‘bn :NewPost
command! -nargs=1 NewPost call NewPost(““)
fun! NewPost(args)
let file = “/web/octopress/source/_posts/” . strftime(“%Y-%m-%d”) . “-” . tolower(substitute(a:args, ” “, “-“, “g”)) . “.markdown”
exe “e!” . file
let g:post_title = a:args

nnoremap ‘bs :SavePost
command! -nargs=1 SavePost call SavePost(““)
fun! SavePost(args)
let file = “/web/octopress/source/_posts/” . strftime(“%Y-%m-%d”) . “-” . tolower(substitute(a:args, ” “, “-“, “g”)) . “.markdown”
exe “w!” . file
let g:post_title = a:args
The :NewPost command will allow you to quickly make a new file in the appropriate directory with the appropriate name. The :SavePost command does essentially the same thing except that it uses the buffer you’re currently working with instead of making a new one. There might be a better approach than this, but this is just my first go at a solution. Both of the functions set a variable, g:post_title, which I then use in a snipmate snippet file like this:

snippet b

date: `strftime(“%Y-%m-%d %T”)`
layout: post
slug: `tolower(substitute(g:post_title, ” “, “-“, “g”))`
title: `g:post_title`
– ${1}

That way I can press ib in the new file to get the appropriate front matter. The next thing I wanted was tag and category completion like vimrepress had, so I solved that using these in my ~/.vimrc:

au BufNewFile,BufRead /web/octopress/source/_posts/*.markdown setl completefunc=TagComplete | cd /web/octopress/source
fun! TagComplete(findstart, base)
if a:findstart
” locate the start of the word
let line = getline(‘.’)
let start = col(‘.’) – 1
while start > 0 && line[start – 1] =~ ‘\a’
let start -= 1
return start
let tags = split(system(“ls /web/octopress/public/blog/tags”), “\n”)
let cats = split(system(“ls /web/octopress/public/blog/categories”), “\n”)
return tags + cats
You’ll have to change the appropriate directories of course. This allows you to use for tag and category completion and changes the directory automatically when you use the :NewPost command. I might modify these some in the future and update this post, but for now this solution is working for me.