Vim Recall繁體中文

Match context, replace only the value

:s/id=\zs\d\+\ze;/42/

Example

Normal mode. Line: id=17; other=99;.

Before
id=17; other=99;
  1. :s/id=\zs\d\+\ze;/42/<CR> Replace digits between id= and ; · id=42; other=99;
After
id=42; other=99;
Details & Vim help

Use \zs and \ze to set match boundaries inside a larger pattern.

Change a value while leaving its identifying prefix and suffix intact.

The surrounding text must still match. The example uses Vim’s default magic syntax, where \d matches a digit and \+ means one or more.

Try it in Vim

  1. Run :s/id=\zs\d\+\ze;/42/<CR>.
  2. The pattern requires id= before the digits and ; afterward.
  3. Only the digits between \zs and \ze are replaced.