Vim Simple Find and replace

Source: Internet
Author: User

Here is a simple introduction to the vim of the search and replace, it is well known that VIM support for regular expressions is very good, for programmers in the analysis of large amounts of data, the use of VIM this function is undoubtedly a weapon.

First of all, we need to understand some of the special meanings of vim:

^ Represents the beginning of the line

$ represents end of line

\d Representative Numbers

\d represents non-digital

[x, Y, z]: represents various conditions of choice

OK, so let's go over a few common topics and try it out:

1. Delete rows beginning with a number

%S/^\D.*$//IGC: Put this line into space

%S/^\D.*$\N//IGC: Delete this line directly, including the newline character, (note that it is \ n, not \ r \ n, because this is for the Linux platform, the next line will go to this line)

2. Delete the line starting with the number 3 or 4 or a

%S/^[3,4,A].*$//IGC: Set this line to empty

3.

1 IP 202.114.1.1.23444

2 IP 202.114.1.2.wokao

3 IP 202.114.1.3.woai23444

The request finally becomes

202.114.1.1

202.114.1.2

202.114.1.3

You can do this in the following order:

%s/\d.*ip//IGC

%s/\.\d*$//igc

%s/\.\d.*$//igc

Vim Simple Find and replace

Related Article

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.