WordPress from Vim

I’ve made a few tweaks to Vim which make it simple to blog to a WordPress blog (like this one). Originally I was using VimRepress but I had a few issues with it. I then discovered blogit.vim which just seems to work better for me. I didn’t like the massively long lines, so I had a look and found DistractFree for Vim which helps eliminate distractions, and also puts margins around your text so that the lines aren’t ridiculously long when Vim is maximized. Here’s what it looks like:

Blogit allows you to edit WordPress posts, and DistractFree lets you limit the length of the lines.

I’ve written some notes on how I set this up.

Set up Blogit

Setting up blogit.vim is very simple. Download the tarball and extract it into your ~/.vim folder. Create ~/.vim/passwords.vim with the following contents:

You can then test this by opening Vim and running the command :Blogit ls. If everything is set up correctly, then you’ll see a menu of your blog posts which you can navigate with hjkl and edit with Enter.

Set up DistractFree

DistractFree setup is a bit different. Basically you download its vmb file, edit it in vim, then run :so % to install it.

Once it’s installed you can set the line length in your .vimrc file like this:

F2 creates a blogpost and F3 lets you open an existing post. It might seem like overkill to map them in this way but I want it to be totally effortless to get something into a post.

Once you hit either F2 or F3, a few other things happen. First, the :w command, which I run instinctively to save things, gets command aliased to :Blogit commit, which saves the post as a draft.

It also enters DistractFree mode, turns off textwidth and some formatoptions which mess up WordPress paragraphs. It also turns on wrap, otherwise it’s very hard to see what’s going on.

One final thing that I have in my .vimrc that is probably necessary if you’re using wrap is the following:

nmap j gj
nmap k gk

This makes it so that the default j and k move up and down in the way that you’d expect them to. The normal behaviour is for them to move between lines, which makes it almost impossible to navigate with wrap on.

Issues

I have had a few issues with formatting getting a bit messed up by wrapping, I’m still not sure what this is about but if you have any ideas let me know in the comments. Any other suggestions also appreciated.