Does vim allow us to assign names to capture groups for search/replace that can be used in place of \1
, \2
etc... for back-references and substitution?
Like in in Python:
>>> import re
>>> s="ABCD HELLO, WORLD! 1234"
>>> print(re.sub(r"^(?P<foo>\w+).*?(?P<bar>\d+)$", r"\n\g<foo> \g<bar>\n", s))
ABCD 1234
Or Perl:
dade_murphy@darkstar$ \
> printf "ABCD HELLO, WORLD! 1234" \
> | perl -pe 's/^(?<foo>\w+).*?(?<bar>\d+)$/\n$+{foo} $+{bar}\n/'
ABCD 1234
ie. something like this:
:s/^\(?P<foo>\w\+\)\s*$/\g<foo>/
Neither syntax seems to work. I'm guessing this is not supported-- it doesn't strike me as a feature that would be particularly sought after in a text editor. But search / Google aren't confirming either way, so here I am.
help \1
i believe. – D. Ben Knoble♦ Sep 11 '19 at 20:16