How can I include the period (.) in Vim's search and replace command? (replacing .html extensions)?

28,437

Solution 1

Escape it. The . is a regex character which means "any character", so you need to escape it with \.

:%s/\.html/.php/g

Solution 2

Just escape the . character.

Search for /\.html

Solution 3

Try escaping period character: /\.html

Solution 4

Use backslach to escape the dot.

/\.html will look for ".html".

Share:
28,437
alexchenco
Author by

alexchenco

Programmer from Taiwan

Updated on October 29, 2020

Comments

  • alexchenco
    alexchenco over 3 years

    When I do: /.html Vim looks for html

    I would like to replace all the .html with .php

    Something like this: :%s/html ext/php ext/g

  • Tim Visée
    Tim Visée almost 6 years
    Note that the . is for any character except a new line.