UltraBlog.vim: Ultimate Vim Blogging Plugin

Posted at — Apr 02, 2011
#Markdown #Plugin #Python #SQLAlchemy #SQLite #UltraBlog.vim #Vim #博客 #编程


UltraBlog.vim is yet another Vim blogging script for Wordpress.

The biggest difference between UB and other similar scripts is that UB is an ultimate client, which stores posts locally in an SQLite database, while others just operate remotely. In this way, many things can be done easily by the advantage of local storage and many other utilities, for example, you can search for posts stored in the database with a few keywords by typing a simple command, also you can preview drafts with any of your favorite templates as soon as you want to.

For those who just needs a lightweight blog editor similar as other Vim blogging scripts, UB also comes with an Editor Mode, which doesn’t create a database and store data in it.

In addition, UB is tending to make life easier for writing posts with many kinds of lightweight markup languages, currently the following kinds are supported: Markdown, reStructuredText, LaTeX, Textile and of cause HTML.

Enjoy Vim blogging !

Here is a post written in Chinese describing the motion for which I wrote UltraBlog.vim.




UltraBlog.vim takes advantages from the following techs:

You must have these prerequisites met before using UltraBlog.vim. For more information, refer to UltraBlog_Prerequisites in the help file.


Download UltraBlog.vim from Vim.org or retrieve the latest source from Github:


Install UltraBlog.vim to your plugin folder and put the following lines in your vimrc file:

