Vim replaces the specified string

Source: Internet
Author: User
Tags alphanumeric characters
Search and replace Vim

  • Replacement in search
    /Which # search whichcwthat # Replace with thatn # repeat search. # repeat replacement
  • Replacement command of one type
    g/pattern/s/old/new/g

    FirstGIndicates that an operation is selected,PatternSpecifies the row mode,SIndicates the replacement operation,OldIs the content to be replaced,NewIs new content,
    GGlobal replacement:

    # Add an arc to the first to ten rows /.*/(&)/

    The

    & Indicates the search mode ~ Indicates that the replacement text \ U specified in the previous replace command is changed to uppercase \ L to lowercase \ U or \ L and \ e or \ e. all payments until \ e and \ e are in uppercase or lowercase. In addition, in VI, \, ", and | any non-alphanumeric characters other than the delimiter used to replace the command, which is very useful in path replacement.

    The following are examples:

    # Replace that or this with this or that: % S/\ (that \) or \ (this \) /\ U \ 2 or \ L \ 1/---- # Replace child at the end of the sentence with children: % S/child \([,.;! :?] \)/Children \ 1/G ----# Change Wi-Fi or Wi-Fi to WLAN: G/\ c/s/Wi-Fi/WLAN/g----  # Change MGI/R/abox to MGI/R/asquare: G/Mg \ ([Ira] \) box/S // mg // my \ 1 square/g <=>: g/mg [Ira] box/S/box/square/G ---- # Replace multiple spaces with one space: % S/* // G ---- # use a space to replace one or more spaces after a period or a colon: % S/\ ([:.] \) */\ 1/G ---- # delete all blank rows: G/^ $/D ---- # delete all blank rows and blank rows: g/^ [] [] * $/D ---- # insert two blank spaces at the beginning of each line: % S/^/>/---- # Add at the end of the next 6 rows. :., 5/$ /. /---- # reverse the row order of the file: G /. */m0o <=>: G/^/m0o ---- # search for the starting line that is not a number and move it to the end of the file: G! /^ [0-9]/M $ <=> G/^ [^ 0-9]/M $ ---- # Copy 10 words from lines 12th to 17 of the file to the current end of the file: 1, 10g/^/12, 17 T $ ~~~~ The number of repetitions ---- # Write the content in the second row below the beginning of chapter into the begin file: G/^ chapter /. + 2 W> begin ----:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin ----:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin | + T $

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.