How can I replace parenthesis in vim

24,959

Solution 1

Vim doesn't require escaping of brackets by default. Try:

:%s/(fig\.)//g

See:

:help magic

Edit

Added backslash escaping of dot.

Solution 2

Don't escape the parens - vim by default uses a "magic" escaping scheme. Try:

:%s/(fig\.)//g

More info: http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\v

Solution 3

On Vim 7.2 (WinXP), the command you used only removes 'fig.', but not the parentheses. Using %s/(fig\.)//g gives the intended result.

Edit Escaped the dot too, as it matches any character, not just a dot.

Share:
24,959
Jogusa
Author by

Jogusa

Updated on July 09, 2022

Comments

  • Jogusa
    Jogusa almost 2 years

    In Vim I have:

    simulación (fig.),pretexto (fig.),excusa (fig.).
    

    My goal is:

    simulación ,pretexto ,excusa .
    

    I have tried with: :%s/\(fig\.\)//g, but it doesn't work.

  • Adriano Varoli Piazza
    Adriano Varoli Piazza over 14 years
    Isn't Vim using the content between the escaped parentheses as a group, then throwing it away? It's a significant distinction in that case.
  • DrAl
    DrAl over 14 years
    @Adriano: It is indeed and this wasn't what @Jogusa wanted.
  • Jogusa
    Jogusa over 14 years
    Thanks a lot, it works :-) Thank you for the second tip, too.
  • DrAl
    DrAl over 14 years
    This will also match (figx) if you don't escape the dot (see my and Adriano's edit: we all did this!).