let ub_blog = {'login_name':'admin',

" Set this option to 1 if you want to enable debug mode, see :help ub_debug for more information
let ub_debug = 0

" Set this option to 0 if you prefer using firefox or chromium to preview items.
let ub_use_ubviewer = 1

" Default timeout period of xmlrpc operations, see :help ub_socket_timeout for more information
let ub_socket_timeout = 10

" Default page size of local post list, see :help ub_local_pagesize for more information
let ub_local_pagesize = 30

" Default page size of remote post list, see :help ub_remote_pagesize for more information
let ub_remote_pagesize = 15

" Default page size of search result list, see :help ub_search_pagesize for more information
let ub_search_pagesize = 30

" Proudly show your visitors that you are blogging with the world's most powerful editor
let ub_append_promotion_link = 1

" Set width of the local id column in post or page lists
let ub_list_col1_width = 7

" Set width of the remote id column in post or page lists
let ub_list_col2_width = 8

" Set width of the status column in post or page lists
let ub_list_col3_width = 11

" Set this value to 1 if you want to use editor mode.
let ub_editor_mode = 0

" Set this value to 1 if you want to save posts/pages immediately after they are fetched from the blog.
let ub_save_after_opened = 0

" Set this value to 0 if you do not want to save posts/pages immediately after they are sent to the blog.
let ub_save_after_sent = 1

" Set the following options to use a custom extenal command as the converter.
let ub_converter_command = 'pandoc'
let ub_converter_options = ['--reference-links']
let ub_converter_option_from = '--from=%s'
let ub_converter_option_to = '--to=%s'

" Customize hotkeys
let ub_hotkey_open_item_in_current_view='<enter>'
let ub_hotkey_open_item_in_splitted_view='<s-enter>'
let ub_hotkey_open_item_in_tabbed_view='<c-enter>'
let ub_hotkey_delete_item='<del>'
let ub_hotkey_save_current_item='<C-S>'

" Set the link template string for images uploaded by :UBUpload
let ub_tmpl_img_url="markdown###![$(file)s][]\n[$(file)s]:%(url)s"

" Set the default template to use when previewing posts/pages locally
let ub_default_template="default"

Change values of the upper options to yours. Restart Vim and a database file will be created in the path you specified above.


It is important to understand some basic concepts of UltraBlog.vim.


UltraBlog.vim makes life easier while writing or updating blogs. It stores posts/pages in a local SQLite database. You can also set it to editor mode, in which UltraBlog.vim does not store data locally, just like other Vim blogging scripts.

By default, UltraBlog.vim is in client mode. You can set it to use editor mode by adding the fallowing line to the vimrc file:

let ub_editor_mode = 1


Currently, UltraBlog.vim manages three items: post, page and tmpl. “tmpl” is the shorthand of “template”.

Templates are used to preview the current post/page in the browser locally. This feature is a reparation for the remote previewing, due to the limit of the API, users cannot send a post to Wordpress as draft and preview it without affecting the post status if the post has been published.

With templates, users can preview posts/pages directly in the browser in a pre-defined style. They can create as many templates as they like and customize the look with CSS and HTML, or even Javascript.

Templates should be formatted as a valid python template string, that is, use the following avaliable placeholders and escape any literal ‘%’ with another ‘%’:

  1. %(title)s
    The title of the current post/page.
  2. %(content)s
    The content of the current post/page.
  3. %%
    A literal '%'.

There is a default template in the database, whose name is ‘default’, which can be used as an example of template.

Users can specify the default template to use with the option ub_default_template.


The syntaxes supported by UltraBlog.vim currently are:

markdown, html, rst, textile, latex.


The available statuses are:

publish, private, draft, pending.


Scopes tells UltraBlog.vim to operate on items in which place, “local” stands for items stored in the database, and “remote” stands for the blog.


Create a new item

:UBNew [item [syntax/template_name]]

Create a new item.

For the first parameter, refer to UltraBlog_Items. The default value is “post”.

If “item” is either “post” or “page”, the second parameter must be a syntax name, refer to UltraBlog_Syntaxes. The default value is “markdown”.

If “item” is “tmpl”, the second parameter should be the name of the new template.

When the cursor is focused in the metadata line of categories, press to do auto-completion. This will use the data set by option ub_blog[‘categories’], if it is not set, categories will be fetched from your blog.

Save a modified post


After executing this command, the current buffer is saved into database.

Send a post to blog

:UBSend [status]

Post an item.

If no parameter is given, UltraBlog.vim will send the item to blog and set it to be the value stored in the meta information area.

Refer to UltraBlog_Statuses.

List posts

:UBList [item [scope [page_size [page_no]]]]

List items.

Refer to UltraBlog_Items for the first parameter. The default value of this parameter is “post”.

The second parameter “scope” is only available when “item” is either “post” or “page”. Refer to UltraBlog_Scopes.

“page_size” and “page_no” are both for the situation when “item” is “post” and “scope” is “local”. The former stands for how many item will be listed a page. The latter stands for the page number.

For example:


This command lists the first page of local posts, by default, posts which have not been posted to blog are listed before the posted ones, and there are ub_local_pagesize posts a page.

:UBList post local 20 3

This command lists the third page of local posts, 20 posts a page. As you see, you can use this command to scroll forward or back between pages. As a matter of fact, there are two key mappings within local post list:

:UBList post remote 50

This command lists the latest 50 posts in the blog.

Pressing the ENTER key in a remote post list will open the post under cursor and save it to the local database if it is not in it, otherwise, the local copy will be opened instead of the remote one. This enables users to modify markdown source and update the remote post.

The remote post list doesn’t support paging.

Open a single post

:UBOpen {item} {post_id/template_name} [scope]

Open an item.

For the first parameter, refer to UltraBlog_Items.

If “item” is either “post” or “page”, the second parameter should be value of its id. If it’s “tmpl”, the name.

For “scope”, refer to UltraBlog_Scopes. The default value is “local”.

Upload a media

:UBUpload {file_path}

This command can only be executed in a post edit view, and the URL of the uploaed file will be appended in that buffer.

Preview the changes

:UBPreview [status/template name]

Preview the content of the current buffer.

If any of the UltraBlog_Statuses is given, the current buffer will be sent to the blog and then opened in the browser with a parameter “preview” appended to the URL.

If the given parameter is not a post status, a pre-defined template whose name is the same with the parameter will be used to preview the buffer locally.

If none is given, the default template is used.

You do not have to care for which syntax you use, markdown source will be translated into html automatically before a browser window is opened to display it.

The matter that whether to use the built-in web browser or the system default ones is controlled by the option ub_use_ubviewer.

Delete a post/page

:UBDel {item} {post_id/template_name} [scope]

Delete an item.

Refer to UBOpen for the usage of these options.

You can also delete items in the list by pressing the DELETE button on the target. In a local post list, if the post to be deleted has been posted to the blog, a confirmation will be prompted for you to decide whether to delete the remote copy cascadly.

Create a post/page using content of the current buffer

:UBThis [item [to_syntax [from_syntax]]]

Create a new post or page which is filled with content in the current buffer.

If no parameter is specified, the first parameter will be default to “post”; for the second and the third one, the syntax of the current buffer is used.

Content of the current buffer will be automatically converted from the from_syntax to the to_syntax.

Convert a post/page buffer between the available syntaxes

:UBConv {to_syntax} [from_syntax]

Convert the current buffer from ‘from_syntax’ to ’to_syntax’.

Refer to UltraBlog_Syntaxes.

If you only need to convert from Markdown to HTML, only python-markdown or python-markdown2 module is required. For other conversion scenarios, you must install pacdoc or use the options: ub_converter_command, ub_converter_options, ub_converter_option_from, ub_converter_option_to to specify a valid external command.

Refresh the current buffer


Full-text search

:UBFind keyword1 [keyword2 …]

Doing full-text searches for both posts and pages by keywords, all keywords will be highlighted. Page size of the search result list is controlled by option ub_search_pagesize.

:UBRegexSearch regexp1 [regexp2 …]

Doing full-text searches for both posts and pages by regular expressions, all strings that match the regular expressions will be highlighted. Page size of the search result list is controlled by ub_search_pagesize.

Full-text substitutions

Attention: Full-text substitutions will change contents of all matched posts/pages immediately when executed. You may need to backup your database file first.

:UBReplace needle replacement

Do full-text substitutions.

:UBRegexReplace regexp replacement

Do full-text substitutions using regular expressions.


In debug mode, SQL statements being executed will be displayed and so are all stack traces of exceptions raised.


Enable debugging.


Disable debugging.


Toggle debugging status.


For more detail information on tweaking UltraBlog.vim, refer to the documentation.



Posted via UltraBlog.vim.