How to replace selected lines or specify text within several lines in vim

  question, vim

After reviewing the vim command list on the Internet, only the current line or the full-text replacement commands are replaced.

:' <,' > s/ replace/replace with /g

The following command replaces all strings idiots in the text with managers:


Usually we use% in the command to refer to the entire file as the replacement scope:


The following command specifies to replace only lines 5 to 15:


The following command specifies that only substitutions are made between the current line and the end of the file:


The following command specifies that only the following 9 lines will be replaced:


You can also use specific characters as replacement ranges. For example, replace all equal signs (=) in the FROM to semicolon section of SQL statements with unequal signs (< >):

:/FROM/,/; /s/=/<>/g

In the visual mode, first select the replacement range, and then enter: enter the command mode, you can use the S command to replace the text in the selected range.
VIM learning note Substitute(Anti-GFW may be required)