gvlasov
gvlasov

Reputation: 20015

How to search for plain text instead of a regular expression?

For example, I want to delete untill the next </p> tag. Doing

d/</p>

Won't work since </p> is treated as a regular expression. Can I specify a plain text search pattern somehow?

Upvotes: 5

Views: 1067

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172570

There are two things that need to be changed for a literal search:

  • The search delimiter (here: /) must be escaped with a backslash (d/<\/p>). If this were a pattern in a :substitute command, you could have also used a different delimiter (:s#</p>##), but for the / search command, you have to escape it.
  • There are plenty of characters with special meaning in a regular expression. Instead of remembering and escaping them all, it's easier to change Vim's regular expression parsing to very nomagic mode via \V; then, only the backslash itself needs escaping. Your example pattern doesn't suffer from this, but it is relevant for characters like . and *.

Upvotes: 9

digger
digger

Reputation: 74

escape the slash with a backslash: d/<\/p>, although I am not sure if this will work, depending upon what the format of your file is. You might have to do something more of the form :.,/<\/p>/d.

Upvotes: 2

Related Questions