Vim Replacement Command

Source: Internet
Author: User

to replace text 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 row with the to. If the current row contains more than onefrom, only the first one is replaced. : s/from/to/g: Replaces all from in the current row with to. : S/FROM/TO/GC: Replaces all from in the current row with to, but before each replacementask the user to confirm the 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: The replacement operation is performed on the current line. : 33s/from/to/g: The replacement operation is performed on line 33rd. : $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: replace the contents of the first line to the last row (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: Replace the line between the mark 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. The complete form of the replacement command:: [Range]s/from/to/[flags]5.1 s/from/to/replaces the from specified string with the string specified by to, and from can be a regular expression. 5.2 [Range]There are several ways to express this: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. 33: Line 33rd. ' A: The line where the mark A is located (previously marked with MA). . +1: The line under which the current cursor is located. $-1: The second line to the bottom. (This shows that we can add a value to a row toget a relative line). 22,33: Line 22nd to 33rd. 1,$: Line 1th to the last row. 1,. : line 1th to current line. ., $: The current line is to the last row. ' A, ' B: The line where Mark A is located is the row where Mark B is located.  %: All rows (equivalent to 1,$).  ? Chapter? : Searches up from the current position, and finds the row where the first chapter is located. (where chapter can be any string or regular expression. /chapter/: Searches down from the current position, and finds the row where the first chapter is located. (where chapter can be any string or regular expression.  Note that all of the above representations for range can be set by the +,-actionThe amount of shift.  5.3 [Flags]The flags available here are: None: Replaces only the first occurrence within a specified range. g: Replaces all occurrences within the specified range. C: Ask the user to confirm before replacing. e: Ignore errors in the execution process.  NOTE: All flags above can be used together, such as a GC for a specified range ofall occurrences are replaced, and the user is asked to confirm each time before the replacement.

Vim Replacement 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.