问题
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:
- once for searching with
:g - once for replacing with
:s
First thought was to simply use g/\(\ \+$\)/s/\1//g but this gives me an error about an invalid back reference (E65).
Is there a way to re-use the pattern used in :g for the [cmd] being executed?
回答1:
You don't need \1:
:g/ \+$/s///g
:g/pat/s//PAT/g
is same as:
:%s/pat/PAT/g
来源:https://stackoverflow.com/questions/9804484/how-do-i-use-a-back-reference-in-the-cmd-executed-by-g