targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

Argument text object: escaped brackets mismatch

Open ivomac opened this issue 6 years ago • 3 comments

Escaped brackets \[ inside an argument interfere with the matching of parenthesis and give wrong argument selection.

Examples: ( cursor: + , selected: +--------+ , cmd: via )

          +
foobar(a,  \[123]  )
         +-----+
                 +
foobar(a,  \[123]  )
             +----+

ivomac avatar Jun 08 '19 11:06 ivomac

@ivomac: Thank you! I can reproduce what you describe. Will look into it 👍

wellle avatar Jun 08 '19 19:06 wellle

@ivomac: I found why it doesn't work. It's because of how targets.vim uses the built in % command to match pairs in order to skip them when finding arguments. Turns out that the build in % ignores the [ in your example because it's escaped. From :help %:

When 'cpoptions' contains "M" |cpo-M| backslashes
before parens and braces are ignored.  Without "M" the
number of backslashes matters: an even number doesn't
match with an odd number.  Thus in "( \) )" and "\( (
\)" the first and last parenthesis match.

So if you're working in an environment where the \[ and ] from your example should be considered a match, you should probably add that flag (for example put this into your vimrc):

set cpoptions+=M

I tested it again with that option and now it works as you expected.

wellle avatar Jun 08 '19 20:06 wellle

@wellle That definitely works! Thanks.

ivomac avatar Jun 08 '19 22:06 ivomac