The Replace command in VIM

Source: Internet
Author: User

Text replacement in Vim:     1.   Replace the contents of the current line:    :s/from/to/    (S is substitude)        : s/from/to/  & nbsp :   replaces the first from in the current row with the to. If the current line contains multiple                             The From, it will only replace the first A.        : s/from/to/g    :   replaces all from in the current line with to.        : S/FROM/TO/GC  :   Replaces all from in the current line with to, but before each substitution           & nbsp                 will ask the user to confirm this action.          Note: both from and to can be any string, where the from can also be a regular expression.      2.   Replace the contents of a line:      :33s/from/to/g       :. s/from/to/g  :   replaces the current line.        : 33s/from/to/g &nbsp:   On line 33rd for the replacement operation.        : $s/from/to/g  :   The last line for the replace operation.      3.   Replace the contents of some lines:      :10,20s/from/to/g       : 10,20s/from/to/g  :   Replaces the contents of lines 10th through 20th.        : 1, $s/from/to/g    :   Replaces the contents of the first line to the last line (that is, all text).        : 1,.s/from/to/g    :   Replaces the contents of the first line to the current line.        :., $s/from/to/g    :   Replaces the contents of the current row to the last row.        : ' A, ' bs/from/to/g  :   Replaces the lines between the marks A and B (with the rows where A and b are located).                                 where A and b are preceded by M The token that is made by the command.      4.   Replace the contents of all lines:      :%s/from/to/g       :%s/from/to/g  :   Replaces the contents of all rows.      5.   Replacement command in full form:    :[range]s/from/to/[flags]        5.1 s/from/to/      & nbsp     replaces the from specified string with the string specified by to, and from can be a regular expression.         5.2 [range]            The following are some of the ways to express: &nbsP           do not write range  :   The default is the line where the cursor is located.            .          :   The line where the cursor is located.             1          :   first line.             $          :   last line.            ,          :   line 33rd.             ' a          :   marks a row (previously marked with MA).             +1        :   The line below the current cursor.             $-1        :   Countdown second line. (This shows that we can add a value to a line                             to get relative rows).             22,33      :   22nd to 33rd line.             1,$        :   Line 1th to the last row.             1,.        :   line 1th to the current line.            , $        :   The current line to the last row.             ' A, ' B      :   Mark A's line to the row where Mark B is located.             ,          :   All lines (equivalent to 1,$).              Chapter?  :   Search up from current position, find the line where the first chapter is located.                             where chapter can be any string or regular expression Expression            /chapter/ :   Search down from the current location to find the row of the first chapter.                             where chapter can be any string or regular expression Expression              Note that all of the above representations for range can be set by the +,-action to the relative bias           & nbsp The amount of shift.          5.3 [flags]            The flags available here are:             no      :   Replaces only the first occurrence within a specified range.             g      :   Replaces all occurrences within the specified range.             C      :   Ask for user confirmation before replacing.             e      :   ignores errors during execution.              NOTE: All flags above can be used together, such as GC for the specified range of           and nbsp All occurrences are replaced, and the user is asked to confirm each time before the replacement.

Replace 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.