是否可以让 Vim 的omnicppcomplete 自动关闭不带任何参数的函数或方法的参数列表?
例如,假设v
是一个STL vector ,当自动完成v.clear()
时,我们最终得到:
v.clear(
如果能自动添加右括号就好了。这可能吗?
最佳答案
看起来应该是可能的:我不确定我是否有最新版本的omnicppcomplete脚本,但是在我的autoload/omni/cpp/complete.vim
中,有一个函数名为s:ExtendTagItemToPopupItem
。在这个函数中,有:
" Formating information for the preview window
if index(['f', 'p'], tagItem.kind[0])>=0
let szItemWord .= '('
if g:OmniCpp_ShowPrototypeInAbbr && has_key(tagItem, 'signature')
let szAbbr .= tagItem.signature
else
let szAbbr .= '('
endif
endif
在行(我的版本中为#165)let szItemWord .= '('
之后,添加:
if (has_key(tagItem, 'signature') == 0) || (tagItem['signature'] =~ '()')
let szItemWord .= ')'
endif
那应该可以解决问题(尽管我不太使用C++,所以我没有广泛测试它)。它基本上检查函数的“签名”是否包含“()
”而不是(例如)“(int *major, int *minor)
”。如果括号为空,则会添加右大括号。
为了完整性,可以通过将 '()'
更改为 '(\s*\(void\)\?\s*)'
来改进:this将检查“()
”、“( )
”、“(void)
”、“( void )
” >”等
关于c++ - 如何让omnicppcomplete自动关闭空参数列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1815542/