vim Find and Replace Replace with or without Regular Expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

This substitute command can use Regular Expressions and will match any instance of foo followed by any( one ) character since the period . in Regular Expressions matches any character, hence the following command will match all instances of foo followed by any character in the current line.

:s/foo./bar/g
  1 fooing fooes fool foobar foosup

will become

  1 barng bars bar barar barup

If you want to match the literal . period you can escape it in the search field with a backslash \.

:s/foo\./bar/g
  1 fooing fooes foo.l foo.bar foosup

will become

  1 fooing fooes barl barbar foosup

Or disable all pattern matching by following the s command with no.

:sno/foo./bar/g
  1 fooing fooes foo.l foo.bar foosup

will raise an error

  E486: Pattern not found


Got any vim Question?