Posting to Wordpress from Vim with tags and Markdown
[tags]wordpress,vim,tagging,markdown,python[/tags] Only a certain kind of geek will delight in the following post.
I favor Vim for most of my text editing. I wanted to compose my WordPress entries with Vim, especially after finding a Vim syntax file for Markdown. Great! But how to post those entries into WordPress?
I found a way last night. A Berkeley student with the same itch, Kesava Yerra, wrote a Python Vim script that posts to WordPress. Supposing you've installed the Ultimate Tag Warrior plug-in for WordPress, his script even lets you tag your post. (An earlier version didn't have tagging.)
So to make this work, you first enable Ultimate Tag Warrior's "embedded tag support" (it's in WordPress's Options screen). Then open your Vim configuration file (.vimrc) and add the following code:
- python <<EOF
- import urllib
- import urllib2
- import vim
- import xml.dom.minidom
- import xmlrpclib
- blog_username = 'your_username'
- blog_password = 'your_password'
- blog_url = 'http://path.to.your.weblog/xmlrpc.php'
- def make_tags(text, numtags=5):
- params = urllib.urlencode({
- 'appid': 'upbylunch',
- 'context': text})
- u = urllib2.urlopen("http://api.search.yahoo.com/"
- + "ContentAnalysisService/V1/termExtraction",
- params)
- response = u.read()
- doc = xml.dom.minidom.parseString(response)
- tags = [str(i.childNodes[0].nodeValue)
- for i in doc.getElementsByTagName('Result')]
- return tags[:numtags]
- def post_blog(numtags=5):
- strid = ''
- offsetline = 0
- if vim.current.buffer[0].find('StrID:') != -1:
- strid = vim.current.buffer[0].split(':')[1]
- offsetline = 1
- title = vim.current.buffer[offsetline + 0]
- tags = vim.current.buffer[offsetline + 1]
- text = '\n'.join(vim.current.buffer[offsetline + 2:])
- # Tag condition
- if tags == '':
- tags = '[ tags\]' + ','.join(make_tags(text,
- numtags)) + '[ /tags]\n'
- else:
- tags = '[ tags]' + tags + '[ /tags]\n'
- content = tags + text
- wp = xmlrpclib.ServerProxy(blog_url)
- post = {
- 'title': title,
- 'description': content
- }
- if strid == '':
- strid = wp.metaWeblog.newPost('', blog_username,
- blog_password, post, 1)
- vim.current.buffer.append('\n')
- vim.current.buffer[:] = ['StrID:' + strid] + [i
- for i in vim.current.buffer[:]]
- else:
- wp.metaWeblog.editPost(strid, blog_username,
- blog_password, post, 1)
- vim.command('set nomodified')
- EOF
(Note: remove the whitespace from '[ tags]' and '[ \tags']) All set? Now you can compose in Vim, using the following format:
Title
your,tags,separated,by,commas (to auto-tag, leave line blank)
The content of your post...
When you're ready, issue this Vim command:
:py post_blog()
After a heartbeat, your entry is posted to WordPress (or to any blog that supports the Metaweblog API).
Oh, before I forget, you are going to have to assign Categories to your post manually in WordPress's Manage Posts panel.
I write using Markdown and, for syntax highlighting in Vim, I find Markdown Vim Mode to be indispensible. (I'll cover installation in a later post, as I had some trouble with it.) So to activate that, I save my entries with an *.mkd extension. The Markdown looks pretty. I write my post. Then I type :py post_blog() to publish.
I'm delighted.



Starting post:Posting to Wordpress from Vim with tags and Markdown by at Google Blog Search: markdown
Pingback by Markdown — 10th Jun, 2006, 7:13 am
Starting post:Posting to Wordpress from Vim with tags and Markdown by at Google Blog Search: markdown
Pingback by Markdown — 10th Jun, 2006, 3:04 am
Sandbox · plaintxt.orgEinloggen - WordDokuBluesome - Exec-PHP plugin for WordpressWarpspire » Hemingway for WordpressGoogle Analytics and Feedburner Reports plugin for WordPress : tan tan noodles - msg free since 2005Posting to Wordpress from Vim with tags and Markdown » Tri NguyenMySQL Connection Management in PHP - How (Not) To Do Things - Jay PipesCustom WordPress Database Error - 5ThirtyOne - Refreshing isn’t it?Wordpress: Ultimate Tag Warrior 3
Pingback by Polska Planeta WordPress’a — 15th Aug, 2006, 10:45 pm
By egwynn on June 12th, 2007. 0 Comments The greatest text editor in the world strikes again. A small vim plugin using python makes it possible for me to post to my wordpress without a web browser, and without a super-fancy blog-posting program. This is ideal for a geek like me who doesn’t need software packed with features to do simple blogging. Go Vim!
Pingback by Woxidu — 12th Jun, 2007, 4:38 am
de Christophe Blaess et pour le moment, je trouve ce langage très élégant et plutôt agréable à utiliser... Bon j'ai juste pondu 18 lignes de code très inspirées d'un petit hack permettant de poster sur un blog Wordpress depuis Vim . Pour le moment mon code permet d'afficher dans un buffer vim les groupes de classes, les nom des classes et leurs attributs extraits du XML généré par l'extension eZ Publish SmileClasses (la même utilisée par le plugin Eclipse), c'est un début.
Pingback by Blog - ~tigrou/pwet.fr — 28th Mar, 2007, 9:54 pm
writing interface again… from my Mac anyhow. (Update it seems you can still get the main tagging stuff to work if you turn on ‘embedded tag support’ in UTW and then use the SimpleTag format. Cool! Thanks to this blog post about posting from vim of all things, for the hint!)
Pingback by lifebsideben — 6th May, 2007, 5:47 am
, che viene poi successivamente convertito in HTML. A differenza dell’HTML, è molto più leggibile e non contiene centinaia di inutili tags. Insomma, fatto sta che mi sono ritrovato a leggere questovecchio postsu come utilizzare Markdown con Vim e magicamente anche con Wordpress. Il link allo script nel post sembra essere morto, ma grazie ai poteri della blogosfera e dell’antani, ho trovato una più che valida alternativa:
Pingback by molok’s nest — 28th Apr, 2008, 2:18 am
Glad you found it useful!
by Kesava Yerra — 16th Jun, 2006, 1:25 am
Using vim for editing Posts was my number 1 reason to use (py)blosxom, but what you are presenting me here is the number 1 reason to use Wordpress.
by René — 15th Aug, 2006, 5:26 am
Um... this is sweet. I wasnt aware of such a feature in vim
by Paul Cline — 26th Aug, 2006, 8:34 am
[...] Tonight I think I stumbled on a potential solution. Tri Nguyen has a nice post about how to use a Python enabled Vim to post directly to WordPress. Although I cannot seem to dial in the Markdown part of her scheme, the Vim-WordPress post capability is scratching an itch for me. Filed under: Vim — serge @ 9:17 pm [...]
Pingback by In the twinkling of an eye » Vim and WordPress — 12th Jan, 2007, 10:31 am
Excellent! Thanks a lot for posting this--I'm going to try writing a similar integration for Django.
by whiteinge — 15th Mar, 2007, 10:49 am
[...] Posting to Wordpress from Vim with tags and Markdown » Tri Nguyen adding this to the todo list (tags: vim wordpress) [...]
Pingback by links for 2007-03-20 | christian wilcox dot com — 19th Mar, 2007, 6:27 pm
Bless you, vim nerd.
by Paul Smith — 16th Apr, 2007, 8:07 pm
[...] Ceci est assez experimental, je suis en train d’écrire cet article dans mon éditeur de texte favori1. J’ai pour cela écrit un plugin, largement inspiré de ceci2. [...]
Pingback by Friggeri.net : Archive : Vimpress ! — 13th Jul, 2007, 8:15 am
Hi ! I just discovered this handy little tool a few days ago, and decided to make a more complex version of it.
By more "complex" version, I mean that it allows to list articles posted on the blog, edit articles, and of course send new articles. It supports tags by using a plugin, but you can of course disable those.
It (should) work correctly.. You can find it here : http://www.friggeri.net/blog/2007/07/13/vimpress/
Adrien
by Adrien .F — 13th Jul, 2007, 8:27 am
[...] Posting to Wordpress from Vim with tags and Markdown » Tri Nguyen Says: June 15th, 2006 at 11:48 am [...]
Pingback by Wordpress Posting Vim Script « not.upbylunch — 10th Aug, 2007, 9:47 pm
[...] This is quite experimental (and unmaintained): I’m currently writing this article using the only decent text editor: Vim. That’s why I wrote a plugin inspired bye this one [...]
Pingback by Friggeri.net » Blog Archive » Vimpress ! — 10th Mar, 2008, 1:15 am
[...] This is quite experimental (and unmaintained): I’m currently writing this article using the only decent text editor: Vim. That’s why I wrote a plugin inspired by this one [...]
Pingback by Syntactic Sugar » Blog Archive » Vimpress ! — 11th Mar, 2008, 10:08 pm
[...] Your page is on StumbleUpon [...]
Pingback by Your page is now on StumbleUpon! — 5th Apr, 2008, 6:16 pm
[...] As a dedicated Vim user, particularly after MacVim received some much-deserved attention, I was happy to read this post by Tri Nguyen: Posting to Wordpress from Vim with tags and Markdown”. [...]
Pingback by Blog from Vim at De-escalate — 27th Aug, 2008, 7:36 am
[...] posted here: Tri Nguyen » Posting to Wordpress from Vim with tags and Markdown Tags: [...]
Pingback by wp-popular.com » Blog Archive » Tri Nguyen » Posting to Wordpress from Vim with tags and Markdown — 18th Feb, 2010, 2:34 pm