I'm trying to do a global find and replace for old-style PHP tags that look like this:
<%= $username %>
However when I try to do a search and replace in Vim, I get an "E71: Invalid character after \%" warning, and a "E476: Invalid command" warning:
:%s/\<\%/other val/c
I've also tried:
:%s/\<\\%/other val/c " two escapes, returns no matches
At the beginning of a Vim command line statement, you can specify a range over which to operate. % is a common range for specifying the whole file, shorthand for 1,$ , i.e. line 1 to end of file. See See :h cmdline-ranges for more.
note that another usage of the % character in bash is if a program such as vim is suspended with ctrl-z , then the %vim command resumes it, like fg .
Nothing in this search needs escaping, :%s/<%/<?php/g
works precisely as expected, replacing <%
with <?php
everywhere.
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