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
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.
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:
% 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.
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.
Escape it. The .
is a regex character which means "any character", so you need to escape it with \
.
:%s/\.html/.php/g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With