• matchIt ?-w win? brace pos ?num?
Return the position of the matching brace. This command supports
parentheses ()
, curly braces {}
, square brackets
[]
, and angle braces <>
. The brace character passed to this
command should be the one whose partner you wish to find (not the one you
want to search for). This determines the direction of the search: for
instance, if you specify a closing parenthesis )
, the command will look
backwards for the matching opening parenthesis (
.
The second argument specifies the position from where to start the
search: this is not the position of the original brace. This argument is
the first position when looking forwards (respectively the last position when looking backwards) where a matching brace can be found.
In both cases, this is the position at which the command should start
looking for the matching brace.
To be more specific:
- if there is an opening parenthesis
(
at position p, the
first position where we could expect to find the matching )
parenthesis
is p+1.
The command to find it is:
matchIt ( p+1
- if there is a closing parenthesis
)
at position p, the last
position where we could expect to find the matching (
parenthesis is p-1.
The command to find it is:
matchIt ) p-1
In both cases, this is the value which should be specified as the pos argument. The returned position can't be less than pos when
looking forwards and can't be more than pos when looking backwards.
For example, if you have the text abc ()
so that )
is at
position 5, then 'matchIt ) 5'
will fail to match, but
'matchIt ) 4'
will correctly return 4.
The optional third argument num specifies how many
characters to search, starting from the specified position. When looking
forward, this restricts the search to the interval [pos,pos+num]
if pos+num is less than the length of the text. When
looking backwards, this restricts the search to the interval
[pos-num,pos-1] if pos-num is ≥ 0.