Vim Search Engine

Source: Internet
Author: User

Original article: http://ccd9527.blogspot.tw/2010/01/vim-search.html

If you want to find "Fat Boy", "Fat Boy", and "Fat Boy" in a file, a regular expression can be used.

/Feizi [zookeeper 」
It can be found that [] represents one character, but the three characters in the middle can be selected ~

If we are looking for an English file today and want to search for the lemon tree, lemon soup, and lemon juice, we must use the \ | or) calculation
/lemon
tree\|lemon soup\|lemon juice


What you want to search for is 1234-1234-5 1234-56 1234-567 1234-789 1234-2399-1234349898.

We can probably analyze that this string is about 1234 starting, followed by or not followed by "-", followed by a bunch of numbers. First, give the command to everyone:

/1234[-]\{,1}[0-9]\{1,}

Or:

/1234-[0-9]\{1,}\|1234[0-9]*

Let's take a look at the first method first. Two special things are used in the first method: \ {1,} And \ {, 1 }. In our statement above, if we do not keep up with any other things in the background, it means that a certain field in the middle section will appear once. Now \ {n, m} is used to indicate that the characters in the center can be selected. (A few characters will appear after the selection)

For example, \ {1,} indicates that at least once (at least once) is generated, and \ {, 1} indicates that at most once (at most once, if this option is not selected, the elements in the text box cannot appear ). Of course, we can also convert it to \ {3, 9}, which means we can select three to nine characters in the content, that is, three to nine characters are displayed, including characters.

In the second method, a "*" is followed in the lower part. In fact, \ {0 ,}, that is
0 to any. In the middle section, we use "0-9", which means that 0123456789 can be used. Similarly, for letters, we can also use "a-z" to represent all the English letters of the small shard and "a-z" to represent all the big shard letters.

Even so, we may not be enough. For example, can I only find a string starting with "cold" or "Master .」 End string?

If we only want to find the string starting with "Han", we can enter the SEARCH Command as follows:

/^ Leng Han

"^" Indicates that the East is the beginning of a line.

However, for typographical purposes, some blank spaces or tabs may appear before "cold". If we only use the preceding commands, we will not proceed. Therefore, we can achieve this by working with our weekly data center, including the secondary data:

/^ [\ T
<Space>] * Han


<Space> indicates a blank space because the web page may not be displayed. And "\ t" is
In vim, the preceding command represents any blank or a combination of tabs on the start of a line, followed by the word "Han.

What about the end? Remember how we moved the game logo to the end of the row? Use the "$" character. Therefore, you can use the string ending with "Main:

/Master $

However, you may not agree. For example, can Vim Help me find out what I forgot to say at the end of the sentence? Yes! Let's look at the instructions first:

/.*[^。]$

Or do not see the entire sentence:

/[^。]$

If the character "^" appears before the character "X", it means that all the elements except X are expected to be compared. Therefore, the first command above indicates that no sentence is found at the end of the sentence (this line must have at least one character, because [^] is used. $ Instead of [^.] * $ ). The second command is different from the second command. It only searches for the end of a sentence and does not end with a sentence. In fact, it depends on which command is used to compare the "eye-catching" command to you.

There are many more powerful functions related to these special operators. You can play H pattern in VIM command mode to see more detailed information. Or use: h regular to see the declarative statement about regular expression.

Now, you can use Vim debugging, debugging, and search. The basic Vim operations are almost the same.

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.