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:

:1,$s/idiots/manages/g

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

:%s/search/replace/g

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

:5,15s/dog/cat/g

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

:.,$s/dog/cat/g

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

:.,.+8s/dog/cat/g

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)