When using python to process text, we need to constantly learn in detail. Next, let's take a look at the specific use of python to process text in vim. Hope to help you. Complicated text processing often occurs in my work.
If the demand occasionally appears, it is enough to use vim to do it. For some fixed format analysis, and it is often repetitive, I have to let python free me. As you can imagine, development always makes things more and more amazing. Later, scripts have accumulated a bunch, and later I wrote a small text processing framework... Until yesterday, I thought of a more interesting thing, that is, to let python process text in the VIM script. Is it a little impatient? Don't worry about it. Start with the question ~
How to Use python to process text
Our goal is to list the records containing the name of January, and the behavior in the format of "name-description" is valid.
Compile the python script "jaypei.cnblogs.com. py ".
- # -*- coding: utf-8 -*-
- import re
- rere_obj = re.compile(r"^(\w*)((?!\-\-).)*\-\-.*January.*$", re.IGNORECASE| re.MULTILINE)
- for line in g_text:
- lineline = line.strip()
- r = re_obj.match(line)
- if r != None:
- print r.groups()[0]
Then input the following command in vim:
- :call JPython("jaypei.cnblogs.com.py")
Task completed:
The above is the specific operation process for python to process text in vim. Hope to help you.