Also, as another example of Python's flexibility, it can be used as the embedded scripting language for VIM. While writing this article, I grew tired of manually replacing > with >, so I composed the following function and put it in ~/vim-htmlify.py:
# a little macro for VIM that helps when composing HTML documents
import vim, string, htmlentitydefs
htmlequivs = {}
# swap built-in table, we want a dictionary indexed by
# characters that can't be used.
for key, value in htmlentitydefs.entitydefs.items():
if key != "amp":
htmlequivs[value] = key
def htmlify():
for i in range(0, len(vim.current.range)):
cLine = vim.current.range[i]
cLine = string.replace(cLine, "&", "&")
for badchar in htmlequivs.keys():
cLine = string.replace(cLine, badchar, "&" + h
tmlequivs[badchar] + ";")
vim.current.range[i] = cLine
print len(vim.current.range), "line(s) HTMLified"
and put this in ~/.vimrc:
pyfile ~/vim-htmlify.py
map h :py htmlify()<CR>
With the touch of "h", I could convert <b>Foo Bar</b> into &lt;b&gt;Foo Bar&lt;b&g. This is yet another example of the power and ubiquity of Python!
-- DetlevLengsfeld 2006-12-30 18:23:14
| /Scite /Vim |
Tags: scite | editor | python | integration
Python/Edit/Vim (last modified 2008-11-04 07:00:07)