因此,基本上,您必须找到最后一个不在注释中且不在字符串中的括号。
我不确定这种语法是什么,所以我将这些行放在缓冲区中并做了
:set ft=javascript
使字符串突出显示
function(abc
function(abc, [def
function(abc, [def], "string("
function(abc, [def], "string(", ghi(
Now put your cursor to the 3rd line open parenthese and issue the following command:
:echo synIDattr(synID(line('.'), col('.'), 0), 'name') =~? '\(Comment\|String\)'
It'll echo you '1' and it means that character under the cursor is in comment or in a string.
If you place the cursor to the last col of the last line and do the same command you'll get '0'.
Now you can iterate backwards over parenthesis and test them against 'comment' and 'string' and get the last open parenthese.
You can check this archive of "LISP: Balance unmatched parentheses in Vim" to see how to close unmatched parenthesis using vimscript.