Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find and replace curly braces { } in vim?

Tags:

replace

vim

I tried :s%/{//g and :s%/\{//g. How do I find and replace (remove, actually) braces in vim?

Thanks.

EDIT: I meant to have the % before the s, so I may have just been mistyping. Thanks everyone for the swift replies.

like image 461
ZenLikeThat Avatar asked Jun 27 '12 16:06

ZenLikeThat


1 Answers

An extension to @chaos

The { character (ie: left brace, not to be confused with bracket [, or parentheses ( )
... does not need to be escaped.

You probably mean to remove all braces. The percent symbol should be before the 's', not after. It means to perform the search on all ranges.

So, just do:

:%s/{//g
:%s/}//g

All done!

You should consider reading up on VIM ranges. For example, to do replacements on the current line and up to 10 lines down, you could do:

:.,.+10s/}//g
like image 136
Cloud Avatar answered Sep 19 '22 13:09

Cloud