VimRepress——用VIM来写博客

VimRepress 可以说是Vimpress的修改版吧 (Vimpress长期都没有更新。)
插件下载:
http://code.google.com/p/ptcoding/

http://www.vim.org/scripts/script.php?script_id=3510

https://github.com/connermcd/VimRepress
安装很简单,不用多说。

1
2
3
4
:BlogList  "列出blog中的所有文章
:BolgNew " 打开页面撰写心得文章
:BlogOpen id "打开文章进行编辑
:BlogSave "将文章保存到blog中

若要文档生效,记得更新下:

1
:helptags ~/.vim/doc

然后就是配置了,编辑~/.vimrc 或者 ~/.gvimrc ,添加如下内容:

1
2
3
4
5
6
7
8
"vimpress
let VIMPRESS=[{'username':'user0',
                 \'password':'pass0',
                 \'blog_url':'http://www.ihacklog.com'
                 \},
                 \{'username':'user',
                 \'blog_url':'http://your-second-blog.com'
                 \}]

如果有第二个博客就把后面那个也配置,否则就只要填写第一个喽。

发现保存的时候(:BlogSave )提示如下错误信息:

Markdown file uploading … vimpress_4ddeb1ec_mkd.txt
The package python-markdown is required and is either not present or not properl
y installed.

于是安装之:

1
sudo pacman -S python-markdown

然后重启vim ,OK了。

这篇文章就是用VIM 编辑和发布的。

更新:
发现用这个发布还是有些地方不方便,幸好又在网上找到了一个vimpress加强版(要是能把上面那个版本与这个版本合并就好了,可惜我不会python ):
http://wiki.yepn.net/vimpress
Vimpress 0.9 plus

增加功能:

增加SLUG功能
:BlogList 默认列出前10条日志 :BlogList 0 列出全部日志

增加< !–more–>截断后继续读取日志功能

:BlogCate 列出Blog中的文章分类

:BlogSave 直接把文章保存到草稿,修改发布后的日志用BlogSave保存后,日志状态变为草稿保存,文章修改后用BlogSend发布。

:BlogDel id 删除指定日志后,重新列出新的日志列表(默认10篇)确认删除成功

修正
:BLogNew时categoryName显示不正确
修改more截断问题,打开日志后more标签代码会替换为wordpress能识别的more方式

使用方法:

复制代码命令为blog.vim,代替原来文件即可。需要原Vimpress已经设置成功。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
" Copyright (C) 2007 Adrien Friggeri.
"

" This program is free software; you can redistribute it and/or modify
"
it under the terms of the GNU General Public License as published by
" the Free Software Foundation; either version 2, or (at your option)
"
any later version.
"
"
This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
"
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
" GNU General Public License for more details.
"

" You should have received a copy of the GNU General Public License
"
along with this program; if not, write to the Free Software Foundation,
" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
"
 
" Maintainer:   Adrien Friggeri <adrien @friggeri.net>
"
URL:      http://www.friggeri.net/projets/vimpress/
" Version:  0.9
"
Last Change:  2009 January 15
"
"
Commands :
" ":BlogList [count]"
"
  Lists recent <count> articles in the blog, default is 10, use 0 for all
" ":BlogCate"
"
  Lists recent catetory in the blog
" ":BlogNew"
"
  Opens page to write new article
" ":BlogOpen <id>"
"
  Opens the article </id><id> for edition
" ":BlogDel </id><id>"
"
  Del the article </id><id>
" ":BlogSend"
"
  Publish the article to the blog
" ":BlogSave"
"
  Draft the article to the blog
"
"
Configuration :  
"   Edit the "Settings" section (starts at line 63).
"

"   If you wish to use UTW tags, you should install the following plugin :  
"
  http://blog.circlesixdesign.com/download/utw-rpc-autotag/
"   and set "enable_tags" to 1 on line 50
"

" Usage :  
"
  Just fill in the blanks, do not modify the highlighted parts and everything
"   should be ok.
 
