Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

replace

vim

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

like image 239
alexchenco Avatar asked Apr 30 '10 13:04

alexchenco


People also ask

How do I search for and replace text in Vim?

How do you search for a text in Vim? Press the / key, type your search text and press enter. This is just like the less command. But this method of finding text doesn't allow you to replace the found result. Let me share how you can find and replace in Vim.

How do I use the substitute command in Vim?

In Vim, you can find and replace text using the :substitute ( :s) command. To run commands in Vim, you must be in normal mode, the default mode when starting the editor. To go back to normal mode from any other mode, just press the ‘Esc’ key. The general form of the substitute command is as follows:

What does %% mean in Vim?

% is the range over which the :s command (short for :substitute) will be run. % itself is short for the range :1,$, which means Line 1 to the last line in the buffer. The Vim help has a couple topics (user manual - :help 10.3, reference manual - :help cmdline-ranges) describing the forms that ranges can take.

Where does Vim put the cursor when searching for a string?

Searches in Vim put the cursor on the first character of the matched string by default; if you search for Debian, it would put the cursor on the D. That’s usually fine, but Vim has a few options for offsetting the cursor placement from the beginning of the matched string.


1 Answers

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

:%s/\.html/.php/g 
like image 162
Samir Talwar Avatar answered Sep 20 '22 17:09

Samir Talwar