Find a specified string using the Find command in VIM

Source: Internet
Author: User

To search up from the current cursor position, use the following command:

/pattern Enter

Where pattern represents a specific sequence of characters to search for.

To search down from the current cursor position, use the following command:

? pattern Enter

When the ENTER key is pressed, vi searches for the specified pattern and positions the cursor at the first character of the pattern. For example, to search up the word for place, type:

/place Enter

If VI finds place, it will position the cursor at p. To search for additional matches for place, press N or N:

N, continue searching for place in the same direction.

N, search in the opposite direction.

If VI does not find the specified pattern, the cursor position is unchanged and the following message is displayed at the bottom of the screen:

Pattern: Not Found

4.5.1 Search for special matches
In the example above, VI finds any sequence containing place, including displace, placement, and replaced.

To find a single place, type the word and add a space before and after it:

/Place Enter

To find place that appears only at the beginning of the line, add a caret (^) before the word:

/^place Enter

To find place only at the end of a line, add a currency symbol ($) after the word:

/place$ Enter

Use ^
To search for this character with the caret (^) or currency symbol ($) Verbatim, add a backslash (\) before the character. Backslash Command VI searches for special characters.

Use $
Special characters are characters that have special features in VI (for example, ^, $, *,/, and.). For example, $ usually means "go to end of line", but if $ is immediately preceded by a \, then $ is just a normal character.

Use
For example,/(no \$ money) searches up the character sequence (no $ money). Immediately before the escape character (\) Command VI searches the currency symbol verbatim.

(Reprinted from: http://sucre.blog.51cto.com/1084905/270556)

Find a specified string using the Find command in VIM

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.