command! -nargs=* BlogList exec("
py blog_list_posts(<args>)")
command! -nargs=* BlogCate exec("
py blog_list_cates()")
command! -nargs=0 BlogNew exec("
py blog_new_post()")
command! -nargs=0 BlogSend exec("
py blog_send_post()")
command! -nargs=0 BlogSave exec("
py blog_save_post()")
command! -nargs=1 BlogOpen exec('py blog_open_post(<f -args>)')
command! -nargs=1 BlogDel exec('py blog_del_post(</f><f -args>)')
python < <EOF
# -*- coding: utf-8 -*-
import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re
 
#####################
#      Settings     #
#####################
 
enable_tags = 0
blog_username = '用户名'
blog_password = '密码'
blog_url = 'http://blog.yepn.net/xmlrpc.php'  
more_mark = '&more;'
more_code = '<!--more-->'
 
#####################
# Do not edit below #
#####################
 
handler = xmlrpclib.ServerProxy(blog_url).metaWeblog
edit = 1
 
def blog_edit_off():
  global edit
  if edit:
    edit = 0
    for i in ["
i","a","s","o","I","A","S","O"]:
      vim.command('map '+i+' <nop>')
 
def blog_edit_on():
  global edit
  if not edit:
    edit = 1
    for i in ["
i","a","s","o","I","A","S","O"]:
      vim.command('unmap '+i)
 
def blog_send_post():
  def get_line(what):
    start = 0
    while not vim.current.buffer[start].startswith('"
'+what):
      start +=1
    return start
  def get_meta(what):  
    start = get_line(what)
    end = start + 1
    while not vim.current.buffer[end][0] == '
"':
      end +=1
    return "
".join(vim.current.buffer[start:end]).split(":")[1].strip()
 
  strid = get_meta("
StrID")
  title = get_meta("
Title")
  slug = get_meta("
Slug")
  cats = [i.strip() for i in get_meta("
Cats").split(",")]
  if enable_tags:
    tags = get_meta("
Tags")
 
  text_start = 0
  while not vim.current.buffer[text_start] == "
"========== Content ==========":
    text_start +=1
  text_start +=1
  text = '\n'.join(vim.current.buffer[text_start:])
 
  parts = text.split(more_mark)
  if len(parts) == 1:
      content = parts[0]
      content_more = ''
  else:
      content = parts[0]
      content_more = parts[1]
 
  if enable_tags:
    post = {
      'title': title,
      'mt_text_more': content_more,
      'wp_slug': slug,
      'description': content,
      'categories': cats,
      'mt_keywords': tags
    }
  else:
    post = {
      'title': title,
      'mt_text_more': content_more,
      'wp_slug': slug,
      'description': content,
      'categories': cats,
    }
 
  if strid == '':
    strid = handler.newPost('', blog_username, blog_password, post, 1)
 
    vim.current.buffer[get_line("StrID")] = ""StrID : "+strid
  else:
    handler.editPost(strid, blog_username, blog_password, post, 1)
 
  vim.command('set nomodified')
 
 
def blog_new_post():
  def blog_get_cats():
    l = handler.getCategories('', blog_username, blog_password)
    s = "
"
    for i in l:
        s = s + (i["
categoryName"].encode("utf-8"))+", "
    if s != "
":  
      return s[:-2]
    else:
      return s
  del vim.current.buffer[:]
  blog_edit_on()
  vim.command("
set syntax=blogsyntax")
  vim.current.buffer[0] =   "
"=========== Meta ============\n"
  vim.current.buffer.append(""StrID : ")
  vim.current.buffer.append("
"Title : ")
  vim.current.buffer.append(""Slug : ")
  vim.current.buffer.append("
"Cats  : "+blog_get_cats())
  if enable_tags:
    vim.current.buffer.append(""Tags  : ")
  vim.current.buffer.append("
"========== Content ==========\n")
  vim.current.buffer.append("\n")
  vim.current.window.cursor = (len(vim.current.buffer), 0)
  vim.command('set nomodified')
  vim.command('set textwidth=0')
 
def blog_open_post(id):
  try:
    post = handler.getPost(id, blog_username, blog_password)
    blog_edit_on()
    vim.command("set syntax=blogsyntax")
    del vim.current.buffer[:]
    vim.current.buffer[0] =   ""=========== Meta ============\n"
    vim.current.buffer.append("
"StrID : "+str(id))
    vim.current.buffer.append(""Title : "+(post["title"]).encode("utf-8"))
    vim.current.buffer.append("
"Slug : "+(post["wp_slug"]).encode("utf-8"))
    vim.current.buffer.append(""Cats  : "+",".join(post["categories"]).encode("utf-8"))
    if enable_tags:
      vim.current.buffer.append("
"Tags  : "+(post["mt_keywords"]).encode("utf-8"))
    vim.current.buffer.append(""========== Content ==========\n")
    content = (post["
description"]).encode("utf-8")
    content_more = (post["
mt_text_more"]).encode("utf-8")
    if content_more !='':
        content = content + more_code + content_more
    for line in content.split('\n'):
      vim.current.buffer.append(line)
      vim.command('%s/\\n\('+more_code+'\)\\n/\\1/e')
    text_start = 0
    while not vim.current.buffer[text_start] == "
"========== Content ==========":
      text_start +=1
    text_start +=1
    vim.current.window.cursor = (text_start+1, 0)
    vim.command('set nomodified')
    vim.command('set textwidth=0')
  except:
    sys.stderr.write("An error has occured")
 
def blog_list_edit():
  try:
    row,col = vim.current.window.cursor
    id = vim.current.buffer[row-1].split()[0]
    blog_open_post(int(id))
  except:
    pass
 
def blog_list_posts(count=10):
  try:
    allposts = handler.getRecentPosts('',blog_username, blog_password, count)
    del vim.current.buffer[:]
    vim.command("set syntax=blogsyntax")
    vim.current.buffer[0] = ""====== List of Posts ========="
    for p in allposts:
      vim.current.buffer.append(("
%-7s\t" % p["postid"]) + (p["title"]).encode("utf-8"))
      vim.command('set nomodified')
    blog_edit_off()
    vim.current.window.cursor = (2, 0)
    vim.command('map <enter> :py blog_list_edit()<cr>')
  except:
    sys.stderr.write("
An error has occured")
 
def blog_list_cates():
  try:
    l = handler.getCategories('', blog_username, blog_password)
    del vim.current.buffer[:]
    vim.command("
set syntax=blogsyntax")
    vim.current.buffer[0] = "
"====== List of Category ========="
    for i in l:
        vim.current.buffer.append(i["categoryName"].encode("utf-8"))
        vim.command('set nomodified')
  except:
    pass
 
def blog_del_post(id):
  try:
    handler.deletePost('',id, blog_username, blog_password)
    allposts = handler.getRecentPosts('',blog_username, blog_password, 10)
    del vim.current.buffer[:]
    vim.command("set syntax=blogsyntax")
    vim.current.buffer[0] = ""====== New List of Posts ========="
    for p in allposts:
      vim.current.buffer.append(("
%-7s\t" % p["postid"]) + (p["title"]).encode("utf-8"))
      vim.command('set nomodified')
    blog_edit_off()
    vim.current.window.cursor = (2, 0)
    vim.command('map <enter> :py blog_list_edit()<cr>')
  except:
    pass
 
def blog_save_post():
  def get_line(what):
    start = 0
    while not vim.current.buffer[start].startswith('"
'+what):
      start +=1
    return start
  def get_meta(what):  
    start = get_line(what)
    end = start + 1
    while not vim.current.buffer[end][0] == '
"':
      end +=1
    return "
".join(vim.current.buffer[start:end]).split(":")[1].strip()
 
  strid = get_meta("
StrID")
  title = get_meta("
Title")
  slug = get_meta("
Slug")
  cats = [i.strip() for i in get_meta("
Cats").split(",")]
  if enable_tags:
    tags = get_meta("
Tags")
 
  text_start = 0
  while not vim.current.buffer[text_start] == "
"========== Content ==========":
    text_start +=1
  text_start +=1
  text = '\n'.join(vim.current.buffer[text_start:])
 
  parts = text.split(more_mark)
  if len(parts) == 1:
      content = parts[0]
      content_more = ''
  else:
      content = parts[0]
      content_more = parts[1]
 
  if enable_tags:
    post = {
      'title': title,
      'mt_text_more': content_more,
      'wp_slug': slug,
      'description': content,
      'categories': cats,
      'mt_keywords': tags
    }
  else:
    post = {
      'title': title,
      'mt_text_more': content_more,
      'wp_slug': slug,
      'description': content,
      'categories': cats,
    }
 
  if strid == '':
    strid = handler.newPost('', blog_username, blog_password, post, 0)
 
    vim.current.buffer[get_line("StrID")] = ""StrID : "+strid
  else:
    handler.editPost(strid, blog_username, blog_password, post, 0)
 
  vim.command('set nomodified')

另外又找到一篇文章:

http://simpx.me/2010/12/vimpress/

更多
6 Responses Post a comment
  1. Tiny

    :mrgreen: 额 用这个可以写wordpress的博客吧

  2. 万戈

    vim,反人类反社会啊!!!

  3. 荒野无灯

    没有 呢,呵呵,其实用这个写很方便的。不过缺点是其功能也有限制了。 :smile:

  4. 老饕

    这个折腾~~用linux,我宁愿在线写了,要不然用firefox那个扩展~

  5. 漠北

    这个看着很复杂呢,现在用的是微软的wlw2011写博客的,觉得还是不错的

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS