Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace parenthesis in vim

Tags:

regex

vim

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.

like image 233
Jogusa Avatar asked Oct 27 '09 15:10

Jogusa


People also ask

How do I add a bracket in Vim?

Explanation. If you want to put the word under the cursor in to brackets this is viwc()<Esc>P . viw will v isually select all charactrs i n a w ord. c() will c change the selection and by dropping you into insert mode, where you type the characters ( ) .


3 Answers

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

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

See:

:help magic

Edit

Added backslash escaping of dot.

like image 111
DrAl Avatar answered Oct 23 '22 10:10

DrAl


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

like image 21
willoller Avatar answered Oct 23 '22 10:10

willoller


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.

like image 34
Adriano Varoli Piazza Avatar answered Oct 23 '22 10:10

Adriano Varoli Piazza