Vim Text Substitution command

Source: Internet
Author: User

Text substitution in vim:      1.   Replace the contents of the current line:    :s/from/to/    (S is substitude)          :s/from/to/    :   replaces the first from in the current line with a to. If the current row contains more than one                              from, only the first one is replaced.         :s/from/to/g    :   Replaces all the from in the current row with to.         :S/FROM/TO/GC   :   Replaces all the from in the current row with to, but each time the substitution is                               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   :   Replace operation on current line.         :33s/from/to/g &nbsp:   On line 33rd for the replacement operation.        &NBSP: $s/from/to/g   :   Replace on the last line.      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 row to the last row (that is, the entire 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 line between A and B, with the row where A and B are located.                                   where A and B are tokens that were previously made with the M 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/             replaces the string specified by the from with the string specified by to. The from can be a regular expression.         5.2 [range]              has some of the following presentation methods:             Do not write range   :   defaults to the line where the cursor is located.             .           :   CursorsThe line where you are located.             1            :   first line.             $            :   last line.             33           :   line 33rd.              ' a          &NBSP:   marks a row (previously marked with MA).             .+1         &NBSP:   The line below which the current cursor is located.             $-1         &NBSP:   Countdown second line. (This shows that we can add a value to a line                               to obtain a relative line).             22,33        :   Line 22nd to 33rd.             1,$         &NBSP:   1th line to the last row.             1,.        &NBSP:   1th line to the current line.             .,$         &NBSP:   Current row to the last row.              ' A, ' B       &NBSP:   marks a row to the row where Mark B is located.              %            :   All rows (equivalent to 1,$).           &nbSp;  ?chapter?   :   Search up from the current position, and the row where the first chapter is located. (                              where chapter can be any string or regular expression.             /chapter/  :   Search down from the current position, The row where the first chapter was found. (                              where chapter can be any string or regular expression.               Note that all of the above representations for range can be done by +,- Action to set the relative offset              shift amount.          5.3 [flags]              The flags available here are:            & nbsp;  no      :   Replaces only the first occurrence within a specified range.             g       :   Replaces all occurrences within the specified range.             c       :   Ask the user for confirmation before replacing.             e       :   ignores errors in the execution process.               NOTE: All flags above can be used together, such as GC Represents a replacement for all occurrences of              in a specified range, and the user is asked to confirm before each substitution.

Vim text Substitution command

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.