-2

I have a TeX file that contains lines like

\[ De = 0 \]

Now my boss wants equation numbers so I want them to be like

\begin{equation}De = 0\end{equation}

I tried the following command by escaping the backslash with a backslash.

:%s@\\[@\\begin{equation}@gc

I think this should work but I am getting pattern not found error. I have looked at

How to include forward slash in vi search & replace

and

http://vim.wikia.com/wiki/Search_and_replace

Can somebody tell what am I doing wrong?

Community
  • 1
  • 1
  • Don't forget to accept answers that worked for you. That way other people that have the same question will see that it was already answered on first sight. – mhinz Aug 19 '13 at 08:52

1 Answers1

6

You have to escape both characters: :%s_\\\[ _\\begin{equation}_g.

EDIT: Since you also asked for an explanation:

Why escape the \?

Vim supports different pattern matching styles (see :help /magic), but escape characters have to be escaped in all of them.

Why escape the [?

[] in patterns are used as collections. Thus you have to escape the [ to match it literally.

mhinz
  • 3,291
  • 20
  • 20