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:
I’ve written some notes on how I set this up.
Set up Blogit
let blogit_username='Your blog user name' let blogit_password='Your blog password' let blogit_url='https://your.path.to/xmlrpc.php'
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
Set up DistractFree
Once it’s installed you can set the line length in your
.vimrc file like this:
I find 66 characters to be the right width for editing (it’s also good for general readability on the web.
I created a few shortcuts to make it easier to create/edit blog posts.
map <F2> :Blogit new<CR>:ca w Blogit commit<CR>:DistractFreeToggle<CR>:set fo-=aw tw=0 wrap<CR> map <F3> :Blogit ls<CR>:ca w Blogit commit<CR>:DistractFreeToggle<CR>:set fo-=aw tw=0 wrap<CR>
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
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
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.