Blogging with WordPress, vim and Markdown
by Conner McDaniel
Recently I made a post on converting your WordPress posts into Markdown files. You may be wondering, “What now?” Now that all your posts are on your file system, how do you continue to make WordPress posts in Markdown? Well, you could write your new posts in Markdown in a text editor on your local filesystem and then copy paste them into WordPress using one of the WordPress Markdown plugins (1,2). Personally, I would rather not have to copy and paste and there is no text editor I would rather use than VIM. So, I looked into several options to determine what the best way to go about this would be.
I tried several plugins, but the simplest I found was vimpress. It’s features are to the point and effective,and there are also several adaptations of it with different features. One of these adaptations is VimRepress which adds the features of colorizing the vimpress display, allowing for the upload of files, and supporting the markdown syntax. VimRepress does require vim-python, so if you’re on a mac you’ll have to compile MacVim from source.
Compiling MacVim with Python & Ruby
Compiling can be tricky sometimes, especially since things seem to almost always break with some unforeseen error. I will show you how I accomplished this using OSX 10.6.7 Snow Leopard with Xcode installed. There’s a guide for compiling MacVim here. First, download or use git to acquire the source then navigate to the ‘src’ folder within it. The guide then lists several configuration options that are available for compiling the code, however, you don’t need them all and I personally had trouble with –enable-perlinterp. Ruby is a useful language that you may want to use for a different plugin later, so I’d go ahead and throw that option in too. I simply used
followed by a
This should compile the software and create the .app file. You can then copy the .app file from files/src/MacVim/build/Release/MacVim.app into your /Applications folder and use it as normal.
Installing VimRepress
Now you’ll need to download the files from VimRepress. They need to be placed within a folder named .vim in your personal directory. To do this you can execute these commands.
cd ~/.vim
mv ~/Downloads/vimpress* .
unzip vimpress*
You’ll have to tell VimRepress the username, password, and URL of your blog, so the next step is to set those options. The easiest way to do this is in your ~/.vimrc file. If you don’t already have one then make one and add the VimRepress configuration variable to it.
\'password':'pass',
\'blog_url':'http://your-first-blog.com/'
\},
\{'username':'user',
\'password':'pass',
\'blog_url':'http://your-second-blog.com/'
\}]
If you download my fork of the project, you don’t need to hardcode your passwords. As you can see, you can use multiple blogs with VimRepress if needed. If not, then just specify one without a comma after the closing curly brace. You will need to go to your WordPress and make sure that Settings->Writing->XML-RPC is checked for this to work.
Using VimRepress with Markdown
Python comes pre-installed on Mac. You can check your version with
Download the python-markdown package, extract it and install it using
Half the point of this whole effort is to be able to code in the syntax simplicity of Markdown. So, first things first, you are going to want some Markdown syntax highlighting for VIM. You can download the files you need here and then unzip them into your ~/.vim folder. Now, navigate to the folder that contains all your WordPress posts as processed by my PHP script and create a new, appropriately titled file. From here you can immediately begin writing your post in Markdown. Once you’re done and ready to preview or publish the post, type the command :MarkDownNewPost and you will enter the VimRepress management window. This command will convert the current file from Markdown into HTML and add post metadata to the top. In the metadata you can assign categories, tags, and a title. This file does not need to be saved. It’s just a way to allow you to edit this data and double check the HTML conversion if you’re concerned about it. Once you’re ready you can use
or
depending on whether you want to preview or publish. Pretty nifty, huh?
Hi, Conner,
Great video. Thanks for posting what’s working for you. I’ve been hunting and pecking a way to blog from the commandline for a while, and streamlining things, to minimize logistical friction. I’d been playing with Blogit.vim, which is nice enough, but not currently maintained and it was causing some odd errors I had no patience to troubleshoot.
The author of VimRepress (a curious name) responded to a note I sent, mentioning this video and also that you’d adapted the code a little. I assume one of the adaptations is the tag/category completion. Is that something you’ve distributed somewhere?
Cheers,
Daniel
Hey Daniel,
Indeed! I have a fork here that you can grab. If you don’t have git, I uploaded a copy here. My fork includes autocomplete of categories using ^X^U and also allows you to remove your hardcoded password from your .vimrc. Instead, it will prompt you for a password if it needs one. If you have additional feature requests I will try to implement them if I find them feasible. I am by no means a python or vim expert! I think the name VimRepress is due to the author’s inexperience in English. The original plugin was called Vimpress (a combination of Vim and WordPress) and using the prefix “re-”, he thought it would make a good name for a fork. Oh, what’s in a name? It works for me!
Hi guys, glad to know that many of you are having vimpress forked to improved it’s power, while i’m also doing the same thing.
I’m working on a version that was refactored a lot, changes include:
- Commands simplified. No more BlogPageNew/BlogPageSave commands anymore, managing pages are available via the argument to the original BlogNew/BlogList commands, Meta fields shows you what kind of post you’re editing.
- Much better Markdown integrated. No more MarkdownXXX commands. You can decide what you edit (Markdown or HTML), when you BlogSave or BlogPreview, program parse the meta field to things done.
- Markdown raw text uploaded as attachment. Updating a post that was written in markdown before is complicated, now your raw markdown will automatically upload to wordpress as an attachment, when you open the post in Vimpress, it downloads the attachment and show you your original markdown text, the attachment also got updated when you BlogSave again.
This version of vimpress is not yet released, for i’m still debuging, i just finished all this features just this 2 days. If any of you got interested, go to my svn:
svn checkout http://ptcoding.googlecode.com/svn/trunk/vimpress-dev
I separated python code from blog.vim to avoid my coding editor got confused about python syntax, i’ll combine them together when final release, if you want to try now, got to change the last line about the python file in “blog.vim”.
@Preston
Thanks for the heads up, Preston. I’ve made some more modifications recently as well. I plan on merging our changes in the coming days, and I’ll get back to you when I do. Lenin Lee has taken his fork in a different direction. It’s called UltraBlog.vim and can be found on his site. UltraBlog utilizes sqllite to store blog changes on your local machine. While I can see how this might be useful for some, it’s a little bit overkill for me. Locally, I want my posts/pages as files and only use vimpress when I want to update my blog. All that to say I like the direction you’re heading in and want to help. Cheers, Conner.
@connermcd
after some fix around in this weekend, i release vimrepress as a beta version and want to invite you to test for it :
http://code.google.com/p/ptcoding/downloads/detail?name=vimpress-2.0.0_beta.zip
The help document haven’t been updated, it need some more words to explain the usage for those new commands, i simply example them here:
:BlogNew page
:BlogNew post
:BlogList
:BlogList post 10
:BlogList page
:BlogPreview local
:BlogPreview publish
:BlogOpen http://connermcd.com/archives/679
:BlogOpen 679
other commands hadn’t changed.
I’d like to have your help with some explain words in the doc for i’m not an English native. Thank you at first here.
I’m looking at your forked about the category menu feature, i may include it in my next release.
I’ve compiled MacVim from source and when I try to use Vimrepress it just Segfaults and dissapears.
I also tried with macvim from macports, there vimrepress wont work because it has python support with both normal python and pyhon25. I think python25 gets priority so the Vimrepress python scripts wont run. I get errors when I run it with macports macvim atleast.
Where do I begin to look for solutions? The segmentation fault gives no error message appart for segfault.
Best regards
Morten
[...] can find the details here. The post is a bit outdated since the commands have been simplified, but it describes the [...]
Nice plug-in, but the latest version – 2.1.5-r81, from vim.org – is not working for me. I get the following error when I try to BlogSave:
Markdown file uploading …
xmlrpc error: Could not write file vimpress_4e7623fe_mkd.txt (Invalid file type)
BlogList is working but I guess, there is some problem in uploading the markdown file as attachment.
@Morten
Hey Morten, not sure why you’re running into that issue. The macports version will probably not work. I uploaded my personal compilation here.
@Appan
Thanks, I haven’t worked on the project since 2.0.0. You can still grab 2.0.0 from my github which is linked above or you can tell Preston Masion about the error.
[...] Blogging with WordPress, VIM and Markdown [...]
@Appan
If you’re using wordpress.com, its media library doesn’t support .txt attachments. Here is a workaround:
1. open blog.vim
2. modify “vimpress_%s_mkd.txt” to “vimpress_%s_mkd.odt”
Enjoy it.
[...] you’re using “Vim + VimRepress + Markdown + wordpress.com”, you might get the error message below when you execute :BlogSave xmlrpc error: Could not write file vimpress_xxxxxxxx_mkd.txt (Invalid [...]
@Bafu
Thanks for the help. This and some proxy fixes were also implemented on my fork last month by Raghu Rajagopalan.
[...] This is a pretty good step-by-step tutorial teaching you how to achieve that. Just follow it. [...]
Thanks for posting the tutorial on VimRepress…. it’s much nicer to not leave the terminal.
Thanks for the feedback! Although, this post is long outdated. You’ll find my updated branch on the github links above. Grabbed your RSS feed – looks interesting. My site has moved to connermcd.wordpress.com (free) for further posts.