如何在由:g执行的cmd中使用向后引用? [英] How do I use a back reference in the cmd executed by :g?
本文介绍了如何在由:g执行的cmd中使用向后引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
回答>仅在有,我注意到我的回答并不令人满意:模式\ \+$
必须键入两次:
When answering Remove EOL spaces of selection only if there are, I noticed that my answer is not really satisfying: the pattern \ \+$
has to be typed twice:
- 一次使用
:g
搜索
- 一次替换为
:s
- once for searching with
:g
- once for replacing with
:s
首先想到的是简单地使用g/\(\ \+$\)/s/\1//g
,但这给了我一个关于无效反向引用的错误(
First thought was to simply use g/\(\ \+$\)/s/\1//g
but this gives me an error about an invalid back reference (E65
).
是否可以重用 :g
要执行[cmd]
吗?
推荐答案
您不需要\1
:
:g/ \+$/s///g
:g/pat/s//PAT/g
与:
:%s/pat/PAT/g
这篇关于如何在由:g执行的cmd中使用向后引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文