Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

replace

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
like image 899
Kevin Burke Avatar asked Jun 03 '12 20:06

Kevin Burke


People also ask

What does percent do in Vim?

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.

What Is percent sign in bash?

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 .


1 Answers

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

like image 88
Kevin Avatar answered Oct 19 '22 19:10

Kevin