How to Use python to process text in vim

Source: Internet
Author: User

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 ".

 
 
  1. # -*- coding: utf-8 -*-  
  2. import re  
  3. rere_obj = re.compile(r"^(\w*)((?!\-\-).)*\-\-.*January.*$", re.IGNORECASE| re.MULTILINE)  
  4. for line in g_text:  
  5. lineline = line.strip()  
  6. r = re_obj.match(line)  
  7. if r != None:  
  8. print r.groups()[0] 

Then input the following command in vim:
 

 
 
  1. :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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.