Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Im unclear as to what the submatch({nr}) expression in vim does. The manual says the following:

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.

I understand what submatch(0) does, but what does it mean by the '{nr}'th submatch'?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

{nr}th means {number}th. In this case it would be the same as \0, \1, ... \9 when not using an expression in the replacement. See:

:help /\1

Submatches are enclosed by \(...\) in the pattern. See:

:help /\(
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.