text.py : This is utility to easy access to vim buffer. For pythonic macrowriters
| script karma
Downloaded by 766
Comments, bugs, improvements
script versions (upload new version)
|This is text.py module for easy association of vim buffer to python language. Module provides Text-calss, which has access vim buffer contents, and has many of string, sequense and file-object methods. You may use slice, may use assignment to slice of buffer, and you can use step argument in this assignment in python 2.3 notation. You can use all of string methods like .upper(), .lower(), .center() etc. You can use many of sequence methods like .append(), .extend(), .reverse() etc. You can use a lot of binary operators like +=, *=; membership test "in" etc. Moreover, Text-instance provide some facilities to work with regular expressions including situations when text in buffer is in multibyte encoding. Searching takes place in unicode, but module provides some new match object: "NoUniMatchObj". This object has all of original match objects attributes but when you expect to get a string, you get a string not unicode. And when you expect to get address (byte-offset) you get address in encoded string too.
t = text.Text()
for i in t.re.finditer(my_regexp): # search my_regexp in buffer
t.replace_i(i.start(), # interactive replace fragment of
i.end(), # buffer from i.start() to i.end()
# where i is an instance of
["replasement one", # There are a lot of substitutions,
my_function(i), ...])# user can choose one of them.
pass # handler of Cancel button
t.center(80) # centering contents of buffer
t.apply_to_lines(my_other_function) # apply my_other_function line by line
Another powerful example you can see in vimscript#841
This utility very useful if you need to do python-substitution using confirmation dialogs, for example if you need to choose a lot of various replacements. This is useful too if you work with utf-8 encoding etc.
Russian mirror: http://python.anabar.ru/emin.htm#textpy
|1) Make in your harddrive some directory for python-vim programs (let it name is /pythonvim/). And put text.py into this directory.
2) Instract python to use this directory like sourse of modules. One way to do this is put following string into your .vimrc file:
:py import sys; sys.path.insert(0, r"/pythonvim/")
NOTE: in some systems you must put absolute address into sys.path list.
NOTE: be careful about slash direction, this is system-depended.
That is all. Happy vimming.
This program writen for Python 2.3. But it is already compatible with
Python 2.2. And for compatibility with Python 2.1 you may do some actions:
some code need to be comment and some to uncomment.
For compatibility with python 2.1 open this program in vim and execute
Be careful, use copy&paste:
1) put cursor after the colon and type y$
2) Then type : to go into command line and type <C-R>"
This command comment section using 'yield' statement and import generators
feature. Then it is uncomment compatibility blocks: raise instraction in
finditer() method and import nested_scopes feature.
For undoing this changes execute in vim following command:
Click on the package to download.
ip used for rating: 220.127.116.11