Kevin Burke
Kevin Burke

Reputation: 64924

How to search for a percent symbol (%) in Vim?

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

Upvotes: 10

Views: 8547

Answers (1)

Kevin
Kevin

Reputation: 56129

Nothing in this search needs escaping, :%s/<%/<?php/g works precisely as expected, replacing <% with <?php everywhere.

Upvotes: 15

Related Questions