How to find and replace in vim

Source: Internet
Author: User

"%s//second/g"

People with vim know that this is to replace all the "most" with the meaning of "second". In fact, Vim's search and replace function is very powerful, good use can greatly improve efficiency.

The Find and replace command for VIM is as follows: :{作用范围}s/{目标}/{替换}/{替换标志}

    • Scope of Action:
      • Current Line S
        :s/most/second/g replace all "most" of the current line with "second"
      • Full-Text%s
        :%s/most/second/g replace All "most" of the full text with "second"
      • 8-15 row 8,15s
        :8,15s//g/second to replace all "most" of the 8-15 rows with "second"
      • The current line and the next 5 rows . , +5s
        :., +5s/most/second/g replace the current line with all "most" of the next 5 rows to "second"
    • Target: Support Regular expressions
    • Replace flag:
    • :%s/most/second/GC replace All "most" of the full text with "second", but each one needs to be confirmed
        • At this point each replacement will prompt: Replace with second (y/n/a/q/l/^e/^y)?
        • Y confirm the replacement of the current "most"
        • n does not replace the current "most"
        • A Replace All
        • Q Exit Find mode
        • L Replace the current position and exit
        • ^e window moves down one line
        • ^y window Move up one line

How to find and replace 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.