Using Vim to Blog with WordPress
A number of static blogging solutions have emerged over the last few years, and while they’ve been attractive I’ve not yet moved off of WordPress.
Perhaps it’s just inertia, but it’s served me well for almost a decade so I’m going to stay loyal to it—at least for now.
Vim as the editor
One of the things that made me most jealous of the newer, more developer-oriented blogging engines is the ability to create and edit posts in Vim. I’m a serious vim enthusiast [check out my primer] and it causes me great frustration every time I interact with WordPress’s GUI.
Thankfully there’s a way.
Setup
First is VimBlog, a renamed fork I just created of the great but two-years-dead project, VimRepress.
Installation
Clone ths repository into your Vim environment’s plugin directory
Create a ~/.vimrepressrc file, and put the following in it
blog_url = http://yoursite.com/ username = you password = goodpassword
I am making some modifications to how the plugin works so that it’s more functional for my uses. In particular, I’m focusing on quick blogging from the terminal.
Shortcuts
Of particular note are the shortcuts I’ve enabled through a combination of Vim and Zsh. These allow me to do everything from my iTerm2 shell, and with just a couple of keystrokes be creating or editing blog content.
The aliases
Here are the aliases I use in Zsh.
alias nb="vim +BlogNew"
alias eb="vim +BlogList"
And the “blog” shortcut within Vim.
nnoremap b :BlogSave publish
So now I can create content for every part of my site from within Vim, instead of having to go into a GUI to do so (typing Vim commands into a dumb editor is supremely annoying). Here are my steps for creating a new post.
Unsupervised Learning — Security, Tech, and AI in 10 minutes…
Get a weekly breakdown of what's happening in security and tech—and why it matters.
Creating a new blog post from the command line (launches VimBlog)
nb
When I’m ready to post, type leader-p
leader-p
Editing posts from the command line (launches VimBlog)
eb
The flow
So, frrom the terminal I do:
- nb
- I’m dropped into Vim, in an interface like the one above
- Create the post, and then type leader-p to post it
That’s it!
And to edit posts, I just type eb, for “edit blog”, and I get the lists of posts seen in the top image.
Questions and comments welcome.