Vim 中的 Perl 正则表达式?
如何在 Vim 中编写这个 perl regex 替换命令? (摘自这个 pandoc epub 教程):
perl -i -0pe \
's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg' \
*/*.markdown
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不能代表
-i -0pe
标志,但正则表达式:将是:
请注意,您必须转义捕获组,并且我使用
.*
代替第二个捕获组中的[^\n]*
。您不需要多行标志。I can't speak for the
-i -0pe
flags, but the regex:Would be:
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.您要寻找的很多内容取决于您的“神奇”设置。有关 vim 字符字面意义的更多信息,请参阅
:help magic
。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.将现有的单行代码变成管道过滤器
然后在 Vim 中使用
1G!G
或:%!
通过该过滤器管道传输当前文件,例如Make your existing one-liner into a pipeline filter
Then use
1G!G
or:%!
in Vim to pipe the current file through that filter, e.g.