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 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 before each substitution 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 on current line. : 33s/from/to/g : Replace operation 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 : Replaces the contents of the first row 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 : replaces the line between the marks 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 full form of the Replace 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] has some of the following representations: Do not write range : defaults to the line where the cursor is located ...          &NBSP: 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 which the current cursor is located. $-1 : Countdown second line. (This shows that we can add a value to a row to get a relative line). 22,33 : 22nd to 33rd line. 1,$ : 1th line to the last row. 1,.        &NBSP: 1th line to Current line ..., $ & nbsp: Current row to the last row. ' A, ' B : marks a row to the row where Mark B is located. % : All rows (equivalent to 1,$). ? 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/ : 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 relative to by using the +,-action Shift amount. 5.3 [Flags] The flags available here are: without : Replaces only the first occurrence within the specified range. G : Replaces all occurrences within the specified range. c : Request user confirmation before replacing. e : ignores errors during execution. NOTE: All flags above can be used together, such as GC for a specified range of All matches are replaced, and the user is asked to confirm each time they are replaced.
Vim Replacement Command Memo