Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.
        :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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .