Within vim I'd like to replace all
``` {.foo}
with
```foo
foo
can be anything.
:0,$ s/``` {\\.([^}]+)}/```\\1/
doesn't do the trick. It results in an
E486: Pattern not found: ``` {\.([^}]+)}
error. What regex can I use?
You need to escape (
and )
if you want to capture the group (otherwise it just represents opening/closing parenthesis). You also need to escape +
if you want it to mean one-or-more.
You also need to add the g
flag at the end to mean global-substitute (all occurrences in a line, not just the first one), unless gdefault
is on (in which case the g
actually removes the global flag). And you can also use :%s
to mean :0,$s
.
So :
:%s/``` {\.\([^}]\+\)}/```\1/g
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.