在vim中我想找到一个字符串并在字符串的每个字符之间插入空格 [英] In vim I want to find a string and insert spaces in between each character of the string
本文介绍了在vim中我想找到一个字符串并在字符串的每个字符之间插入空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试以一种简单的方式使用正则表达式和捕获组进行搜索和替换,但不知道如何进行.
I have been trying to search and replace with regex and capture groups in a simple way, but have no idea how.
假设我想对前面的句子进行操作,捕获trying"并替换为t r y i n g".
Let's say I want to operate on the previous sentence capturing "trying" and replacing with "t r y i n g".
:%s/\vtrying{-}/ \1/g
推荐答案
您有一个解决方案,但这里有一个不同的解决方案:
You have a solution, but here is a different one:
%s/trying/\=join(split(submatch(0),'\zs'), ' ')/g
这应该比替换()调用快一点,这并不重要.
That should be a little bit faster than the substitute() call, not that this matters much.
这篇关于在vim中我想找到一个字符串并在字符串的每个字符之间插入空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文