I have a file where I have comments like ######### Utility Functions #######
. I am trying to clean it up and make it something like # Utility Functions #
which requires me to match a string of more than one pound signs and replace it with a single pound sign.
I have tried the following
:%s/#+/#/gc
:%s/"#"+/#/gc
:%s/\#+/#/gc
:%s/(#)+/#/gc
and a bunch more. As I understand # has a special significance to match multiple characters like * but in reverse direction. This would mean that I would have to escape it somehow to achieve the above. Any help appreciated.
try that: :%s/\v#{2,}/#/g
#{2,} " 2, means at least two
There is a shortcut for "more than one" in most regex flavours: +
so
:%s/\v#+/#/g
works too, if you use "very magic" (\v
), see :h magic
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With