我不清楚 vim 中的 submatch({nr}) 表达式的作用。手册上是这样说的:
submatch({nr}) *submatch()*
Only for an expression in a |:substitute| command. Returns
the {nr}'th submatch of the matched text. When {nr} is 0
the whole matched text is returned.
Example:
:s/\d\+/\=submatch(0) + 1/
This finds the first number in the line and adds one to it.
A line break is included as a newline character.
我理解 submatch(0) 的作用,但是 '{nr}'th submatch' 是什么意思?
答案1
{nr}th 表示第 {number} 个。在这种情况下,当在替换中不使用表达式时,它将与 \0、\1、... \9 相同。请参阅:
:help /\1
在模式中,子匹配项被括在 \(...\) 中。请参阅:
:help /\(