Reputation:
Vi gets messed up with my perl script!
While {
at the end of the code matches none of the closing curly brackets, {
s at the end of the lines 27 and 28 match the same }
at 30.
Here is the screen video of how Vi treats my script behavior.
(source: abbasinasab.com)
Here is also my troublemaker piece of code:
#CODE
while ($data =~ m{
^foo_\s+ $X \s* \{
( (?: [^{}]+ | \{(?1)\} )* )
\}
}mgx)
{
my $Y = $1;
next if $Y !~ m{
bar_$Z \s* \{
( (?: [^{}]+ | \{(?1)\} )*? )
\}
}mx;
my $DO = $1;
#CODE
}
My questions are:
Upvotes: 3
Views: 296
Reputation: 172600
There are two pieces of functionality in Vim that can be fooled by complex syntaxes:
'matchpairs'
highlighting and jumping uses an internal heuristic. This can be slightly influenced (cp. :help cpo-M
)::set cpo+=M
With this, the %
correctly jumps to the expected closing brace (unless you have a plugin like matchpairs.vim override the %
command). Also note that the 'cpoptions'
setting is global, so this may adversely affect other filetypes.
In general, I would avoid rewriting the code just so that the editor will be happy. Other people may use different editors, and soon the code gets hugely distorted with various such "workarounds". The only exception is when the code is obviously complex and cumbersome, and general readability would improve from a restructuring.
Upvotes: 4