Vim+Markdown写Wordpress博客

什么是Markdown

在上一次的博文中我已经介绍过了,不了解的点此进入传送门。那次只是顺口提了提如何用Vim去写Markdown,这篇文章就来教教大家具体的怎么去做。

准备工作

安装和配置插件

插件的选择必然是VimRepress的无疑,下载地址。关于这个插件的前身,便是VimPress了,只不过那个已经没有人来维护,所以一些国外的网友将其改写重构后,改名为VimRepress,其实从名字都能看得出来。 将下载的zip包,解压然后得到三个文件夹,分别放到你Vim的相关同名文件夹的底下。然后用Vim打开blog.vim,利用/Settings找到下面的代码:
######################      Settings     ######################

blog_username ='xxxx'
blog_password ='xxx'
blog_url ='http://www.domon.cn'

image_template ='<img title="%(file)s" src="%(url)s" class="aligncenter" /
将其中的username和password中xxx替换成你的Wordpress后台登录的帐号密码,url后面填入你的blog地址。这样就完成了配置的工作。

基本语法

VimpressCommands:>:BlogList[<count>]<Lists post titles in your blog, defaultly recent 30,use an arg. to specify.>:BlogNew<Openfor a new post.Contentsin current buffer will append in the post edit area.>:BlogOpen<id><Open a post <id>for editing.>:BlogSave<draft|publish><Saves the post, defaultly as draft, an arg. to specify.>:BlogPreview<draft|publish><Sameas:BlogSave, will open a browser to preview current post.You have to login in your browser to preview the draft post.>:BlogUpload<file><Upload media file to blog.Appends img element after cursor.>:BlogCode[<code type>]<Append a section of a <pre> element, which could be hilighted by wp-syntax plugin.When give a code type, will fillin the element for syntax.
  • BlogList <count> 列表文章,可以用参数定义列出多少篇文章。默认最近30篇。
  • BlogNew 新文章命令,会将当前的buffer内容作为文章的内容。
  • BlogOpen <id> 打开文章,需要手动输入post id.
  • BlogSave <draft|publish> 保存文章,可以保存为草稿、或者直接发布。
  • BlogPreview <draft|publish> 预览文章,实际和BlogSave命令相同,之后会打开浏览器窗口预览文章。但如果你是保存成草稿的,还得在浏览器登录才能看到。
  • BlogUpload <file> 可上传图片等文件到博客。自动添加链接代码到光标后。
  • BlogCode <code type> 代码片段,添加一个<pre>元素的块,对程序博客特别有用,目前默认用wp-syntax插件的高亮模式。

使用方法

打开Vim输入:
:BlogList QQ截图20131208211516
就能看见你博客中所有的文章了,如上图。为什么是乱码,嗯,是因为编码的关系,那咋们继续:
:set encoding=utf-8 QQ截图20131208212833
如此一来中文就可以圆满的显示了,虽然可能你的Vim窗口会有写乱码不过不要紧,下次启动时候又会还原了。 当咱们要写一篇新的Blog的时候,就要使用BlogNew命令,写完之后的保存分为两种: 1.利用:BlogSave保存为draft 2.直接通过:BlogSave publish发布到WP中 OK,来试试吧~希望大家都可以能拿Vim来写作。