Reputation: 61091
How can I write this perl regex replace command in Vim? (Taken from this pandoc epub tutorial):
perl -i -0pe \
's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg' \
*/*.markdown
Upvotes: 2
Views: 1752
Reputation: 901
A lot of what you are looking for is dependent on what you "magic" setting is set to. see :help magic
for more info on what charctors vim takes literally.
Upvotes: 3
Reputation: 2847
Make your existing one-liner into a pipeline filter
perl -pe 's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg'
Then use 1G!G
or :%!
in Vim to pipe the current file through that filter, e.g.
:%!perl -pe 's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg'
Upvotes: 0
Reputation: 20270
I can't speak for the -i -0pe
flags, but the regex:
s/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg
Would be:
s/^Insert\s*\(.*\).png\s*\n\(.*\)$/!\[\2](..\/figures\/\1-tn.png)/g
Note that you have to escape the capturing groups and that I used .*
instead of [^\n]*
in the second capturing group. You don't need a multi-line flag.
Upvotes: 4