cpoptions in Vim is so …

cpoptions in Vim is so complicated...

{'{,''}’} this pattern will cause a wrong % action (MATCHING PARENTHESES SEARCH) in Vim with default cpoptions flag.

A real Example in JavaScript

if (~item.indexOf('\n ')) {  
    space -= item.length;  
    item = !this.options.pedantic  
      ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')  
      : item.replace(/^ {1,4}/gm, '');  
}  

And if we :set cpoptions&vi to change cpoptions let Vim act like VI, the result seems correct.

But after read the doc in Vim, proved it was a coincidence because VI just treat this pattern a PLAINTEXT without considering parens in “” or ''. So, if you remove one of the parens, the result get wrong again.

What I am curious about is that the default syntax highlighting is correct but the % action is wrong in Vim with such pattern.

I know install a plugin like matchit can probably resolve this problem. But is there any built-in method to deal with it?

My friend found this problem while he was trying to fold his code and got an unpredictable result.

References


Share


Donation

如果覺得這篇文章對你有幫助, 除了留言讓我知道外, 或許也可以考慮請我喝杯咖啡, 不論金額多寡我都會非常感激且能鼓勵我繼續寫出對你有幫助的文章。

If this blog post happens to be helpful to you, besides of leaving a reply, you may consider buy me a cup of coffee to support me. It would help me write more articles helpful to you in the future and I would really appreciate it.


Related Posts