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


Solution 1

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:


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:


Solution 2

You should put % before s to replace it in the whole file not only on current line:


Solution 3

:s/{//g works fine. Why in the world are you putting that % after the s? By doing that you're indicating % as your regex delimiter character, which is making the rest of your pattern not work because it's written as if / were your delimiter character.

Oh, I see, you mean :%s/{//g.

Author by


Updated on July 28, 2022


  • ZenLikeThat
    ZenLikeThat 2 months

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


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