
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}'번째 하위 일치'가 무엇을 의미하나요?
답변1
{nr}번째는 {숫자}번째를 의미합니다. 이 경우 대체에 표현식을 사용하지 않으면 \0, \1, ... \9와 동일합니다. 보다:
:help /\1
부분 일치는 패턴에서 \(...\)로 묶입니다. 보다:
:help /\(