See also this fandom vim wiki page.
:s/find/replace/, only search in current line, and replace the first matched pattern
- Default: only in current line
- In all lines:
:%s/f/r/ - In selected line:
:'<,'>s/f/r/ - In selected characters:
:`<,`>s/f/r/
- Default: only first matched in given range
- match every one:
:s/f/r/g
- Reuse the matched pattern:
:s/f/&/&is the text that matches the search pattern.Example:
:s/[a-z]/&1/g, add a1after each characte:s/\(a\)/\1/\(a\)makes a backreference toa.\1is the first backreference,\2is the second backreference,\0is the text matched by the entire pattern.