How to find and replace curly braces {} in vim?

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

Thanks.

EDIT: I meant% to s, so maybe I was just wrong. Thanks to everyone for the quick answers.

+6
source share
3 answers

@Chaos extension

The symbol { (i.e., the left bracket, which must not be confused with the bracket [ or parentheses ( )) ... does not need to be escaped.

You probably want to remove all curly braces. The percent sign must be before 's', not after. This means performing a search in all ranges.

So just do:

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

Done!

You should consider reading on VIM bands. For example, to make replacements in the current line and up to 10 lines down, you can do:

 :.,.+10s/}//g 
+11
source

:s/{//g works fine. Why in the world do you put this % after s ? In doing so, you specify % as the regex separator character, which makes the rest of your pattern work not because it was written as / . It was a delimiter character.

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

+5
source

You have to put % to s in order to replace it in the whole file, not only in the current line:

 :%s/{//g 
+4
source

Source: https://habr.com/ru/post/919157/


All Articles